1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-06-23 06:25:26 +00:00

Fix date parsing bug

issue #114
This commit is contained in:
Ivan Habunek 2019-09-04 08:36:12 +02:00
parent e9acd6daf7
commit e310482cb6
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -9,7 +9,15 @@ HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')
def parse_datetime(value):
"""Returns an aware datetime in local timezone"""
return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z").astimezone()
# 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")
else:
dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z")
return dttm.astimezone()
def highlight_keys(text, high_attr, low_attr=""):