mirror of
https://github.com/ihabunek/toot
synced 2024-12-23 07:27:12 +01:00
Fix datetime parsing on python 3.5
datetime.astimezone supports native datetimes only since python 3.6 fixes #162
This commit is contained in:
parent
32005b10f9
commit
5fc46d0cfc
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user