Repository navigation
Conversation
In Ruby 1.8 and 1.9.2, Date#+ with a Float stored a Float day number, and the dump has the Float. old_to_new kept a Float second fraction for the dump, and the loaded date was eql? to a date with a different hash. old_to_new now converts a Float day number to a Rational. Co-authored-by: Claude Mythos 5.2 <noreply@anthropic.com>
wtn
marked this pull request as ready for review
November 28, 2026 23:02
jeremyevans
approved these changes
Nov 29, 2026
jeremyevans
left a comment
Contributor
There was a problem hiding this comment.
I guess this is OK, though I find it unlikely that anyone has marshal data from a Ruby version that old with float dates.
Comment on lines
+89
to
+95
|
|
||
| d = Date.allocate | ||
| d.marshal_load([0.5, Date::ITALY]) | ||
| d2 = Date.allocate | ||
| d2.marshal_load([Rational(1, 2), Date::ITALY]) | ||
| assert_equal(d2, d) | ||
| assert_equal(d2.hash, d.hash) |
Contributor
There was a problem hiding this comment.
Support for fractional dates in Date is already deprecated, so I don't think we need a test for this. If we do add a test for it, we should change the marshal load support so it issues a deprecation warning when attempting to restore a Date with a fractional day.
Suggested change
| d = Date.allocate | |
| d.marshal_load([0.5, Date::ITALY]) | |
| d2 = Date.allocate | |
| d2.marshal_load([Rational(1, 2), Date::ITALY]) | |
| assert_equal(d2, d) | |
| assert_equal(d2.hash, d.hash) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Ruby 1.8 and 1.9.2, the dump of a date has a Float day number after a Float is added to the date:
But a DateTime loaded from the array does not work as a Hash key. The loaded DateTime is
eql?to a DateTime fromDateTime.newfor the same time, and the two have different hashes:The hashes differ because
marshal_loadgives the loaded DateTime a Float second fraction, whereDateTime.newgives an Integer or a Rational.Fix
marshal_loadnow converts a Float day number to a Rational before the second fraction is computed. In the example,d.sec_fractionis(0/1), the two hashes are equal, and{d => 1}[e]returns 1.