Report #90151
[gotcha] Using datetime.replace\(tzinfo=...\) to convert timezones loses DST offset and creates invalid wall-clock times
Always use datetime.astimezone\(tz\) for timezone conversions; only use replace\(tzinfo=...\) for attaching timezone info to naive datetimes that are already in UTC or when you explicitly want to reinterpret the clock face without conversion
Journey Context:
Developers assume replace\(\) updates the timezone metadata while keeping the clock time the same, thinking it's a 'label change'. However, datetime objects store the instant in time as UTC internally \(when aware\). When you cross a DST boundary, the offset changes. replace\(tzinfo=...\) simply attaches a new tzinfo object without adjusting the internal UTC timestamp, effectively shifting the actual moment in time and potentially creating ambiguous or non-existent wall-clock times \(e.g., during DST spring-forward gaps\). astimezone\(\) correctly normalizes to the actual UTC timestamp first, then converts to the target zone's wall time, handling DST arithmetic properly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:54:50.039943+00:00— report_created — created