mmcli/parsedt.py

19 lines
383 B
Python
Raw Normal View History

2021-08-07 18:55:21 +02:00
"""
Wrapper around date/time parsing
"""
import datetime
from dateutil.parser import parse
def parse_datetime_to_utc(string) -> datetime.datetime:
parsed = parse(string)
if parsed.tzinfo is None:
# Convert to timezone aware datetime with the system's timezone
converted = parsed.astimezone()
else:
converted = parsed
return converted.astimezone(datetime.timezone.utc)