This commit is contained in:
k00kzaAntonovaIra
2026-10-23 14:09:32 +03:00
parent 65003b6119
commit 840907cf2b
79 changed files with 6656 additions and 20 deletions
+20
View File
@@ -0,0 +1,20 @@
"""Преобразования времени: 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)
def from_micros(micros: int) -> datetime:
"""Микросекунды от эпохи -> datetime в UTC."""
return EPOCH + timedelta(microseconds=micros)