Report #24275
[gotcha] datetime.replace\(tzinfo=...\) creates fixed-offset naive of DST causing ambiguous or non-existent times
Use datetime.astimezone\(tz\) instead of replace\(tzinfo=tz\); astimezone consults the tzinfo object's utcoffset\(\) at the specific datetime instance, correctly handling variable DST offsets
Journey Context:
Developers often treat tzinfo as a timezone label, but it is actually a fixed offset from UTC. When you replace\(tzinfo=EST\), Python stores -05:00 permanently. During daylight saving transitions, this creates invalid local times \(e.g., 2:30 AM on spring-forward day does not exist\). astimezone\(\) properly calculates the offset for that exact moment, handling the gap or fold correctly. This distinction is critical for scheduling systems and calendar applications crossing DST boundaries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:09:20.944270+00:00— report_created — created