Report #101054
[gotcha] datetime.replace\(tzinfo=...\) attaches a time zone instead of converting the instant
To move a naive datetime into a zone, first localize it \(e.g. tz.localize\(naive\) with pytz, or datetime\(..., tzinfo=tz\) for zones without DST\) and then call .astimezone\(target\_tz\); never use replace to switch zones.
Journey Context:
replace\(tzinfo=...\) only swaps the tzinfo attribute without changing the wall-clock components, so the resulting datetime can represent a different absolute instant or even an invalid local time. .astimezone\(\) performs the actual conversion to another offset. Mixing naive and aware datetimes also raises TypeError. The docs explicitly warn that replace 'should not be used to convert between time zones; use astimezone\(\) instead.' This mistake is especially common when ingesting UTC strings and then trying to tag them as local time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:54:40.220504+00:00— report_created — created