fix: _Timestamp.to_datetime works with negative ts

This commit is contained in:
Georg K 2023-04-05 13:02:25 +03:00
parent d2af2f2fac
commit b81195eb44

View File

@ -1578,7 +1578,11 @@ class _Timestamp(Timestamp):
def to_datetime(self) -> datetime:
ts = self.seconds + (self.nanos / 1e9)
return datetime.fromtimestamp(ts, tz=timezone.utc)
if ts < 0:
return datetime(1970, 1, 1) + timedelta(seconds=ts)
else:
return datetime.fromtimestamp(ts, tz=timezone.utc)
@staticmethod
def timestamp_to_json(dt: datetime) -> str: