fix timezone handling for timestamps from the database

SQLite is not timezone-aware, so make sure to convert to UTC
before inserting any data.
This commit is contained in:
Sarah Hoffmann
2024-01-06 22:31:38 +01:00
parent f03ec3ea12
commit 474d4230b8
2 changed files with 16 additions and 4 deletions

View File

@@ -37,7 +37,10 @@ async def get_status(conn: SearchConnection) -> StatusResult:
status.data_updated = await conn.scalar(sql)
if status.data_updated is not None:
status.data_updated = status.data_updated.replace(tzinfo=dt.timezone.utc)
if status.data_updated.tzinfo is None:
status.data_updated = status.data_updated.replace(tzinfo=dt.timezone.utc)
else:
status.data_updated = status.data_updated.astimezone(dt.timezone.utc)
# Database version
try: