tor-browser

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

roundtrip-from-property-bag.js (5549B)


      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.zoneddatetime.from
      7 description: >
      8  Check that various dates created from a property bag have the expected
      9  properties
     10 includes: [temporalHelpers.js]
     11 features: [Temporal, Intl.Era-monthcode]
     12 ---*/
     13 
     14 const options = { overflow: "reject" };
     15 
     16 const cases = [
     17  ["buddhist", 2543, 1, "M01", 1, "be", 2543, "ISO date 2000-01-01"],
     18  ["chinese", 1999, 11, "M11", 25, undefined, undefined, "ISO date 2000-01-01"],
     19  ["coptic", 1716, 4, "M04", 22, "am", 1716, "ISO date 2000-01-01"],
     20  ["dangi", 1999, 11, "M11", 25, undefined, undefined, "ISO date 2000-01-01"],
     21  ["ethioaa", 7492, 4, "M04", 22, "aa", 7492, "ISO date 2000-01-01"],
     22  ["ethiopic", 1992, 4, "M04", 22, "am", 1992, "ISO date 2000-01-01"],
     23  ["gregory", 2000, 1, "M01", 1, "ce", 2000, "ISO date 2000-01-01"],
     24  ["hebrew", 5760, 4, "M04", 23, "am", 5760, "ISO date 2000-01-01"],
     25  ["indian", 1921, 10, "M10", 11, "shaka", 1921, "ISO date 2000-01-01"],
     26  ["islamic-civil", 1420, 9, "M09", 24, "ah", 1420, "ISO date 2000-01-01"],
     27  ["islamic-tbla", 1420, 9, "M09", 25, "ah", 1420, "ISO date 2000-01-01"],
     28  ["islamic-umalqura", 1420, 9, "M09", 24, "ah", 1420, "ISO date 2000-01-01"],
     29  ["japanese", 2000, 1, "M01", 1, "heisei", 12, "ISO date 2000-01-01"],
     30  ["persian", 1378, 10, "M10", 11, "ap", 1378, "ISO date 2000-01-01"],
     31  ["roc", 89, 1, "M01", 1, "roc", 89, "ISO date 2000-01-01"],
     32 
     33  // ISO date 0001-01-01
     34  ["buddhist", 544, 1, "M01", 1, "be", 544, "ISO date 0001-01-01"],
     35  // ["chinese", 0, 12, "M11", 21, undefined, undefined, "ISO date 0001-01-01"], // (out of specified range)
     36  ["coptic", -283, 5, "M05", 8, "am", -283, "ISO date 0001-01-01"],
     37  // ["dangi", 0, 12, "M11", 21, undefined, undefined, "ISO date 0001-01-01"], // (out of specified range)
     38  ["ethioaa", 5493, 5, "M05", 8, "aa", 5493, "ISO date 0001-01-01"],
     39  ["ethiopic", -7, 5, "M05", 8, "aa", 5493, "ISO date 0001-01-01"],
     40  ["gregory", 1, 1, "M01", 1, "ce", 1, "ISO date 0001-01-01"],
     41  ["hebrew", 3761, 4, "M04", 18, "am", 3761, "ISO date 0001-01-01"],
     42  ["indian", -78, 10, "M10", 11, "shaka", -78, "ISO date 0001-01-01"],
     43  ["islamic-civil", -640, 5, "M05", 18, "bh", 641, "ISO date 0001-01-01"],
     44  ["islamic-tbla", -640, 5, "M05", 19, "bh", 641, "ISO date 0001-01-01"],
     45  ["islamic-umalqura", -640, 5, "M05", 18, "bh", 641, "ISO date 0001-01-01"],
     46  ["japanese", 1, 1, "M01", 1, "ce", 1, "ISO date 0001-01-01"],
     47  ["persian", -621, 10, "M10", 11, "ap", -621, "ISO date 0001-01-01"],
     48  ["roc", -1910, 1, "M01", 1, "broc", 1911, "ISO date 0001-01-01"],
     49 
     50  // Additional cases that were moved in from staging tests, or that we add to
     51  // catch regressions
     52  ["chinese", 1899, 12, "M12", 1, undefined, undefined, "start of non-approximated range"],
     53  ["chinese", 2099, 13, "M12", 21, undefined, undefined, "end of non-approximated range"],
     54  ["dangi", 1899, 12, "M12", 1, undefined, undefined, "start of non-approximated range"],
     55  ["dangi", 2049, 12, "M12", 8, undefined, undefined, "end of non-approximated range"],
     56  ["islamic-civil", 1445, 1, "M01", 1, "ah", 1445, "recent year"],
     57  ["islamic-tbla", 1445, 1, "M01", 1, "ah", 1445, "recent year"],
     58  ["islamic-umalqura", 1445, 1, "M01", 1, "ah", 1445, "recent year"],
     59  ["islamic-umalqura", -6823, 1, "M01", 1, "bh", 6824, "https://github.com/unicode-org/icu4x/issues/4914"],
     60  ["persian", 1395, 1, "M01", 1, "ap", 1395, "leap year 1395"],
     61  ["persian", 1396, 1, "M01", 1, "ap", 1396, "common year 1396"],
     62  ["persian", 1397, 1, "M01", 1, "ap", 1397, "common year 1397"],
     63  ["persian", 1398, 1, "M01", 1, "ap", 1398, "common year 1398"],
     64  ["persian", 1399, 1, "M01", 1, "ap", 1399, "leap year 1399"],
     65  ["persian", 1400, 1, "M01", 1, "ap", 1400, "common year 1400"],
     66 ];
     67 
     68 for (const [calendar, year, month, monthCode, day, era, eraYear, descr] of cases) {
     69  const dateFromYearMonth = Temporal.ZonedDateTime.from({ year, month, day, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
     70  TemporalHelpers.assertPlainDateTime(
     71    dateFromYearMonth.toPlainDateTime(),
     72    year, month, monthCode, day, 12, 34, 0, 0, 0, 0,
     73    `${descr} (${calendar}) - created from year and month`,
     74    era, eraYear);
     75 
     76  const dateFromYearMonthCode = Temporal.ZonedDateTime.from({ year, monthCode, day, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
     77  TemporalHelpers.assertPlainDateTime(
     78    dateFromYearMonthCode.toPlainDateTime(),
     79    year, month, monthCode, day, 12, 34, 0, 0, 0, 0,
     80    `${descr} (${calendar}) - created from year and month code`,
     81    era, eraYear);
     82 
     83  if (era === undefined) continue;  // skip era-less calendars
     84 
     85  const dateFromEraMonth = Temporal.ZonedDateTime.from({ era, eraYear, month, day, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
     86  TemporalHelpers.assertPlainDateTime(
     87    dateFromEraMonth.toPlainDateTime(),
     88    year, month, monthCode, day, 12, 34, 0, 0, 0, 0,
     89    `${descr} (${calendar}) - created from era, era year, and month`,
     90    era, eraYear);
     91 
     92  const dateFromEraMonthCode = Temporal.ZonedDateTime.from({ era, eraYear, monthCode, day, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
     93  TemporalHelpers.assertPlainDateTime(
     94    dateFromEraMonthCode.toPlainDateTime(),
     95    year, month, monthCode, day, 12, 34, 0, 0, 0, 0,
     96    `${descr} (${calendar}) - created from era, era year, and month code`,
     97    era, eraYear);
     98 }
     99 
    100 reportCompare(0, 0);