From 2316e0ed3d60d0a948d4737dc94c9b2cb06cf75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 25 May 2019 23:22:26 +0200 Subject: [PATCH] fix strptime workaround from b0e85a4 Don't return a modified version of 'date_time' if strptime fails. --- gallery_dl/text.py | 6 ++++-- test/test_text.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gallery_dl/text.py b/gallery_dl/text.py index a21306d0..ee987099 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -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 diff --git a/test/test_text.py b/test/test_text.py index f33642be..da7d8156 100644 --- a/test/test_text.py +++ b/test/test_text.py @@ -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)