problem with US time zones

Bug #1446347 reported by Fred Drake
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pytz
Invalid
Undecided
Unassigned

Bug Description

This problem appears to be new as of pytz-2014.3:

>>> datetime.datetime(2010, 6, 1, 11, 17, 3, 5432, pytz.timezone("US/Central")).astimezone(pytz.UTC)
datetime.datetime(2010, 6, 1, 17, 8, 3, 5432, tzinfo=<UTC>)
>>> datetime.datetime(2010, 6, 1, 11, 17, 3, 5432, pytz.timezone("US/Eastern")).astimezone(pytz.UTC)
datetime.datetime(2010, 6, 1, 16, 13, 3, 5432, tzinfo=<UTC>)

Revision history for this message
Fred Drake (fdrake) wrote :

Note in particular that the minute value is changed unexpectedly.

description: updated
Revision history for this message
Stuart Bishop (stub) wrote :

You need to use the pytz API to construct the localized timestamps, per its README

>>> import pytz
>>> central = pytz.timezone('US/Central')
>>> eastern = pytz.timezone('US/Eastern')
>>> import datetime
>>> central.localize(datetime.datetime(2010, 6, 1, 11, 17, 3, 5432)).astimezone(pytz.utc)
datetime.datetime(2010, 6, 1, 16, 17, 3, 5432, tzinfo=<UTC>)
>>> eastern.localize(datetime.datetime(2010, 6, 1, 11, 17, 3, 5432)).astimezone(pytz.utc)
datetime.datetime(2010, 6, 1, 15, 17, 3, 5432, tzinfo=<UTC>)
>>>

PEP 431 is all about fixing this and making it sane.

Revision history for this message
Fred Drake (fdrake) wrote :

Ok; I think I understand the problem now. It's not that the conversion to UTC was a problem, but that the input itself was insane, where the input I was dealing with was:

datetime.datetime(2010, 6, 1, 11, 17, 3, 5432, pytz.timezone("US/Eastern"))

because the resulting datetime value didn't have the right timezone.

Thanks!

Changed in pytz:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.