mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Replace use of timezone objects from dateutil package with those from the stdlib
The dateutil local_tz malfunctions on windows for dates before 1970-1-1 See https://bugs.launchpad.net/calibre/+bug/2028019 for details.
This commit is contained in:
parent
1a32580cb7
commit
84ace57cc3
@ -2,38 +2,13 @@
|
||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from dateutil.tz import tzlocal, tzutc, tzoffset
|
||||
from calibre_extensions import speedup
|
||||
|
||||
|
||||
class SafeLocalTimeZone(tzlocal):
|
||||
|
||||
def _isdst(self, dt):
|
||||
# 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()._isdst(dt)
|
||||
except Exception:
|
||||
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()._naive_is_dst(dt)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
utc_tz = tzutc()
|
||||
local_tz = SafeLocalTimeZone()
|
||||
del tzutc, tzlocal
|
||||
utc_tz = timezone.utc
|
||||
local_tz = datetime.now().astimezone().tzinfo
|
||||
UNDEFINED_DATE = datetime(101,1,1, tzinfo=utc_tz)
|
||||
|
||||
|
||||
@ -48,7 +23,7 @@ def parse_iso8601(date_string, assume_utc=False, as_utc=True, require_aware=Fals
|
||||
else:
|
||||
sign = '-' if tzseconds < 0 else '+'
|
||||
description = "%s%02d:%02d" % (sign, abs(tzseconds) // 3600, (abs(tzseconds) % 3600) // 60)
|
||||
tz = tzoffset(description, tzseconds)
|
||||
tz = timezone(tzseconds, description)
|
||||
elif require_aware:
|
||||
raise ValueError(f'{date_string} does not specify a time zone')
|
||||
dt = dt.replace(tzinfo=tz)
|
||||
|
Loading…
x
Reference in New Issue
Block a user