A kind of initial commit

This commit is contained in:
heboba
2026-02-26 19:33:05 +00:00
commit 9ab125b1a6
37 changed files with 3053 additions and 0 deletions

25
app/utils/time.py Normal file
View File

@@ -0,0 +1,25 @@
from __future__ import annotations
from datetime import datetime, timezone
def utcnow() -> datetime:
return datetime.now(timezone.utc)
def ensure_utc(dt: datetime) -> datetime:
if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None:
return dt.replace(tzinfo=timezone.utc)
return dt.astimezone(timezone.utc)
def parse_spotify_datetime(value: str | None) -> datetime | None:
if not value:
return None
if value.endswith("Z"):
value = value.replace("Z", "+00:00")
return datetime.fromisoformat(value)
def to_unix_ms(dt: datetime) -> int:
return int(dt.timestamp() * 1000)