Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Peter Pearson Newsgroups: comp.lang.python Subject: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble) Date: 1 Jul 2015 16:36:22 GMT Lines: 29 Message-ID: References: X-Trace: individual.net CrC2oLBlScc0KcEgKiTirQ2G59ZHY32Ui59DQ2HzVn5I64jYZA Cancel-Lock: sha1:CYcRuGqDmhxWPRAftGU9lvecJxY= User-Agent: slrn/pre1.0.0-18 (Linux) Xref: csiph.com comp.lang.python:93379 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". -- To email me, substitute nowhere->runbox, invalid->com.