Repository navigation
fix(diff): count months from the start date, not the last step - #480
Merged
spencermountain merged 1 commit intoOct 30, 2026
Merged
Conversation
diff() counts the leftover months by adding one month at a time to
the previous result. Once a month-end got clamped (jan 31 -> feb 28)
every later step kept the shorter day, so the count ran over:
spacetime('2023-01-31').diff('2023-03-30', 'months') // 2, not 1
spacetime('2008-05-31').diff('2009-05-29', 'months') // 12, not 11
and quarters, which are derived from months % 12, came out as 0 for
the second one. Add i units to the start date on each step instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
good catch! thank you! |
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.
diff() counted leftover months by adding one month to the previous result, so after a clamp (jan 31 → feb 28) every later step kept the shorter day:
Each step now adds i units to the start date. Tests added in tests/comparisons/diff.test.js; they fail on master and pass with the change.
I used Claude Code to write this change.