forked from mtusi2026/mtusi2026lab5
12 lines
417 B
Python
12 lines
417 B
Python
from datetime import datetime, timezone
|
|
|
|
|
|
def to_rfc3339(value: datetime) -> str:
|
|
return value.astimezone(timezone.utc).isoformat(timespec='microseconds').replace('+00:00', 'Z')
|
|
|
|
|
|
def from_rfc3339(value: str) -> datetime:
|
|
if not isinstance(value, str) or not value.endswith('Z'):
|
|
raise ValueError('timestamp must end with Z')
|
|
return datetime.fromisoformat(value[:-1]).replace(tzinfo=timezone.utc)
|