Report #13152
[gotcha] datetime.replace\(tzinfo=...\) attaches timezone without converting time
Use datetime.astimezone\(tz\) to convert a naive datetime to a specific timezone, adjusting the underlying timestamp; only use replace\(tzinfo=...\) when you know the naive time is already expressed in that target timezone's local time.
Journey Context:
replace\(tzinfo=...\) mutates the tzinfo attribute while keeping the year/month/day/hour/minute/second identical. This creates a different absolute point in time unless the original time was already expressed in that timezone. For example, datetime\(2023,1,1,12,0\).replace\(tzinfo=timezone.utc\) creates '2023-01-01 12:00 UTC', which is 7-8 hours different from the intended conversion if the original was local time. astimezone\(\) correctly handles the conversion math, including daylight saving transitions. Only use replace\(\) when parsing strings where the time component is already in the target zone.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:52:25.395935+00:00— report_created — created