You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON encoder does not respect ZoneInfo (the IANA time zone database) when encoding datetime objects. #533
When using the JSON encoder on datetime objects with a timezone set using the IANA time zone database record, the encoder will not convert the datetime to UTC, only drop the timezone. This is not the case with the msgpack encoder, which correctly converts the datetime to UTC and removes the timezone.
I've replicated the issue using the Zone Info module from the Standard Library and the 3rd party module python-dateutil.
Minimal example:
importdatetimefromzoneinfoimportZoneInfoimportmsgspecfoo=datetime.datetime.now(tz=ZoneInfo("Europe/Prague"))
foo.isoformat()
# > 2023-08-24T12:17:59.327527+02:00# NOT converted to UTCfoo_json=msgspec.json.decode(msgspec.json.encode(foo), type=datetime.datetime)
foo_json.isoformat()
# > 2023-08-24T12:17:59.327527+00:00# Converted to UTCfoo_msgpack=msgspec.msgpack.decode(msgspec.msgpack.encode(foo), type=datetime.datetime)
foo_msgpack.isoformat()
# > 2023-08-24T10:17:59.327527+00:00
Activity
jcrist commentedon Aug 24, 2023
Thanks for the excellent reproducible issue, this should be fixed by #534.