Spaces:
Runtime error
Runtime error
File size: 534 Bytes
69a6cef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import datetime
import dateparser
try:
from zoneinfo import ZoneInfo
except (ImportError, ModuleNotFoundError):
from backports.zoneinfo import ZoneInfo
def parse_time(time):
if isinstance(time, str):
d = dateparser.parse(time)
elif isinstance(time, (int, float)):
d = datetime.datetime.fromtimestamp(time)
elif isinstance(time, datetime.datetime):
d = time
else:
raise TypeError(f'Unknown time type - {time}.')
if not d.tzinfo:
d = d.astimezone()
return d
|