Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57373

Confused about timezones

Date 2013-10-23 11:17 -0500
Subject Confused about timezones
From Skip Montanaro <skip@pobox.com>
Newsgroups comp.lang.python
Message-ID <mailman.1416.1382545517.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Confused about timezones Skip Montanaro <skip@pobox.com> - 2013-10-23 11:17 -0500

csiph-web