Python time zone bugs trace to naive datetimes and the repeated hour, per the docs
A review of Python's official datetime and zoneinfo documentation explains that many time zone bugs stem from naive datetime objects, which lack the information to pin down a specific moment. The docs define an object as aware if its utcoffset() returns a value rather than None, and note that date objects are always naive. Functions like utcnow() and fromtimestamp() without a timezone argument return naive objects, so the recommended approach is to pass timezone.utc explicitly. During the repeated hour at the end of daylight saving time, the fold attribute resolves which of the two matching moments is meant, and converting from UTC sets it automatically. Adding a timedelta does not apply time zone adjustments, so arithmetic across a transition can produce a wall time that differs from what one might expect.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in