Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.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.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'dst': 0.07; 'boundaries.': 0.09; 'cc:addr:python-list': 0.10; 'python': 0.11; 'appropriate': 0.14; 'wed,': 0.15; 'thu,': 0.15; '2.7.3': 0.16; 'docstring': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'offsets': 0.16; 'utc': 0.16; 'utc.': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'am,': 0.23; 'appears': 0.23; '2015': 0.23; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'second': 0.24; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.28; "we're": 0.30; 'maybe': 0.31; 'supposed': 0.31; "can't": 0.32; 'pacific': 0.33; 'case,': 0.34; 'received:google.com': 0.34; 'wrong': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.37; 'subject:: ': 0.37; '12,': 0.37; 'version': 0.38; 'skip:p 20': 0.38; 'easily': 0.39; 'subject:-': 0.39; 'skip:t 20': 0.40; 'subject: (': 0.40; 'your': 0.60; 'simple': 0.61; 'here.': 0.61; 'show': 0.62; 'more': 0.62; 'mar': 0.65; 'hour': 0.69; 'jul': 0.72; 'saw': 0.76; '+1000,': 0.84; '2:36': 0.84; 'chrisa': 0.84; 'converter,': 0.84; 'to:none': 0.90; '2014,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=prmlV3n36Yd9+nw2cURnq6N0fQciLM50H4TUgQ7qyWU=; b=CrgHtRcj2UWq0Px6d1WBWMneozmgdrkrSeBi87gLa4OSzoTxYqF/46aR5scgObNiM/ J8hio+JlJmUEyZzbrBOg4qUIYszLjYeG2WVshUfFuOApqVxuChCfyRg4bTKGNkvaw/kL WgV/x9Ow2ZXCd2Kt/7UfK7Z3kAWkkg5gq91MtdOUUxNIN4QuAmFHNuCIuCjM616E5FMZ POycpKScfn7bNZ0PFa347qLa7H1yfXeUB8NV9PDbYHvBfLQ+JNnJJKodc3/4sqDEUd5P Z4TlZERJthEtpQcMhvQ33Q0rytH2gXOwCwTmEcZTkjU91QMQEGt/qdbwVDnPxgKoDZgs 3jDw== MIME-Version: 1.0 X-Received: by 10.107.160.141 with SMTP id j135mr38857818ioe.43.1435770514271; Wed, 01 Jul 2015 10:08:34 -0700 (PDT) In-Reply-To: References: Date: Thu, 2 Jul 2015 03:08:34 +1000 Subject: Re: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 1435770517 news.xs4all.nl 2837 [2001:888:2000:d::a6]:42970 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93381 On Thu, Jul 2, 2015 at 2:36 AM, Peter Pearson wrote: > On Wed, 1 Jul 2015 17:15:38 +1000, Chris Angelico wrote: >> >> Interestingly, when I tried this (pytz version 2015.4, Python 2.7.9, >> Debian Jessie), I saw utcoffset() showing (-1, 58020) for both. That >> seems... odd. And I can't fault your dates - those definitely ought to >> be easily inside and easily outside the DST boundaries. When I try >> those dates in an unrelated time converter, they do show seven- and >> eight- hour offsets to UTC. Maybe we're both misunderstanding the >> meaning of utcoffset()? > > Here's a very simple demonstration that either something is wrong > or I don't understand how datetime and tzinfo are supposed to work: > > $ python > Python 2.7.3 (default, Mar 13 2014, 11:03:55) >>>> from pytz import timezone >>>> from datetime import datetime >>>> pacific = timezone("US/Pacific") >>>> print(datetime(2014, 7, 7, 12, tzinfo=pacific)) > 2014-07-07 12:00:00-08:00 >>>> print(datetime(2014, 1, 7, 12, tzinfo=pacific)) > 2014-01-07 12:00:00-08:00 >>>> > > The "-08:00" is appropriate in the second (January) case, but the > first case is in July, and should have "-07:00". Interesting. I poked around with the docstring for pytz.timezone and replicated it more exactly, and this appears to work: $ python Python 2.7.9 (default, Mar 1 2015, 12:57:24) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from pytz import timezone >>> from datetime import datetime >>> pacific = timezone("US/Pacific") >>> utc = timezone("UTC") >>> print(datetime(2014, 7, 7, 12, tzinfo=utc).astimezone(pacific)) 2014-07-07 05:00:00-07:00 >>> print(datetime(2014, 1, 7, 12, tzinfo=utc).astimezone(pacific)) 2014-01-07 04:00:00-08:00 Clearly I do not understand what's going on here. ChrisA