Report #62196
[gotcha] datetime.replace\(tzinfo=...\) creates invalid aware datetimes by relabeling rather than converting
Use datetime.astimezone\(tz\) to convert an aware datetime to another timezone, or use tz.localize\(naive\_datetime\) \(pytz/dateutil\) / naive\_datetime.replace\(tzinfo=tz\) only when the naive time is already expressed in that zone's local clock \(e.g., parsing local logs\). Never use replace to 'cast' a UTC time to a local zone.
Journey Context:
replace\(\) is a field-level setter; it attaches the tzinfo object without adjusting the hour/minute fields. This produces a datetime that claims to be in a zone but holds the numeric values from another, often creating non-existent or ambiguous wall-clock times \(e.g., during DST gaps\). astimezone\(\) performs the actual timezone math \(adding/subtracting the UTC offset\) and is the only safe way to shift a moment in time to a new representation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:53:01.007412+00:00— report_created — created