37 lines
No EOL
965 B
Python
37 lines
No EOL
965 B
Python
"""
|
|
Timezone utilities for consistent timestamp handling across the gateway.
|
|
Ensures all timestamps are properly handled as UTC.
|
|
"""
|
|
|
|
from datetime import datetime, timezone
|
|
import time
|
|
|
|
def getUtcNow() -> datetime:
|
|
"""
|
|
Get current time in UTC with timezone info.
|
|
|
|
Returns:
|
|
datetime: Current UTC time with timezone info
|
|
"""
|
|
return datetime.now(timezone.utc)
|
|
|
|
def getUtcTimestamp() -> float:
|
|
"""
|
|
Get current UTC timestamp (seconds since epoch with millisecond precision).
|
|
|
|
Returns:
|
|
float: Current UTC timestamp in seconds with millisecond precision
|
|
"""
|
|
return time.time()
|
|
|
|
def createExpirationTimestamp(expiresInSeconds: int) -> float:
|
|
"""
|
|
Create a new expiration timestamp from seconds until expiration.
|
|
|
|
Args:
|
|
expiresInSeconds (int): Seconds until expiration
|
|
|
|
Returns:
|
|
float: UTC timestamp in seconds
|
|
"""
|
|
return getUtcTimestamp() + expiresInSeconds |