dateutil has moved its dangerous dst check into a dedicated method in newer versions. Fixes #1653277 [timestamp error on startup](https://bugs.launchpad.net/calibre/+bug/1653277)

This commit is contained in:
Kovid Goyal 2016-12-31 05:59:44 +05:30
parent 40140d4b88
commit ae1cf1baf3

View File

@ -17,7 +17,8 @@ if not speedup:
class SafeLocalTimeZone(tzlocal):
def _isdst(self, dt):
# This method in tzlocal raises ValueError if dt is out of range.
# This method in tzlocal raises ValueError if dt is out of range (in
# older versions of dateutil)
# In such cases, just assume that dt is not DST.
try:
return super(SafeLocalTimeZone, self)._isdst(dt)
@ -25,6 +26,17 @@ class SafeLocalTimeZone(tzlocal):
pass
return False
def _naive_is_dst(self, dt):
# This method in tzlocal raises ValueError if dt is out of range (in
# newer versions of dateutil)
# In such cases, just assume that dt is not DST.
try:
return super(SafeLocalTimeZone, self)._naive_is_dst(dt)
except Exception:
pass
return False
utc_tz = tzutc()
local_tz = SafeLocalTimeZone()
del tzutc, tzlocal
@ -48,6 +60,7 @@ def parse_iso8601(date_string, assume_utc=False, as_utc=True):
return dt
return dt.astimezone(utc_tz if as_utc else local_tz)
if __name__ == '__main__':
import sys
print(parse_iso8601(sys.argv[-1]))