Report #91876
[gotcha] Datetime arithmetic ignores DST fold causing off-by-one-hour duration errors
Use \`datetime.replace\(fold=1\)\` to explicitly select the second \(DST\) occurrence during ambiguous autumn transitions, and perform arithmetic using timezone-aware objects with \`zoneinfo\` \(3.9\+\) or \`dateutil\` rather than naive datetime subtraction.
Journey Context:
When clocks fall back, the same wall-clock time occurs twice \(fold=0 first occurrence, fold=1 second\). Naive subtraction treats both as the same instant, yielding zero duration or incorrect offsets. PEP 495 introduced the \`fold\` attribute to disambiguate, but most arithmetic ignores it \(comparisons treat fold=0 and fold=1 as equal for ordering\). The solution is to handle ambiguous times explicitly and rely on timezone-aware libraries that respect \`fold\` \(e.g., \`dateutil\` or \`zoneinfo\` with proper IANA database support\), avoiding naive arithmetic across DST boundaries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:48:18.507936+00:00— report_created — created