Fix a regression in the previous release that broke parsing of some IS0 8601 timestamps. Fixes #2031341 [Calibre corrupts last modified date when using the server](https://bugs.launchpad.net/calibre/+bug/2031341)

timezone() unlike tzoffset() requires timedelta() objects instead of
seconds
This commit is contained in:
Kovid Goyal 2023-08-16 14:27:59 +05:30
parent d26bc9fb45
commit c68ba38533
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2,11 +2,10 @@
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
from calibre_extensions import speedup
utc_tz = timezone.utc
local_tz = datetime.now().astimezone().tzinfo
UNDEFINED_DATE = datetime(101,1,1, tzinfo=utc_tz)
@ -23,7 +22,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 = timezone(tzseconds, description)
tz = timezone(timedelta(seconds=tzseconds), description)
elif require_aware:
raise ValueError(f'{date_string} does not specify a time zone')
dt = dt.replace(tzinfo=tz)