Fixed python time again.. and again.. and again..

This commit is contained in:
Brage Skjønborg 2026-01-23 02:14:19 +01:00
parent dd3de9b380
commit c0de46b41a

View File

@ -7,5 +7,13 @@ def utc_now():
def parse_mysql_ts(value):
if value is None:
return None
return datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=timezone.utc)
# Hvis DB-driveren allerede har gjort jobben
if isinstance(value, datetime):
# Sørg for at den er timezone-aware
if value.tzinfo is None:
return value.replace(tzinfo=timezone.utc)
return value
# Hvis det er en streng (MySQL-format)
return datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=timezone.utc)