21 lines
619 B
Python
21 lines
619 B
Python
# engine/utils/time_utils.py
|
|
|
|
from datetime import datetime, timezone, timedelta
|
|
import pytz
|
|
|
|
LOCAL_TZ = pytz.timezone("America/Toronto")
|
|
|
|
def utc_ts_to_local_datetime(ts: float):
|
|
"""Timestamp UNIX (UTC réel) → datetime locale America/Toronto."""
|
|
return datetime.fromtimestamp(ts, timezone.utc).astimezone(LOCAL_TZ)
|
|
|
|
def utc_ts_to_utc_datetime(ts: float):
|
|
"""Timestamp UNIX (UTC réel) → datetime UTC."""
|
|
return datetime.fromtimestamp(ts, timezone.utc)
|
|
|
|
def local_datetime_to_utc(dt):
|
|
"""Datetime locale → UTC."""
|
|
if dt is None:
|
|
return None
|
|
return dt.astimezone(timezone.utc)
|