on-internet
← Community

Why does Python return True when comparing two datetime objects with different UTC timestamps?

Stack Overflow ·

I'm developing a Python application that stores scheduled events using timezone-aware datetime objects. I encountered an unexpected behaviour when handling Daylight Saving Time (DST). from datetime import datetime from zoneinfo import ZoneInfo tz = ZoneInfo("America/New_York") first = datetime(2024, 11, 3, 1, 30, tzinfo=tz, fold=0) second = datetime(2024, 11, 3, 1, 30, tzinfo=tz, fold=1) print("First timestamp:", first.timestamp()) print("Second timestamp:", second.timestamp()) print("Are they equal?", first == second) events = { first: "First event", second: "Second event" } print("Dictionary

Comments

Sign in or sign up to comment and upvote.

No comments yet.