Skip to content

Fix DateTime#hash for a Rational second fraction - #212

Open
wtn wants to merge 1 commit into
ruby:masterfrom
wtn:hash
Open

wtn wants to merge 1 commit into
ruby:masterfrom
wtn:hash

Conversation

@wtn

@wtn wtn commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

A DateTime stores a second fraction (such as ⅓ second) as a Rational. d_lite_hash uses the address of the Rational as hash input, so two DateTimes that are eql? have different hashes:

a = DateTime.new(2000, 1, 1, 0, 0, Rational(1, 3))
b = DateTime.new(2000, 1, 1, 0, 0, Rational(1, 3))
a.eql?(b)        # => true
a.hash == b.hash # => false
{a => 1}[b]      # => nil

d_lite_hash now calls rb_hash on a Rational second fraction.

Follow-up to 31f07bc, which made the same change for a large year.

d_lite_hash used the address of a Rational second fraction as hash
input, so two eql? DateTimes with a second fraction such as 1/3 second
had different hashes. d_lite_hash now calls rb_hash on the Rational.

Co-authored-by: Claude Mythos 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant