kopia lustrzana https://github.com/ihabunek/toot
Remove datetime hack used for python < 3.7
rodzic
3df8e2722a
commit
da9931e5e5
|
@ -1,19 +1,12 @@
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
|
||||||
def parse_datetime(value):
|
def parse_datetime(value):
|
||||||
"""Returns an aware datetime in local timezone"""
|
"""Returns an aware datetime in local timezone"""
|
||||||
|
dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z")
|
||||||
# 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").replace(tzinfo=timezone.utc)
|
|
||||||
else:
|
|
||||||
dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z")
|
|
||||||
|
|
||||||
# When running tests return datetime in UTC so that tests don't depend on
|
# When running tests return datetime in UTC so that tests don't depend on
|
||||||
# the local timezone
|
# the local timezone
|
||||||
|
|
Ładowanie…
Reference in New Issue