tor-browser

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

dangi-month-codes.js (1930B)


      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 regular month codes in Dangi calendar
      8 features: [Temporal, Intl.Era-monthcode]
      9 ---*/
     10 
     11 // Test that all regular month codes M01-M12 are valid for the Dangi calendar
     12 // Dangi is a lunisolar calendar used in Korea, structurally identical to Chinese
     13 
     14 const calendar = "dangi";
     15 const monthCodes = [
     16  "M01", "M02", "M03", "M04", "M05", "M06",
     17  "M07", "M08", "M09", "M10", "M11", "M12"
     18 ];
     19 
     20 for (const monthCode of monthCodes) {
     21  // Test creation with monthCode
     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");
     25 
     26  // Test with a larger day value (months can have 29 or 30 days)
     27  const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 });
     28  assert.sameValue(pmd30.monthCode, monthCode, `monthCode ${monthCode} with day 30 should be valid`);
     29 
     30  // Test overflow: constrain to maximum valid day in the month
     31  const constrained = Temporal.PlainMonthDay.from(
     32    { calendar, monthCode, day: 31 },
     33    { overflow: "constrain" }
     34  );
     35  assert.sameValue(constrained.monthCode, monthCode, `monthCode ${monthCode} should be preserved with constrain`);
     36  assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`);
     37 
     38  // Test overflow: reject should throw for invalid day
     39  assert.throws(RangeError, () => {
     40    Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" });
     41  }, `monthCode ${monthCode} with day 31 should throw with reject overflow`);
     42 }
     43 
     44 reportCompare(0, 0);