Report #35106
[gotcha] Naive datetime arithmetic silently fails across DST boundaries producing wrong durations
Always convert naive datetimes to UTC \(or timezone-aware with fold handling\) before performing arithmetic, then convert back; never subtract or add timedeltas to naive local times that might cross DST transitions.
Journey Context:
When you subtract two naive datetimes representing local wall-clock times, Python calculates the absolute difference in seconds, ignoring any DST shifts that occurred between the two timestamps. If the interval crosses a 'spring forward' transition, the naive calculation suggests a longer duration than actually elapsed; if it crosses a 'fall back' transition, it suggests a shorter duration. Developers expect '3pm minus 1pm equals 2 hours' to hold regardless of DST, but during the transition day this fails silently. The alternatives considered were using pytz \(deprecated\) or dateutil to normalize, but the robust pattern is to treat all arithmetic as happening in UTC or strictly-continuous timezone-aware objects \(with proper fold handling per PEP 495\). The key insight is that 'naive local time' is a presentation format, not a calculation format; arithmetic on wall-clock time is undefined behavior across discontinuities.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:23:52.115129+00:00— report_created — created