This commit is contained in:
k00kzaAntonovaIra
2026-11-02 20:05:33 +03:00
parent 0ab3a341aa
commit e3ff3b25ce
145 changed files with 9724 additions and 473 deletions
+23
View File
@@ -0,0 +1,23 @@
"""Преобразования времени: RFC 3339 UTC и микросекунды."""
from datetime import datetime, timedelta, timezone
EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)
def format_ts(moment: datetime) -> str:
"""datetime -> строка RFC 3339 в UTC с суффиксом Z."""
return moment.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
def to_micros(moment: datetime) -> int:
"""datetime -> микросекунды от эпохи."""
return (moment - EPOCH) // timedelta(microseconds=1)
MAX_TIMESTAMP_MICROS = to_micros(datetime.max.replace(tzinfo=timezone.utc))
def from_micros(micros: int) -> datetime:
"""Микросекунды от эпохи -> datetime в UTC."""
return EPOCH + timedelta(microseconds=micros)