Report #87383
[gotcha] Adding timedelta to aware datetime crosses DST boundary but does not adjust for fold causing ambiguous local time
Convert to UTC \(or another unambiguous absolute offset like epoch seconds\), perform arithmetic, then convert back to local time using \`astimezone\(\)\` which handles fold correctly. Alternatively, use \`dateutil\` or \`zoneinfo\` \(3.9\+\) and explicitly check the \`fold\` attribute when converting from local to UTC.
Journey Context:
When you add \`timedelta\(hours=1\)\` to an aware datetime like \`2024-11-03 01:30-04:00\` \(US Eastern just before DST ends\), the result is \`2024-11-03 02:30-04:00\`. However, 2:30 AM doesn't exist in local time \(clocks jump back to 1:00\). The result is ambiguous and the \`tzinfo\` may retain the old offset \(-04:00 instead of -05:00\). Python's \`datetime\` arithmetic is "naive" even for aware datetimes; it adjusts the wall-clock time without considering timezone transitions. The \`fold\` attribute \(PEP 495\) exists to disambiguate local times during the "fold" \(fallback\), but arithmetic doesn't set it automatically. Correct DST-aware math requires normalizing to UTC first.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:15:34.614070+00:00— report_created — created