Skip to content

Conversation

@catamorphism
Copy link
Contributor

See #3197

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it's going to be a difficult-to-deal-with PR any way we slice it, but here are some suggestions that may make it at least a bit smaller and easier.

Also check the test262 and snapshot test results — are these legitimate failures in the sense that the previous behaviour did actually already have test coverage and those tests need to be updated, or are they regressions?

It occurred to me that a simpler approach to implementing this might be to introduce a CalendarYearMonthAdd similar to but simpler than CalendarDateAdd. That could go either way, it might result in a bunch of duplication.

Comment on lines -693 to 697

export function RegulateISODate(year, month, day, overflow) {
switch (overflow) {
case 'reject':
RejectISODate(year, month, day);
break;
case 'constrain':
({ year, month, day } = ConstrainISODate(year, month, day));
break;
}
return { year, month, day };
export function RegulateISODate(year, month, day, overflowMonths, overflowDays) {
RejectISODate(year, month, day, overflowMonths, overflowDays);
return ConstrainISODate(year, month, day);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this function, we don't have to make the distinction between the two types of overflow, because they don't matter in the ISO calendar. So RegulateISODate can just be left as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to take these arguments because they have to be passed to RejectISODate (see below).

Comment on lines -2787 to +2792
export function RejectISODate(year, month, day) {
RejectToRange(month, 1, 12);
RejectToRange(day, 1, ISODaysInMonth(year, month));
export function RejectISODate(year, month, day, overflowMonths, overflowDays) {
if (overflowMonths === 'reject') {
RejectToRange(month, 1, 12);
}
if (overflowDays === 'reject') {
RejectToRange(day, 1, ISODaysInMonth(year, month));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, RejectISODate can just stay as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work with the implementation of RejectISODate being as it is, because there's no way for it to distinguish between the case where it should (effectively) constrain the day despite overflow being reject, and the case where it should reject the day, without taking an overflow argument.

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 97.51553% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.74%. Comparing base (2cee76a) to head (c8f0b9b).

Files with missing lines Patch % Lines
polyfill/lib/calendar.mjs 96.72% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3198   +/-   ##
=======================================
  Coverage   96.74%   96.74%           
=======================================
  Files          22       22           
  Lines       10348    10415   +67     
  Branches     1859     1871   +12     
=======================================
+ Hits        10011    10076   +65     
- Misses        287      288    +1     
- Partials       50       51    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@catamorphism
Copy link
Contributor Author

Also check the test262 and snapshot test results — are these legitimate failures in the sense that the previous behaviour did actually already have test coverage and those tests need to be updated, or are they regressions?

There was one test262 failure, which was a regression that I fixed in 21c8063, and no snapshot test failures.

@catamorphism
Copy link
Contributor Author

It occurred to me that a simpler approach to implementing this might be to introduce a CalendarYearMonthAdd similar to but simpler than CalendarDateAdd. That could go either way, it might result in a bunch of duplication.

@ptomato I started, but I think it's going to be much more duplication, specifically for the non-ISO-calendar code. Either an extra argument needs to get passed around to permit day being undefined (error-prone), or quite a lot of code needs to be duplicated. I think having two overflow parameters is cleaner.

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.

2 participants