Repository navigation
fix(add): walk to the target year when adding years - #479
Merged
spencermountain merged 1 commit intoOct 29, 2026
Merged
Conversation
add(n, 'year') moves the epoch by n * 365.05 days, nudges it by a
guessed number of leap days, then walks the month and date back.
The year itself was never set, so when the guess fell short or went
too far the result kept the wrong year:
spacetime('2023-01-01').add(11, 'year') // 2033-01-01, not 2034
spacetime('2040-12-31T22:26').add(2, 'year') // 2043-12-31, not 2042
From Feb 29 the month-length clamp also used the starting leap year,
so walkTo() was asked for Feb 29 in a common year and gave up
part-way:
spacetime('2024-02-29').add(13, 'year') // 2037-02-25, not 2037-02-28
Set the target year on the wanted fields, so the year is walked to
directly and Feb 29 is clamped against the year we land in.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
thank you!! |
Merged
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.
add(n, 'year')never set the year itself, so when the leap-day guess was off the year was wrong, and from Feb 29 the clamp used the old leap year:This sets the target year on the wanted fields, so walkTo() goes there directly and Feb 29 clamps to the 28th in a common year. Tests added in tests/arithmetic/add.test.js; they fail on master and pass with the change.
I used Claude Code to write this change.