Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.045 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; '21,': 0.07; 'correct,': 0.09; '39,': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'utc': 0.16; 'utc.': 0.16; 'values:': 0.16; 'sender:addr:gmail.com': 0.17; 'variable': 0.18; '>>>': 0.22; 'import': 0.22; 'skip': 0.24; 'earlier': 0.24; 'looks': 0.24; '15,': 0.26; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'object.': 0.31; 'call.': 0.33; 'trouble': 0.34; 'skip:d 20': 0.34; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'chair': 0.36; 'right?': 0.36; 'to:addr:python-list': 0.38; 'does': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; 'happen': 0.63; 'us:': 0.65; 'city': 0.66; 'chicago,': 0.68; 'good,': 0.91; 'sitting': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=fdNq4MtMml8hRnMTXLnBuYHTM143dPVNSiOUet9HyhQ=; b=pdD9kvx+xvhjcE8WEhrX8bAcp6Wv8ll7fCHoBQvNueXRDiT/bSp7cFgPgPYF+ShDsR CqeOGrppL9RtnTEQ/UQJ8uaCGbk+GCLWCo5cUuGJ9834LQoci6G9uBy/ZoXAEBOLMA2E UpOVSL8ysCzvPfU7Z1FsxowVnVW7azjxxa/uI9+PC2n445jtA8qH1RHu1kvNsZ3NCqGR nMz6HxPgYt+F58A/l91WZDZycT+G8bBalEX63QsxE81+MJdg+8AGvDLEc9WIVGNlzXih hge51aa2ovBOrIE3OXLuV83hfeFYfIRq8DObKBVNjdTS1kXI0kLRMjlLLNN0H+mKrgaA nUHQ== MIME-Version: 1.0 X-Received: by 10.50.114.168 with SMTP id jh8mr10902418igb.6.1391032325201; Wed, 29 Jan 2014 13:52:05 -0800 (PST) Sender: skip.montanaro@gmail.com Date: Wed, 29 Jan 2014 15:52:05 -0600 X-Google-Sender-Auth: qBvhNArcukFFFnbBY7LecSY6B74 Subject: UTC "timezone" causing brain explosions From: Skip Montanaro To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391032788 news.xs4all.nl 2880 [2001:888:2000:d::a6]:33435 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64952 Following up on my earlier note about UTC v. GMT, I am having some trouble grokking attempts to convert a datetime into UTC. Consider these three values: >>> import pytz >>> UTC = pytz.timezone("UTC") >>> UTC >>> LOCAL_TZ = pytz.timezone("America/Chicago") >>> LOCAL_TZ >>> now = datetime.datetime.now() >>> now datetime.datetime(2014, 1, 29, 15, 39, 35, 263666) All well and good, right? The variable "now" is a naive datetime object. I happen to be sitting in a chair in the city of Chicago, so let's call it what it is, a datetime in the America/Chicago timezone: >>> s = LOCAL_TZ.localize(now) >>> s datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=) That looks good to me. Now, let's normalize it to UTC: >>> t = UTC.normalize(s) >>> t datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=) >>> t.hour 15 WTF? Why isn't the t.hour == 21? Okay, let's see what GMT does for us: >>> GMT = pytz.timezone("GMT") >>> u = GMT.normalize(s) >>> u datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=) >>> u.hour 21 That looks correct, but I don't understand why I don't get hour==21 out of the UTC.normalize call. It's like it's a no-op. Skip