Fix datetime parsing on python 3.5

datetime.astimezone supports native datetimes only since python 3.6

fixes #162
This commit is contained in:
Ivan Habunek 2020-04-15 14:01:23 +02:00
parent 32005b10f9
commit 5fc46d0cfc
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
1 changed files with 2 additions and 2 deletions

View File

@ -2,7 +2,7 @@ import re
import shutil
import subprocess
from datetime import datetime
from datetime import datetime, timezone
HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
@ -13,7 +13,7 @@ def parse_datetime(value):
# In Python < 3.7, `%z` does not match `Z` offset
# https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior
if value.endswith("Z"):
dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%fZ")
dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
else:
dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z")