Skip to content

aux

_raise_if_naive_datetime(*timestamps)

Raise 422 if any not-null argument is a naive datetime object: https://docs.python.org/3/library/datetime.html#determining-if-an-object-is-aware-or-naive

Source code in fractal_server/app/routes/aux/__init__.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def _raise_if_naive_datetime(*timestamps: tuple[Optional[datetime]]) -> None:
    """
    Raise 422 if any not-null argument is a naive `datetime` object:
    https://docs.python.org/3/library/datetime.html#determining-if-an-object-is-aware-or-naive
    """
    for timestamp in filter(None, timestamps):
        if (timestamp.tzinfo is None) or (
            timestamp.tzinfo.utcoffset(timestamp) is None
        ):
            raise HTTPException(
                status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
                detail=f"{timestamp=} is naive. You must provide a timezone.",
            )