Skip to content

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

Open
yangbaechu wants to merge 1 commit into
python:mainfrom
yangbaechu:gh-155023-datetime-time-subminute-offset
Open

gh-99772: Fix datetime.time comparison and hashing for sub-minute UTC offsets#155024
yangbaechu wants to merge 1 commit 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 saitejabandaru-in left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me. The logic correctly handles the sub-minute UTC offset conversions by normalizing to microseconds across both the Python and C implementations, and the tests adequately cover equality, ordering, and hashing for these edge cases. Thanks for fixing this!

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants