Handle datetime without second fraction part
This commit is contained in:
parent
c82e670882
commit
b35facb84c
1 changed files with 7 additions and 1 deletions
|
@ -1,12 +1,18 @@
|
|||
import math
|
||||
import os
|
||||
import sys
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def parse_datetime(value):
|
||||
"""Returns an aware datetime in local timezone"""
|
||||
dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z")
|
||||
if sys.version_info.major == 3 and sys.version_info.minor >= 11:
|
||||
dttm = datetime.fromisoformat(value)
|
||||
else:
|
||||
# Fallback manual format parsing
|
||||
# This does not catches all possible formats used by server software
|
||||
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
|
||||
# the local timezone
|
||||
|
|
Loading…
Reference in a new issue