[pywin32-bugs] [ pywin32-Bugs-3525567 ] Fix for 3524786 breaks None-ambiguous conversions
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2012-05-10 16:29:39
|
Bugs item #3525567, was opened at 2012-05-10 09:19 Message generated for change (Comment added) made by bmatthews27 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3525567&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: Fix for 3524786 breaks None-ambiguous conversions Initial Comment: I seem to be causing you lots of problems.... :( The fix for 3524786 has introduced new issues. This example shows a none-ambiguous conversion. The timestamps are in UTC, and therefore do have a correct conversion that is not ambiguous. I dont think raising an exception is going to help here. The script should be run with the PC in the Pacific Time Zone so localtime() can be used for comparison. It should show local times of 2:00 AM (STD), 1:00 AM (STD), 1:00 AM (DST) I am going to suggest removing the exception. The ambiguous issue is when converting from localtimes to UTC or another timezone. I am not really sure how it should be fixed. The only possible solution is to be able to tell the function it is 1:30 in DST or STD. but I dont know how this could be implemented as datetime does not have this. Perhaps it should just be documented as an ambiguity. Anyway, here is the script showing the problem. >>> import win32timezone >>> from datetime import datetime >>> import time >>> ... PST = win32timezone.TimeZoneInfo('Pacific Standard Time') >>> >>> print datetime.fromtimestamp(1320573600, PST) 2011-11-06 02:00:00-08:00 >>> print datetime.fromtimestamp(1320570000, PST) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\win32\lib\win32timezone.py", line 635, in utcoffset return -winInfo.bias + self.dst(dt) File "C:\Python27\lib\site-packages\win32\lib\win32timezone.py", line 641, in dst if not self.fixedStandardTime and self._inDaylightSavings(dt): File "C:\Python27\lib\site-packages\win32\lib\win32timezone.py", line 664, in _inDaylightSavings raise AmbiguousTimeError(dt) win32timezone.AmbiguousTimeError: 2011-11-06 01:00:00 >>> print datetime.fromtimestamp(1320566400, PST) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\win32\lib\win32timezone.py", line 635, in utcoffset return -winInfo.bias + self.dst(dt) File "C:\Python27\lib\site-packages\win32\lib\win32timezone.py", line 641, in dst if not self.fixedStandardTime and self._inDaylightSavings(dt): File "C:\Python27\lib\site-packages\win32\lib\win32timezone.py", line 664, in _inDaylightSavings raise AmbiguousTimeError(dt) win32timezone.AmbiguousTimeError: 2011-11-06 01:00:00 >>> >>> 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-10 09:29 Message: Ok, that is much better. There is still one issue, datetime is showing the offset as -08:00 for the last timestamp, and it should be -07:00. But the hour is correct now. >>> import win32timezone >>> from datetime import datetime >>> import time >>> ... PST = win32timezone.TimeZoneInfo('Pacific Standard Time') >>> >>> print datetime.fromtimestamp(1320573600, PST) 2011-11-06 02:00:00-08:00 >>> print datetime.fromtimestamp(1320570000, PST) 2011-11-06 01:00:00-08:00 >>> print datetime.fromtimestamp(1320566400, PST) 2011-11-06 01:00:00-08:00 >>> >>> 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: Jason R. Coombs (jaraco) Date: 2012-05-10 09:22 Message: I was afraid we might encounter something like this. In that case, would you try the parent revision, which doesn't add the ambiguous exception? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3525567&group_id=78018 |