1
0
mirror of https://github.com/enpaul/keyosk.git synced 2024-11-24 23:47:49 +00:00

Fix epoch time field to properly use utc

This commit is contained in:
Ethan Paul 2020-03-08 19:50:59 -04:00
parent bed608a2a5
commit d3306120d5

View File

@ -91,7 +91,7 @@ class Epoch(msh.fields.Field):
"""Serialize a datetime object to an integer""" """Serialize a datetime object to an integer"""
if isinstance(value, datetime): if isinstance(value, datetime):
return int(value.timestamp()) return int(value.replace(tzinfo=datetime.timezone.utc).timestamp())
return value return value
def _deserialize(self, value: int, attr, data, **kwargs) -> datetime: def _deserialize(self, value: int, attr, data, **kwargs) -> datetime:
@ -104,7 +104,7 @@ class Epoch(msh.fields.Field):
raise msh.ValidationError( raise msh.ValidationError(
f"Invalid epoch value '{value}' of type '{type(value)}'" f"Invalid epoch value '{value}' of type '{type(value)}'"
) )
return datetime.fromtimestamp(int(value)) return datetime.utcfromtimestamp(int(value))
class RawMultiType(msh.fields.Raw): class RawMultiType(msh.fields.Raw):