13 lines
361 B
Python
13 lines
361 B
Python
"""Serialize UTC database timestamps consistently across PostgreSQL and SQLite."""
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
from fastapi.encoders import jsonable_encoder
|
|
|
|
|
|
def encode_snapshot(value):
|
|
return jsonable_encoder(
|
|
value,
|
|
custom_encoder={datetime: lambda item: item.replace(tzinfo=item.tzinfo or timezone.utc).isoformat()},
|
|
)
|