This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients belopolsky, docs@python, mark.dickinson
Date 2010-07-07.04:49:10
SpamBayes Score 9.602174e-07
Marked as misclassified No
Message-id <1278478163.74.0.970570412156.issue9063@psf.upfronthosting.co.za>
In-reply-to
Content
There is nothing we can do about misreporting of UTC offset.  Unlike time tuples, datetime objects do not store the DST flag and thus have no means to disambiguate between standard and DST during the hour after the clock is set back for DST to standard transition.

Nevertheless, dt = datetime.fromtimestamp(t) is a well defined operation, it is dt.dst() and dt.utcoffset() which are not so well defined.

According to the comment at the end of Modules/datetimemodule.c, in order for the default implementation of tzinfo.fromutc() to operate correctly, the concrete implementation of tzinfo.dst(dt) must treat dt that falls into the ambiguous hour (where it can be ether DST or standard time) as the standard time.  This is precisely what is done in the implementation of USTimeZone class.  The Local class, however, relies on mktime to choose between DST and standard and apparently, at least on OSX, mktime does not do what Python's tzinfo.fromutc() expects.

The attached patch for Doc/includes/tzinfo-examples.py fixes this problem by passing is_dst=0 instead of -1 to mktime and also adds __repr__ to LocalTimezone class.

With this patch,

>>> x = datetime(2010, 11, 7, 5)
>>> s = (x - datetime(1970, 1, 1))//timedelta(seconds=1)
>>> for i in range(-3600, 5000, 3600):
...     datetime.fromtimestamp(s + i, Local)
... 
datetime.datetime(2010, 11, 7, 0, 0, tzinfo=EST/EDT)
datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST/EDT)
datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST/EDT)

which is correct and consistent with Easter timezone:

>>> for i in range(-3600, 5000, 3600):
...     datetime.fromtimestamp(s + i, Eastern)
... 
datetime.datetime(2010, 11, 7, 0, 0, tzinfo=Eastern)
datetime.datetime(2010, 11, 7, 1, 0, tzinfo=Eastern)
datetime.datetime(2010, 11, 7, 1, 0, tzinfo=Eastern)
History
Date User Action Args
2010-07-07 04:49:26belopolskysetrecipients: + belopolsky, mark.dickinson, docs@python
2010-07-07 04:49:23belopolskysetmessageid: <1278478163.74.0.970570412156.issue9063@psf.upfronthosting.co.za>
2010-07-07 04:49:21belopolskylinkissue9063 messages
2010-07-07 04:49:14belopolskycreate