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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '21,': 0.07; '22,': 0.09; 'correct,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; '39,': 0.16; 'cases:': 0.16; 'utc': 0.16; 'utc.': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'code,': 0.22; 'header:User-Agent:1': 0.23; 'skip': 0.24; 'earlier': 0.24; 'looks': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; '>>>>': 0.31; 'call.': 0.33; 'trouble': 0.34; 'skip:d 20': 0.34; "can't": 0.35; 'convert': 0.35; 'but': 0.35; '14,': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'does': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; 'tell': 0.60; 'received:173': 0.61; 'us:': 0.65; 'different.': 0.84 Date: Wed, 29 Jan 2014 14:21:00 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: UTC "timezone" causing brain explosions References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source-IP: 173.12.184.233 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:57790 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391035371 news.xs4all.nl 2884 [2001:888:2000:d::a6]:44118 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64953 On 01/29/2014 01:52 PM, Skip Montanaro wrote: > Following up on my earlier note about UTC v. GMT, I am having some > trouble grokking attempts to convert a datetime into UTC. > > 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. Having not examined the code, I can't tell you why UTC is different. I can say that .astimezone seems to work in all cases: --> GMT --> UTC --> LOCAL_TZ = pytz.timezone("America/Los_Angeles") --> now = datetime.datetime.now() --> s = LOCAL_TZ.localize(now) --> s datetime.datetime(2014, 1, 29, 14, 9, 56, 494967, tzinfo=) --> s.astimezone(UTC) datetime.datetime(2014, 1, 29, 22, 9, 56, 494967, tzinfo=) --> s.astimezone(GMT) datetime.datetime(2014, 1, 29, 22, 9, 56, 494967, tzinfo=) -- ~Ethan~