Skip to content

Conversation

@ptomato
Copy link
Collaborator

@ptomato ptomato commented Nov 27, 2025

Fixes a bug in the determination of PlainMonthDay reference years, exposed by new test262 tests. Updates the test262 commit to pull in these new tests.

The spec is correct, no change to the spec text needed.

In the tabular Hijri calendars, the months have a set number of days
with only one month varying between 29 and 30 days in leap years. In
the observational Hijri calendar (islamic-umalqura) any month can have
30 days.

This applies that information to make maxLengthOfMonthCodeInAnyYear() in
helperIslamic more accurate. It prevents a slow search roundtripping
through 20 years when code like this is executed:

    Temporal.PlainMonthDay.from({
      calendar: 'islamic-tbla',
      monthCode: 'M10',
      day: 30
    })

This PlainMonthDay shouldn't exist. The change makes it fail immediately
rather than exhausting the search space.

This is just a polyfill optimization. The spec text remains correct.
In hindsight, when I wrote the maxLengthOfMonthCodeInAnyYear() code in
e977eff I put it in a slightly odd place. There is no need to check
overflow in each iteration of the search loop, we can check it at the
beginning.

And in fact this code was buggy: PlainMonthDays created from
out-of-range days with overflow: 'constrain' would sometimes get wrong
reference years. For example:

   Temporal.PlainMonthDay.from({
     calendar: 'gregory',
     monthCode: 'M12',
     day: 32
   })

This would get the incorrect reference year 1971, and would actually
produce a different PlainMonthDay instance from the same call with day:
31, which would get the correct reference year 1972.

This was a polyfill-only bug. No change needed to the spec text.
We need to add some new tests to the expected failures file: they expose
a bug in ICU4C where the wrong leap month was calculated for the Chinese
calendar in 1987.
@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.74%. Comparing base (4197642) to head (5a6ca4d).

Files with missing lines Patch % Lines
polyfill/lib/calendar.mjs 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3190      +/-   ##
==========================================
+ Coverage   96.67%   96.74%   +0.06%     
==========================================
  Files          22       22              
  Lines       10357    10348       -9     
  Branches     1859     1859              
==========================================
- Hits        10013    10011       -2     
+ Misses        294      287       -7     
  Partials       50       50              

☔ 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.

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