Matplotlib X-axis timezone trouble

Chris Angelico rosuav at gmail.com
Wed Jul 1 09:15:38 CEST 2015


On Wed, Jul 1, 2015 at 3:50 PM, Peter Pearson <pkpearson at nowhere.invalid> wrote:
> But look:
>
>     >>> from datetime import datetime
>     >>> import pytz
>     >>> pacific = pytz.timezone("US/Pacific")
>     >>> dt1 = datetime(2006, 11, 21, 16, 30, tzinfo=pacific) # no DST
>     >>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=pacific)   # yes DST
>     >>> dt1.dst()
>     datetime.timedelta(0)
>     >>> dt2.dst()
>     datetime.timedelta(0)
>     >>> dt1.utcoffset()
>     datetime.timedelta(-1, 57600)
>     >>> dt2.utcoffset()
>     datetime.timedelta(-1, 57600)
>
> The dst() values are equal, and the utcoffset() values are equal, even
> though one datetime is during DST and the other is not -- exactly the
> opposite of the example.

Just to confirm, they are still showing the times as 16:30 and 13:00, right?

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()?

ChrisA


More information about the Python-list mailing list