Fix dict encoding for timezone aware datetimes (#468)

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
This commit is contained in:
Jinyu Liu
2023-04-13 18:34:19 -04:00
committed by GitHub
parent b0b6cd24ad
commit 2b41383745
4 changed files with 97 additions and 0 deletions

View File

@@ -1583,6 +1583,9 @@ class _Timestamp(Timestamp):
@staticmethod
def timestamp_to_json(dt: datetime) -> str:
nanos = dt.microsecond * 1e3
if dt.tzinfo is not None:
# change timezone aware datetime objects to utc
dt = dt.astimezone(timezone.utc)
copy = dt.replace(microsecond=0, tzinfo=None)
result = copy.isoformat()
if (nanos % 1e9) == 0: