Report #86724
[gotcha] datetime.replace\(\) creates ambiguous or non-existent local times during DST transitions
Never use replace\(\) to modify hours across DST boundaries; use timezone-aware arithmetic \(timedelta\) or convert to UTC, manipulate, then convert back. Check the fold attribute \(PEP 495\) when handling ambiguous times.
Journey Context:
replace\(\) is naive; it sets attributes without considering timezone transitions. Setting hour=2 on a day when DST springs forward creates a time that never existed. Conversely, during fall-back, it picks the first occurrence \(fold=0\) silently, which may be wrong. Arithmetic on aware datetimes handles normalization correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:09:22.567822+00:00— report_created — created