From 9ed579fa3556e91cffd90c3caad93b319e8c2396 Mon Sep 17 00:00:00 2001 From: Georg K Date: Mon, 20 Nov 2023 22:46:34 +0300 Subject: [PATCH] fix: datetime offsets --- src/betterproto/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/betterproto/__init__.py b/src/betterproto/__init__.py index b2a63d8..1b072c2 100644 --- a/src/betterproto/__init__.py +++ b/src/betterproto/__init__.py @@ -1943,6 +1943,8 @@ class _Timestamp(Timestamp): # manual epoch offset calulation to avoid rounding errors, # to support negative timestamps (before 1970) and skirt # around datetime bugs (apparently 0 isn't a year in [0, 9999]??) + if dt.tzinfo is None: + dt = dt.replace(tzinfo=timezone.utc) offset = dt - DATETIME_ZERO # below is the same as timedelta.total_seconds() but without dividing by 1e6 # so we end up with microseconds as integers instead of seconds as float