[pywin32-bugs] [ pywin32-Bugs-3524786 ] Conversion of UTC timestamp to localtime is wrong at STD/DS
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2012-05-08 16:46:26
|
Bugs item #3524786, was opened at 2012-05-08 09:34 Message generated for change (Comment added) made by bmatthews27 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3524786&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: win32timezone Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Brian Matthews (bmatthews27) Assigned to: Jason R. Coombs (jaraco) Summary: Conversion of UTC timestamp to localtime is wrong at STD/DST Initial Comment: I am not sure if this error is in TimeZoneInfo or datetime. I am running my PC in Pacific time, so I have a way to easily check the results. The script below converts UTC timestamps into a datetime in the Pacific time zone. The result for PST 2:00 AM on 2011-11-06 is wrong. Doing the same conversion using localtime() is correct. During the ambiguous localtime hour on 6-Nov, 2:00 AM should only appear once. 1:00 AM should appear twice. >>> from win32timezone import TimeZoneInfo >>> from datetime import datetime >>> import calendar >>> import time >>> >>> tzi = TimeZoneInfo('Pacific Standard Time') >>> tzutc = TimeZoneInfo('Coordinated Universal Time') >>> >>> def fromtimestamp_to_timetuple(timestamp): ... tm = time.gmtime(timestamp) ... tz1 = datetime(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, ... tm.tm_min, tm.tm_sec, tzinfo=tzutc) ... tz_time = tz1.astimezone(tzi) ... return tz_time ... >>> print fromtimestamp_to_timetuple(1320573600).timetuple() time.struct_time(tm_year=2011, tm_mon=11, tm_mday=6, tm_hour=2, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=310, tm_isdst=0) >>> print fromtimestamp_to_timetuple(1320570000).timetuple() time.struct_time(tm_year=2011, tm_mon=11, tm_mday=6, tm_hour=2, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=310, tm_isdst=0) >>> print fromtimestamp_to_timetuple(1320566400).timetuple() time.struct_time(tm_year=2011, tm_mon=11, tm_mday=6, tm_hour=1, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=310, tm_isdst=1) >>> >>> print time.strftime('%c', time.localtime(1320573600)) 11/06/11 02:00:00 >>> print time.strftime('%c', time.localtime(1320570000)) 11/06/11 01:00:00 >>> print time.strftime('%c', time.localtime(1320566400)) 11/06/11 01:00:00 ---------------------------------------------------------------------- >Comment By: Brian Matthews (bmatthews27) Date: 2012-05-08 09:46 Message: NOTE: This is a problem only at precisely the end of the hour. It is using the most recent patches. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3524786&group_id=78018 |