12 lines
421 B
Python
12 lines
421 B
Python
import datetime
|
|
from backports.datetime_fromisoformat import MonkeyPatch
|
|
MonkeyPatch.patch_fromisoformat()
|
|
|
|
|
|
def from_iso_format(date_str):
|
|
"""Z-suffix aware version of `datetime.datetime.fromisoformat`"""
|
|
time = datetime.datetime.fromisoformat(date_str.replace('Z', '+00:00'))
|
|
if time.tzinfo:
|
|
return time.astimezone(tzinfo=datetime.timezone.utc)
|
|
return time.replace(tzinfo=datetime.timezone.utc)
|