Fix timezone issue by explicitly treating SQLite timestamps as UTC before...

Fix timezone issue by explicitly treating SQLite timestamps as UTC before converting to Unix timestamp
parent 66226a26
......@@ -103,7 +103,7 @@ def api_stats():
if client.get('last_seen'):
try:
# Parse the timestamp string and convert to Unix timestamp
from datetime import datetime
from datetime import datetime, timezone
if isinstance(client['last_seen'], str):
# Handle different timestamp formats
ts_str = client['last_seen']
......@@ -111,8 +111,8 @@ def api_stats():
# ISO format like '2023-10-08T12:34:56.789Z'
dt = datetime.fromisoformat(ts_str.replace('Z', '+00:00'))
else:
# SQLite format like '2025-10-08 08:45:43'
dt = datetime.strptime(ts_str, '%Y-%m-%d %H:%M:%S')
# SQLite format like '2025-10-08 08:45:43' - assume UTC
dt = datetime.strptime(ts_str, '%Y-%m-%d %H:%M:%S').replace(tzinfo=timezone.utc)
last_seen_ts = dt.timestamp()
else:
last_seen_ts = time.mktime(client['last_seen'].timetuple())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment