Report #14395
[gotcha] Using datetime.replace to add timezone info fails at DST transitions
Always use pytz.timezone.localize\(\) or zoneinfo.ZoneInfo for aware datetimes; never use .replace\(tzinfo=...\) for local times
Journey Context:
When converting naive datetimes to aware ones, .replace\(tzinfo=...\) sets the timezone without considering DST offsets. At transition points \(e.g., 2:00 AM -> 3:00 AM\), this creates invalid or ambiguous times that comparison operators handle inconsistently. pytz.localize\(\) and ZoneInfo handle fold/ambiguous attributes correctly. People choose .replace\(\) because it's 'simpler' and doesn't require importing pytz/zoneinfo, but it's silently wrong twice a year.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:23:49.581294+00:00— report_created — created