Confused about timezones

Skip Montanaro skip at pobox.com
Wed Oct 23 12:17:16 EDT 2013


This isn't really a Python issue, though my problem solution will be
implemented in Python. If I have a naive datetime object for some time
in the past, it's not clear to me how the offset gets set correctly.
Consider this sequence:

>>> import datetime, pytz
>>> LOCAL_TZ = pytz.timezone(os.environ.get('TZ', "America/Chicago"))
>>> dt1 = datetime.datetime(2013, 5, 30, 0, 0) # DST in effect
>>> dt2 = datetime.datetime(2013, 1, 30, 0, 0) # no DST
>>> LOCAL_TZ.localize(dt1).utcoffset()
datetime.timedelta(-1, 68400)
>>> LOCAL_TZ.localize(dt2).utcoffset()
datetime.timedelta(-1, 64800)

Why is the UTC offset the same for both datetime objects despite the
presence/absence of Daylight Savings?

Thx,

Skip



More information about the Python-list mailing list