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
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
The text was updated successfully, but these errors were encountered:
Description
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:
The text was updated successfully, but these errors were encountered: