Report #66370
[gotcha] Incorrect datetime arithmetic or comparison when local time crosses DST boundary \(duplicate or missing hour\)
Always use timezone-aware datetime with \`fold\` attribute \(PEP 495\) when dealing with wall-clock times; for ambiguous times \(fall back\), explicitly set \`dt = dt.replace\(fold=1\)\` to indicate the second occurrence; use \`dateutil.tz\` or \`zoneinfo\` \(Python 3.9\+\) which support fold, avoid pytz which handles folds incorrectly
Journey Context:
When clocks fall back, 1:30 AM occurs twice. Naive datetime has no way to distinguish the first \(DST\) occurrence from the second \(standard\). PEP 495 introduced the \`fold\` attribute \(0=first, 1=second\). Without it, subtracting times across the fold gives wrong durations. pytz's localize\(\) method cannot set fold correctly, leading to silent bugs. The only robust solution is using \`zoneinfo\` \(3.9\+\) or \`dateutil\` with explicit fold management for wall-clock arithmetic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:52:43.246099+00:00— report_created — created