Fixed python time again.. and again.. and again..
This commit is contained in:
parent
dd3de9b380
commit
c0de46b41a
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user