tor-browser

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

islamic-tbla-month-codes.js (2953B)


      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-tbla calendar
      8 features: [Temporal, Intl.Era-monthcode]
      9 ---*/
     10 
     11 // Test that all month codes M01-M12 are valid for the Islamic-tbla calendar
     12 // Islamic calendar month lengths:
     13 // - 30 days: M01, M03, M05, M07, M09, M11, M12
     14 // - 29 days: M02, M04, M06, M08, M10
     15 
     16 const calendar = "islamic-tbla";
     17 
     18 // Months with 30 days
     19 const monthsWith30Days = ["M01", "M03", "M05", "M07", "M09", "M11", "M12"];
     20 
     21 for (const monthCode of monthsWith30Days) {
     22  const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 });
     23  assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`);
     24  assert.sameValue(pmd.day, 1, `day should be 1 for ${monthCode}`);
     25 
     26  const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 });
     27  assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`);
     28  assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`);
     29 
     30  const constrained = Temporal.PlainMonthDay.from(
     31    { calendar, monthCode, day: 31 },
     32    { overflow: "constrain" }
     33  );
     34  assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`);
     35  assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`);
     36 
     37  assert.throws(RangeError, () => {
     38    Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" });
     39  }, `${monthCode} with day 31 should throw with reject overflow`);
     40 }
     41 
     42 // Months with 29 days
     43 const monthsWith29Days = ["M02", "M04", "M06", "M08", "M10"];
     44 
     45 for (const monthCode of monthsWith29Days) {
     46  const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 });
     47  assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`);
     48  assert.sameValue(pmd.day, 1, `day should be 1 for ${monthCode}`);
     49 
     50  const pmd29 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 29 });
     51  assert.sameValue(pmd29.monthCode, monthCode, `${monthCode} with day 29 should be valid`);
     52  assert.sameValue(pmd29.day, 29, `day should be 29 for ${monthCode}`);
     53 
     54  const constrained = Temporal.PlainMonthDay.from(
     55    { calendar, monthCode, day: 30 },
     56    { overflow: "constrain" }
     57  );
     58  assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`);
     59  assert.sameValue(constrained.day, 29, `day 30 should be constrained to 29 for ${monthCode}`);
     60 
     61  assert.throws(RangeError, () => {
     62    Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 }, { overflow: "reject" });
     63  }, `${monthCode} with day 30 should throw with reject overflow`);
     64 }
     65 
     66 reportCompare(0, 0);