Menu

Python says these times are equal. They’re an hour apart.
📰

Python says these times are equal. They’re an hour apart.

DEV Community: python·Brodyga 45·about 4 hours ago
#PN1ZmOaS
#devtopython#devto#dev#print#timezone
Reading 0:00
15s threshold

Cedrik built Clockshift to inspect local schedules around clock changes. While checking a weekend example, I found a second surprise in Python: two timezone-aware values printed different UTC offsets and still compared equal.

Belgrade turns its clocks back on 25 October 2026 , from 03:00 to 02:00. The local time 02:30 occurs twice. The published clock-change date supplies the calendar context; the code below checks the two occurrences.

Two values, one surprising comparison

from datetime import datetime , timezone from zoneinfo import ZoneInfo

zone = ZoneInfo ( " Europe/Belgrade " ) first = datetime ( 2026 , 10 , 25 , 2 , 30 , tzinfo = zone , fold = 0 ) second = first . replace ( fold = 1 )

print ( first . isoformat ()) print ( second . isoformat ()) print ( first == second ) print (( second - first ).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.