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:
parent
b3e4664715
commit
2316e0ed3d
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user