File size: 524 Bytes
7ca0188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""UTC timestamp and elapsed-time helpers."""

from datetime import datetime, timezone
from time import time_ns


def current_utc_iso() -> str:
    """Return a timezone-aware UTC timestamp in ISO 8601 format."""

    return datetime.now(timezone.utc).isoformat()


def now_ms() -> int:
    """Return Unix time in integer milliseconds."""

    return time_ns() // 1_000_000


def elapsed_ms(start_ms: int) -> int:
    """Return non-negative elapsed milliseconds since ``start_ms``."""

    return max(0, now_ms() - start_ms)