Report #15362
[gotcha] datetime arithmetic errors during DST transition \(ambiguous time fold\)
Always use aware datetimes with proper timezone objects \(zoneinfo/dateutil\), never \`replace\(tzinfo=...\)\`. For times in the 'fold' \(duplicate hour when DST ends\), explicitly set \`fold=1\` on the second occurrence before conversion or arithmetic. Convert to UTC before doing arithmetic, then convert back, to avoid DST boundary issues entirely.
Journey Context:
When clocks 'fall back', local times like 1:30 AM occur twice. Without PEP 495's \`fold\` attribute \(3.6\+\), both occurrences look identical but represent different UTC instants. Using \`pytz\` or naive datetimes, arithmetic across this boundary subtracts the DST offset change \(e.g., 1 hour\), giving wrong durations. The \`fold\` attribute disambiguates, but most developers don't know it exists and use \`dateutil\` or \`zoneinfo\` improperly. The robust fix is UTC-first arithmetic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:51:57.077404+00:00— report_created — created