tor-browser

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

islamic-umalqura-month-codes.js (1955B)


      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 Islamic-umalqura calendar
      8 features: [Temporal, Intl.Era-monthcode]
      9 ---*/
     10 
     11 // Test that all month codes M01-M12 are valid for the Islamic-umalqura calendar
     12 // Unlike the tabular islamic-civil and islamic-tbla calendars, islamic-umalqura
     13 // is an observational calendar where any month can have either 29 or 30 days
     14 // depending on the year. Therefore, all months support up to 30 days for PlainMonthDay.
     15 
     16 const calendar = "islamic-umalqura";
     17 
     18 const allMonths = ["M01", "M02", "M03", "M04", "M05", "M06", "M07", "M08", "M09", "M10", "M11", "M12"];
     19 
     20 for (const monthCode of allMonths) {
     21  const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 });
     22  assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`);
     23  assert.sameValue(pmd.day, 1, `day should be 1 for ${monthCode}`);
     24 
     25  const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 });
     26  assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`);
     27  assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`);
     28 
     29  const constrained = Temporal.PlainMonthDay.from(
     30    { calendar, monthCode, day: 31 },
     31    { overflow: "constrain" }
     32  );
     33  assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`);
     34  assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`);
     35 
     36  assert.throws(RangeError, () => {
     37    Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" });
     38  }, `${monthCode} with day 31 should throw with reject overflow`);
     39 }
     40 
     41 reportCompare(0, 0);