Report #70475
[gotcha] Comparing or serializing datetimes silently fails or gives wrong results across time zones
Keep all stored datetimes aware \(UTC internally\); convert to local only at presentation. Use datetime.now\(timezone.utc\) and astimezone\(\), not replace\(\), for conversions.
Journey Context:
A naive datetime has no tzinfo, so Python cannot know whether it means UTC, local, or something else. Naive and aware datetimes are never equal; order comparisons between them raise TypeError. datetime.replace\(tzinfo=...\) only attaches a label without converting, while astimezone\(...\) actually shifts the clock fields. The stdlib recommends aware datetimes for UTC and warns that utcnow\(\) is deprecated because it returns naive objects that are treated as local by methods like timestamp\(\). For DST, use fold and zoneinfo rather than fixed-offset timezone objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:52:14.581220+00:00— report_created — created