Skip to content

gh-99772: Fix datetime.time comparison and hashing for sub-minute UTC offsets - #155024

Merged
StanFromIreland merged 3 commits into
python:mainfrom
yangbaechu:gh-155023-datetime-time-subminute-offset
Sep 7, 2026
Merged

gh-99772: Fix datetime.time comparison and hashing for sub-minute UTC offsets#155024
StanFromIreland merged 3 commits into
python:mainfrom
yangbaechu:gh-155023-datetime-time-subminute-offset

Conversation

@yangbaechu

@yangbaechu yangbaechu commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

closes #155023.

This PR fixes datetime.time comparison and hashing when UTC offsets contain seconds or microseconds.

The C comparison now includes the complete offset by normalizing each time to signed microseconds. The pure Python comparison uses the same integer normalization, and its hash uses the normalized value wall time - UTC offset.

The shared tests cover equality, ordering, and hashing with second and microsecond offsets, including a negative microsecond offset. They run against both the C and pure Python implementations.

…ute UTC offsets

Normalize the complete UTC offset in the C and pure Python comparison paths, and align the pure Python hash with the C implementation. Add shared regression tests for both implementations.
saitejabandaru-in

This comment was marked as off-topic.

@StanFromIreland StanFromIreland changed the title gh-155023: Fix datetime.time comparison and hashing for sub-minute UTC offsets gh-99772: Fix datetime.time comparison and hashing for sub-minute UTC offsets Aug 1, 2026

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few little nits.

Comment thread Lib/test/datetimetester.py Outdated
Comment thread Lib/test/datetimetester.py Outdated
Comment thread Lib/_pydatetime.py Outdated
Comment thread Lib/test/datetimetester.py
@StanFromIreland
StanFromIreland merged commit 5d24802 into python:main Sep 7, 2026
58 checks passed
@StanFromIreland

Copy link
Copy Markdown
Member

Since we're changing hashes, I'm hesitant to backport as it may break things, so leaving it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datetime.time comparisons and hashing mishandle sub-minute UTC offsets

3 participants