13 lines
335 B
Python
13 lines
335 B
Python
from datetime import UTC, datetime
|
|
|
|
# Every timestamp in the DB uses this exact format, so string comparison == chronological comparison.
|
|
DB_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
|
|
|
|
|
|
def utcnow() -> datetime:
|
|
return datetime.now(UTC).replace(microsecond=0)
|
|
|
|
|
|
def to_db(dt: datetime) -> str:
|
|
return dt.astimezone(UTC).strftime(DB_FORMAT)
|