Please see Strict Invalid Time Checking section in PEP 495:

https://peps.python.org/pep-0495/#strict-invalid-time-checking

It contains example code for detecting both non-existing and ambiguous
times.

On Mon, Nov 14, 2022 at 10:41 PM <[email protected]> wrote:

> Working on improving zoneinfo support in pandas, I want to check for
> non-existent datetimes.  e.g.
>
> ```
> from datetime import datetime, timezone
> import zoneinfo
>
> tz = zoneinfo.ZoneInfo("US/Pacific")
>
> dt = datetime(2014, 3, 9, 2, tzinfo=tz)   # <- want to tell if this exists
>
> roundtrip = dt.astimezone(timezone.utc).astimezone(tz)
>
> if roundtrip != dt:
>      raise ValueError("Nonexistent!")
> ```
>
> Is checking for round-tripping a) correct and b) the suggested way of
> doing this?
> _______________________________________________
> Datetime-SIG mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/datetime-sig.python.org/
> The PSF Code of Conduct applies to this mailing list:
> https://www.python.org/psf/codeofconduct/
>
_______________________________________________
Datetime-SIG mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/datetime-sig.python.org/
The PSF Code of Conduct applies to this mailing list: 
https://www.python.org/psf/codeofconduct/

Reply via email to