jcrist · GitHub

@jcrist

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`.

Read the original on github.com ↗