-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JSON encoding of datetimes with zoneinfo tzinfos
This fixes a bug where datetime objects with `zoneinfo.ZoneInfo` instances set for `tzinfo` would encode as UTC, ignoring the zoneinfo. This issue was due to `datetime.utcoffset` being called with `None` instead of the `datetime` instance. This worked fine for other `tzinfo` types (like `datetime.timezone`) since those use fixed offsets that aren't date aware. This also fixes a bug where `datetime.time` instances with a `tzinfo` that returns `None` from `datetime.time.utcoffset` were treated as UTC rather than naive. Quoting from the standard library docs: > A datetime object d is aware if both of the following hold: > > 1. d.tzinfo is not None > 2. d.tzinfo.utcoffset(d) does not return None > > Otherwise, d is naive. > > A time object t is aware if both of the following hold: > > 1. t.tzinfo is not None > 2. t.tzinfo.utcoffset(None) does not return None. > > Otherwise, t is naive. Both bugs fixed above were due to incorrect behavior around the 2nd condition using `utcoffset`.
- Loading branch information
Showing
3 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters