Skip to content

Commit

Permalink
Fix datetime parsing on python 3.5
Browse files Browse the repository at this point in the history
datetime.astimezone supports native datetimes only since python 3.6

fixes #162
  • Loading branch information
ihabunek committed Apr 15, 2020
1 parent 32005b1 commit 5fc46d0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions toot/tui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
import subprocess

from datetime import datetime
from datetime import datetime, timezone

HASHTAG_PATTERN = re.compile(r'(?<!\w)(#\w+)\b')

Expand All @@ -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")

Expand Down

0 comments on commit 5fc46d0

Please sign in to comment.