mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-16 15:43:16 +00:00
15 lines
405 B
Python
15 lines
405 B
Python
from datetime import datetime, timezone
|
|
|
|
|
|
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)
|
|
|
|
|
|
def ensure_timezone(dt: datetime) -> datetime:
|
|
if dt.tzinfo is None or dt.tzinfo.utcoffset(None) is None:
|
|
dt = dt.replace(tzinfo=timezone.utc)
|
|
return dt
|