Download astrbot/core/utils/datetime_utils.py from qa1145/astrbbbb: direct link, hf CLI and curl.
- Browser
- Download file 793 Bytes
-
https://huggingface.co/spaces/qa1145/astrbbbb/resolve/main/astrbot/core/utils/datetime_utils.py
- Command line
-
hf download hf://spaces/qa1145/astrbbbb/astrbot/core/utils/datetime_utils.py
-
curl -L -o datetime_utils.py https://huggingface.co/spaces/qa1145/astrbbbb/resolve/main/astrbot/core/utils/datetime_utils.py
793 Bytes
| from datetime import datetime, timezone | |
| def normalize_datetime_utc(dt: datetime | None) -> datetime | None: | |
| """Normalize datetime values to UTC. | |
| Naive datetimes are interpreted as UTC to match SQLite storage behavior. | |
| """ | |
| if dt is None: | |
| return None | |
| if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None: | |
| return dt.replace(tzinfo=timezone.utc) | |
| return dt.astimezone(timezone.utc) | |
| def to_utc_isoformat(dt: datetime | None) -> str | None: | |
| normalized = normalize_datetime_utc(dt) | |
| if normalized is None: | |
| return None | |
| return normalized.isoformat() | |
| def to_utc_timestamp(dt: datetime | None) -> float | None: | |
| normalized = normalize_datetime_utc(dt) | |
| if normalized is None: | |
| return None | |
| return normalized.timestamp() | |