From ae1cf1baf34bcd2074136361980f7f9888f794bf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 31 Dec 2016 05:59:44 +0530 Subject: [PATCH] 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) --- src/calibre/utils/iso8601.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/iso8601.py b/src/calibre/utils/iso8601.py index f91f119f09..00e6bdfc01 100644 --- a/src/calibre/utils/iso8601.py +++ b/src/calibre/utils/iso8601.py @@ -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]))