21 lines
510 B
Python
21 lines
510 B
Python
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime, timedelta
|
|
|
|
|
|
def utc_now() -> datetime:
|
|
return datetime.now(UTC)
|
|
|
|
|
|
def to_iso(value: datetime | None = None) -> str:
|
|
current = value or utc_now()
|
|
return current.astimezone(UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
|
|
|
|
def from_iso(value: str) -> datetime:
|
|
return datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
|
|
|
|
def expires_in(days: int) -> str:
|
|
return to_iso(utc_now() + timedelta(days=days))
|