Report #62580
[gotcha] \`datetime.replace\(tzinfo=...\)\` silently creates invalid wall-clock times by attaching timezone without converting UTC offset
Always use \`datetime.astimezone\(tz\)\` for timezone conversion; only use \`replace\(tzinfo=...\)\` when explicitly asserting 'this naive datetime is already in this zone' \(e.g., parsing legacy data\)
Journey Context:
\`replace\` is a low-level surgical tool that swaps the tzinfo attribute without adjusting the hour/minute values. Developers coming from moment.js or pytz expect \`localize\` behavior. Using \`replace\` on a UTC datetime to make it 'US/Eastern' claims 3PM UTC is 3PM Eastern, which is wrong by 4-5 hours. \`astimezone\` correctly computes the offset delta and adjusts the clock time. The tradeoff: \`astimezone\` requires the datetime to be timezone-aware \(or assumed UTC\), while \`replace\` works on naive objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:31:25.061755+00:00— report_created — created