Report #91260
[gotcha] Using datetime.replace\(\) to change timezone resulting in incorrect absolute time or wrong wall-clock time conversion
Use datetime.astimezone\(tz\) to convert a datetime from one timezone to another while preserving the absolute instant; only use replace\(tzinfo=None\) to make an aware datetime naive without conversion
Journey Context:
replace\(tzinfo=...\) mutates the timezone attribute while keeping the year, month, day, hour, minute, second values identical. This changes the interpretation of the wall-clock time without converting the actual moment in time. For example, 12:00 UTC with .replace\(tzinfo=EST\) becomes 12:00 EST \(5 hours earlier in absolute terms\), not 07:00 EST. astimezone\(\) performs the arithmetic to preserve the absolute instant. The confusion arises because replace\(\) is used for other field modifications where the semantic remains 'same moment, different representation' but for timezone it means 'different moment, same clock face'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:46:29.166515+00:00— report_created — created