-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix non-ISO calendar month arithmetic #1761
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1761 +/- ##
==========================================
+ Coverage 94.81% 94.89% +0.08%
==========================================
Files 19 19
Lines 10764 10782 +18
Branches 1725 1729 +4
==========================================
+ Hits 10206 10232 +26
+ Misses 545 537 -8
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Converted to draft, because I think there may be a separate bug happening with subtraction of months. If there is, I'll fix it too before un-drafting this. |
d1ac8ce
to
37b8f36
Compare
Fixed the subtraction bug too and added tests for it. Removing draft status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked closely at why this works but I think we should probably test gregory
at least as well as we do iso8601
, so it might be worth applying this patch https://gist.github.com/ptomato/adcedda30013fc750c7f4f57bd1427d1 to run the (hopefully exhaustive) datemath
tests again with the gregory
calendar. (The complication is that doing this reveals that there's a bug somewhere in non-ISO dateUntil
as well, even without this PR)
Great idea! I'd prefer to do it in a separate PR though. I could fix |
I've done this in #1768. |
Adding and subtracting months was broken for non-ISO months when the starting point was near the end of the calendar month. This commit fixes this issue and adds tests for this case.
37b8f36
to
5633434
Compare
Fixes tc39#1768 which was caused by assuming that `two` was always later than `one` when `largestUnit` was `'years'` or `'months'`. Also included `calendar: 'gregory'` in datemath demitasse tests.
While fixing another bug, I noticed that `weeks` was being returned by non-ISO dateUntil when largestUnit is `months` or `years`. There were existing demitasse test cases that should have covered this codepath, but they weren't adding enough days to trigger the bug. Now they do.
Adapting these tests and fixing that bug turned out to be really easy. So I just included the changes here. Also fixed another bug I found in the neighborhood. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Addresses three bugs with non-ISO date math. Fixes #1760. Fixes #1768.
This PR includes the following changes to the non-production polyfill:
add
/subtract
when the starting day of the month was longer than the shortest month between the start and endpoint, e.g. adding a month to Jan 31 or subtracting a month from Mar 31 in the Gregorian calendar.until
/since
wherelargestUnit
was'months'
or'years'
and the second argument was more than one month later than the first argumentuntil
/since
wherelargestUnit
was'months'
or'years'
whereweeks
were being incorrectly returned.Because non-ISO calendar implementations are part of ECMA 402, not ECMA 262, this won't result in any spec changes nor docs changes. Only the non-prod polyfill is affected, but it's a polite to fix bug anyways so we won't have obviously broken results for some calendars.