Module dynamo_pydantic.dates

Functions

def ensure_utc(dt: datetime.datetime) ‑> datetime.datetime
Expand source code
def ensure_utc(dt: datetime) -> datetime:
    if dt.tzinfo is None:
        # If naive, assume local system time (matching standard Python/Pydantic behavior)
        # and convert it to UTC.
        return dt.astimezone(timezone.utc)
    # If already timezone-aware, shift it to UTC hours
    return dt.astimezone(timezone.utc)