tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

buddhist-month-codes.js (2095B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2025 Igalia, S.L. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-temporal.plainmonthday.from
      7 description: PlainMonthDay can be created for all month codes (M01-M12) in Buddhist calendar
      8 features: [Temporal, Intl.Era-monthcode]
      9 includes: [temporalHelpers.js]
     10 ---*/
     11 
     12 // Test that all month codes M01-M12 are valid for the Buddhist calendar
     13 // The Buddhist calendar follows the Gregorian calendar structure
     14 
     15 const calendar = "buddhist";
     16 
     17 for (const { month, monthCode, daysInMonth } of TemporalHelpers.ISOMonths) {
     18  // Test creation with monthCode and day 1
     19  const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 });
     20  TemporalHelpers.assertPlainMonthDay(pmd, monthCode, 1, `monthCode ${monthCode} should be preserved`);
     21 
     22  // Test creation with month and day 1
     23  const pmdMonth = Temporal.PlainMonthDay.from({ calendar, year: 2515, month, day: 1 });
     24  TemporalHelpers.assertPlainMonthDay(pmdMonth, monthCode, 1, `Equivalent monthCode ${monthCode} and month ${month} are resolved to the same PlainMonthDay`);
     25 
     26  // Test with maximum day value for this month (minimum for PlainMonthDay)
     27  const pmdMax = Temporal.PlainMonthDay.from({ calendar, monthCode, day: daysInMonth });
     28  TemporalHelpers.assertPlainMonthDay(pmdMax, monthCode, daysInMonth, `${monthCode} with day ${daysInMonth} should be valid`);
     29 
     30  // Test constrain overflow
     31  const constrained = Temporal.PlainMonthDay.from(
     32    { calendar, monthCode, day: daysInMonth + 1 },
     33    { overflow: "constrain" }
     34  );
     35  TemporalHelpers.assertPlainMonthDay(constrained, monthCode, daysInMonth, `day ${daysInMonth + 1} should be constrained to ${daysInMonth} for ${monthCode}`);
     36 
     37  // Test reject overflow
     38  assert.throws(RangeError, () => {
     39    Temporal.PlainMonthDay.from({ calendar, monthCode, day: daysInMonth + 1 }, { overflow: "reject" });
     40  }, `${monthCode} with day ${daysInMonth + 1} should throw with reject overflow`);
     41 }
     42 
     43 reportCompare(0, 0);