Ambiguity is resolved without a word¶
When time zone offsets change—most commonly due to daylight saving time—a local clock time may occur twice or not at all.
Python resolves these ambiguities with the fold parameter, which defaults to 0.
That’s not inherently wrong: having a deterministic default is often useful.
The problem is that it’s difficult to handle ambiguity explicitly:
There is no option to raise an error (instead of picking a default)
The
foldparameter is subtle and poorly discoverableMany users are unaware ambiguity exists at all
# does `fold` matter here? Hard to tell!
datetime(2024, 10, 27, 2, 30, tzinfo=ZoneInfo("Europe/Amsterdam"), fold=1)
Without careful handling, code may interpret a repeated local time differently than intended.
How whenever solves this¶
whenever applies the same default as Python, but with an
ImplicitDisambiguationWarning; state disambiguation= to make the choice explicit:
>>> dt = ZonedDateTime(2024, 10, 27, 2, 30, tz="Europe/Amsterdam", disambiguation="raise")
Traceback (most recent call last):
...
RepeatedTime: 2024-10-27 02:30:00 is repeated in time zone 'Europe/Amsterdam'