Files
mtusi2026lab4-fork/app/timefmt.py
daniil_sobolev 747ca222e5 Implement lab4 attachments on RustFS for grade 4.
Carry over lab3 HA stack and add private S3 storage, Attachment API, orphan compensation/reaper, own tests, and evidence for smoke/persistence/failover.
2026-11-12 20:41:02 +03:00

21 lines
610 B
Python

"""Форматирование времени в RFC 3339 UTC с миллисекундами и Z."""
from datetime import datetime, timezone
def now_utc() -> str:
return format_utc(datetime.now(timezone.utc))
def format_utc(value: datetime) -> str:
if value.tzinfo is None:
value = value.replace(tzinfo=timezone.utc)
else:
value = value.astimezone(timezone.utc)
return value.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
def parse_rfc3339(value: str) -> datetime:
if value.endswith("Z"):
value = value[:-1] + "+00:00"
return datetime.fromisoformat(value)