a9c16febf4
* test(skills): align sandbox cache tests with readonly behavior * ci(release): enforce core quality gate before publish * ci: enforce locked dependency installs in workflows * security: remove curl-pipe-shell installs * chore: align project python baseline to 3.12 * ci(dashboard): add explicit typecheck gate * chore(pre-commit): align ruff hook version with project * ci(codeql): add javascript-typescript analysis * chore(ruff): defer py312 migration lint rules * fix: resolve ruff violations without new ignores * fix: resolve ASYNC230 and ASYNC240 without ignores * fix(auth): replace utcnow with timezone-aware UTC now * fix: avoid blocking file read in file_to_base64
28 lines
770 B
Python
28 lines
770 B
Python
from datetime import UTC, datetime
|
|
|
|
|
|
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=UTC)
|
|
return dt.astimezone(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()
|