1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

fix strptime workaround from b0e85a4

Don't return a modified version of 'date_time' if strptime fails.
This commit is contained in:
Mike Fährmann 2019-05-25 23:22:26 +02:00
parent b3e4664715
commit 2316e0ed3d
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 8 additions and 2 deletions

View File

@ -228,8 +228,10 @@ def parse_datetime(date_string, format="%Y-%m-%dT%H:%M:%S%z"):
try:
if format.endswith("%z") and date_string[-3] == ":":
# workaround for Python < 3.7: +00:00 -> +0000
date_string = date_string[:-3] + date_string[-2:]
d = datetime.datetime.strptime(date_string, format)
ds = date_string[:-3] + date_string[-2:]
else:
ds = date_string
d = datetime.datetime.strptime(ds, format)
o = d.utcoffset()
if o is not None:
d = d.replace(tzinfo=None) - o # convert to naive UTC

View File

@ -365,6 +365,10 @@ class TestText(unittest.TestCase):
f("2019-05-07T21:25:02+0900"),
datetime.datetime(2019, 5, 7, 12, 25, 2),
)
self.assertEqual(
f("2019-05-07 21:25:02"),
"2019-05-07 21:25:02",
)
for value in INVALID:
self.assertEqual(f(value), None)