Report #43871
[gotcha] Subtracting naive datetimes across Daylight Saving Time transition gives incorrect elapsed time
Convert both to UTC before subtraction, or use aware datetimes with IANA timezone database \(zoneinfo\) and handle fold
Journey Context:
Naive datetimes represent wall-clock time without timezone context. During a 'fall back' transition, 1:30 AM occurs twice; during 'spring forward', an hour is skipped. Simple subtraction treats all hours as 3600 seconds, ignoring the DST offset shift. Python's datetime arithmetic is 'wall-clock' arithmetic for naive times. The fix requires absolute time \(UTC\) or the fold-aware timezone handling from PEP 495. Using zoneinfo \(3.9\+\) or pytz, localize the naive time, convert to UTC, then subtract.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:06:38.992403+00:00— report_created — created