tor-browser

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

reference-day-chinese.js (2863B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2023 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.calendar.prototype.yearmonthfromfields
      7 description: Reference ISO day is chosen to be the first of the calendar month
      8 info: |
      9  6.d. Perform ! CreateDataPropertyOrThrow(_fields_, *"day"*, *1*<sub>𝔽</sub>).
     10    e. Let _result_ be ? CalendarDateToISO(_calendar_.[[Identifier]], _fields_, _options_).
     11 includes: [temporalHelpers.js]
     12 features: [Temporal]
     13 ---*/
     14 
     15 // Month codes, month indices, and the ISO reference days of the months in 2022
     16 const months2022TestData = [
     17  ["M01", 1, 1],
     18  ["M02", 2, 3],
     19  ["M03", 3, 1],
     20  ["M04", 4, 1],
     21  ["M05", 5, 30],
     22  ["M06", 6, 29],
     23  ["M07", 7, 29],
     24  ["M08", 8, 27],
     25  ["M09", 9, 26],
     26  ["M10", 10, 25],
     27  ["M11", 11, 24],
     28  ["M12", 12, 23],
     29 ];
     30 for (let [nonLeapMonthCode, month, referenceISODay] of months2022TestData) {
     31  const leapMonthCode = nonLeapMonthCode + "L";
     32  const fields = { year: 2022, monthCode: leapMonthCode, calendar: "chinese" };
     33 
     34  const result = Temporal.PlainYearMonth.from(fields, { overflow: "constrain" });
     35  TemporalHelpers.assertPlainYearMonth(
     36    result,
     37    2022, month, nonLeapMonthCode,
     38    `Chinese intercalary month ${leapMonthCode} is constrained to ${nonLeapMonthCode} in year 2022 (overflow constrain)`,
     39    /* era = */ undefined, /* era year = */ undefined, referenceISODay
     40  );
     41 
     42  assert.throws(
     43    RangeError,
     44    () => Temporal.PlainYearMonth.from(fields, { overflow: "reject" }),
     45    `Chinese intercalary month ${leapMonthCode} does not exist in year 2022 (overflow reject)`
     46  );
     47 }
     48 
     49 // Years in which leap months exist in our supported range according to
     50 // ICU4C/ICU4X. Note use of near-future year for "M11L" rather than use of a
     51 // year several hundred years before the start of our range.
     52 const leapMonthsTestData = [
     53  ["M02L", 2023, 3, 22],
     54  ["M03L", 1993, 4, 22],
     55  ["M04L", 2020, 5, 23],
     56  ["M05L", 2009, 6, 23],
     57  ["M06L", 2017, 7, 23],
     58  ["M07L", 2006, 8, 24],
     59  ["M08L", 1995, 9, 25],
     60  ["M09L", 2014, 10, 24],
     61  ["M10L", 1984, 11, 23],
     62  ["M11L", 2033, 12, 22],
     63 ];
     64 for (const [monthCode, year, month, referenceISODay, isoYear = year, isoMonth = month] of leapMonthsTestData) {
     65  const result = Temporal.PlainYearMonth.from({ year, monthCode, calendar: "chinese" });
     66  TemporalHelpers.assertPlainYearMonth(
     67    result,
     68    year, month, monthCode,
     69    `Date of sample Chinese intercalary month ${monthCode}`,
     70    /* era = */ undefined, /* era year = */ undefined, referenceISODay
     71  );
     72  const isoYearMonth = result.toString().slice(0, 7);
     73  assert.sameValue(isoYearMonth, `${isoYear}-${String(isoMonth).padStart(2, '0')}`, `${year}-${monthCode} starts in ISO month ${isoYear}-${isoMonth}`);
     74 }
     75 
     76 reportCompare(0, 0);