tor-browser

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

dangi-leap-month-codes-common.js (2720B)


      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 common leap month codes in Dangi calendar
      8 features: [Temporal, Intl.Era-monthcode]
      9 ---*/
     10 
     11 // Test common leap months in the Dangi calendar
     12 // Dangi is a lunisolar calendar where leap months follow the same distribution as Chinese
     13 // Common leap months (occurring more frequently in the astronomical cycle):
     14 // M02L, M03L, M04L, M05L, M06L, M07L, M08L
     15 //
     16 // Like the Chinese calendar, the Dangi calendar inserts leap months to keep the
     17 // lunar year synchronized with the solar year. The distribution of leap months
     18 // follows astronomical calculations.
     19 //
     20 // Note: M01L, M02L and M08L through M12L are temporarily omitted from this
     21 // test because while any leap month can have 30 days, there isn't a year in the
     22 // supported range where these months do, and it's not yet well-defined what
     23 // reference ISO year should be used.
     24 // See https://github.com/tc39/proposal-intl-era-monthcode/issues/60
     25 
     26 const calendar = "dangi";
     27 
     28 // Test leap months M03L-M07L with day 30
     29 // These are well-established leap months that can have 30 days
     30 const leapMonthsWith30Days = ["M03L", "M04L", "M05L", "M06L", "M07L"];
     31 
     32 for (const monthCode of leapMonthsWith30Days) {
     33  // Test creation with monthCode
     34  const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 });
     35  assert.sameValue(pmd.monthCode, monthCode, `leap monthCode ${monthCode} should be preserved`);
     36  assert.sameValue(pmd.day, 1, `day should be 1 for ${monthCode}`);
     37 
     38  // These leap months can have up to 30 days (minimum for PlainMonthDay)
     39  const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 });
     40  assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`);
     41  assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`);
     42 
     43  // Test constrain overflow - day 31 should be constrained to 30
     44  const constrained = Temporal.PlainMonthDay.from(
     45    { calendar, monthCode, day: 31 },
     46    { overflow: "constrain" }
     47  );
     48  assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`);
     49  assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`);
     50 
     51  // Test reject overflow - day 31 should throw
     52  assert.throws(RangeError, () => {
     53    Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" });
     54  }, `${monthCode} with day 31 should throw with reject overflow`);
     55 }
     56 
     57 reportCompare(0, 0);