From d3306120d591038b8b34653fe48262b0cfb46c1c Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Sun, 8 Mar 2020 19:50:59 -0400 Subject: [PATCH] Fix epoch time field to properly use utc --- keyosk/_fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyosk/_fields.py b/keyosk/_fields.py index 5da914f..50daeed 100644 --- a/keyosk/_fields.py +++ b/keyosk/_fields.py @@ -91,7 +91,7 @@ class Epoch(msh.fields.Field): """Serialize a datetime object to an integer""" if isinstance(value, datetime): - return int(value.timestamp()) + return int(value.replace(tzinfo=datetime.timezone.utc).timestamp()) return value def _deserialize(self, value: int, attr, data, **kwargs) -> datetime: @@ -104,7 +104,7 @@ class Epoch(msh.fields.Field): raise msh.ValidationError( f"Invalid epoch value '{value}' of type '{type(value)}'" ) - return datetime.fromtimestamp(int(value)) + return datetime.utcfromtimestamp(int(value)) class RawMultiType(msh.fields.Raw):