selfprivacy-rest-api/selfprivacy_api/models/tokens/time.py

15 lines
405 B
Python
Raw Permalink Normal View History

from datetime import datetime, timezone
2023-06-14 11:01:15 +00:00
def is_past(dt: datetime) -> bool:
# we cannot compare a naive now()
# to dt which might be tz-aware or unaware
dt = ensure_timezone(dt)
return dt < datetime.now(timezone.utc)
2023-06-14 11:01:15 +00:00
def ensure_timezone(dt: datetime) -> datetime:
if dt.tzinfo is None or dt.tzinfo.utcoffset(None) is None:
2023-06-14 11:01:15 +00:00
dt = dt.replace(tzinfo=timezone.utc)
return dt