tor-browser

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

coptic-month-codes.js (2932B)


      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-M13) in Coptic calendar
      8 features: [Temporal, Intl.Era-monthcode]
      9 ---*/
     10 
     11 // Test that all month codes M01-M13 are valid for the Coptic calendar
     12 // The Coptic calendar has 12 months of 30 days each, plus a 13th month (Epagomenal days)
     13 // of 5 or 6 days
     14 
     15 const calendar = "coptic";
     16 
     17 // M01-M12: Regular months with 30 days each
     18 const regularMonthCodes = [
     19  "M01", "M02", "M03", "M04", "M05", "M06",
     20  "M07", "M08", "M09", "M10", "M11", "M12"
     21 ];
     22 
     23 for (const monthCode of regularMonthCodes) {
     24  // Test creation with monthCode
     25  const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 });
     26  assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`);
     27  assert.sameValue(pmd.day, 1, "day should be 1");
     28 
     29  // Test with day 30 (all regular months have 30 days)
     30  const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 });
     31  assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`);
     32  assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`);
     33 
     34  // Test overflow: constrain to 30
     35  const constrained = Temporal.PlainMonthDay.from(
     36    { calendar, monthCode, day: 31 },
     37    { overflow: "constrain" }
     38  );
     39  assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`);
     40  assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`);
     41 
     42  // Test overflow: reject should throw for day 31
     43  assert.throws(RangeError, () => {
     44    Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" });
     45  }, `${monthCode} with day 31 should throw with reject overflow`);
     46 }
     47 
     48 // M13: Short month (Epagomenal days) with 5 or 6 days
     49 
     50 // Test M13 with day 6 (maximum, valid in leap years)
     51 const pmdM13Day6 = Temporal.PlainMonthDay.from({ calendar, monthCode: "M13", day: 6 });
     52 assert.sameValue(pmdM13Day6.monthCode, "M13", "M13 should be valid with day 6");
     53 assert.sameValue(pmdM13Day6.day, 6, "day should be 6 for M13");
     54 
     55 // Test M13 overflow: constrain to maximum
     56 const constrained = Temporal.PlainMonthDay.from(
     57  { calendar, monthCode: "M13", day: 7 },
     58  { overflow: "constrain" }
     59 );
     60 assert.sameValue(constrained.monthCode, "M13", "M13 should be preserved with constrain");
     61 assert.sameValue(constrained.day, 6, "day 7 should be constrained to 6 for M13");
     62 
     63 // Test M13 overflow: reject should throw for day 7
     64 assert.throws(RangeError, () => {
     65  Temporal.PlainMonthDay.from({ calendar, monthCode: "M13", day: 7 }, { overflow: "reject" });
     66 }, "M13 with day 7 should throw with reject overflow");
     67 
     68 reportCompare(0, 0);