tor-browser

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

roundtrip-from-string.js (3653B)


      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.plaindate.from
      7 description: >
      8  Check that various dates created from a RFC 9557 string have the expected
      9  properties
     10 includes: [temporalHelpers.js]
     11 features: [Temporal, Intl.Era-monthcode]
     12 ---*/
     13 
     14 const year2000Cases = [
     15  ["buddhist", 2543, 1, "M01", 1, "be", 2543],
     16  ["chinese", 1999, 11, "M11", 25, undefined, undefined],
     17  ["coptic", 1716, 4, "M04", 22, "am", 1716],
     18  ["dangi", 1999, 11, "M11", 25, undefined, undefined],
     19  ["ethioaa", 7492, 4, "M04", 22, "aa", 7492],
     20  ["ethiopic", 1992, 4, "M04", 22, "am", 1992],
     21  ["gregory", 2000, 1, "M01", 1, "ce", 2000],
     22  ["hebrew", 5760, 4, "M04", 23, "am", 5760],
     23  ["indian", 1921, 10, "M10", 11, "shaka", 1921],
     24  ["islamic-civil", 1420, 9, "M09", 24, "ah", 1420],
     25  ["islamic-tbla", 1420, 9, "M09", 25, "ah", 1420],
     26  ["islamic-umalqura", 1420, 9, "M09", 24, "ah", 1420],
     27  ["japanese", 2000, 1, "M01", 1, "heisei", 12],
     28  ["persian", 1378, 10, "M10", 11, "ap", 1378],
     29  ["roc", 89, 1, "M01", 1, "roc", 89],
     30 ];
     31 
     32 for (const [calendar, year, month, monthCode, day, era, eraYear, descr] of year2000Cases) {
     33  const string = `2000-01-01[u-ca=${calendar}]`;
     34  const dateFromString = Temporal.PlainDate.from(string);
     35  TemporalHelpers.assertPlainDate(
     36    dateFromString,
     37    year, month, monthCode, day,
     38    `${descr} - created from string ${string}`,
     39    era, eraYear);
     40 }
     41 
     42 const year1Cases = [
     43  ["buddhist", 544, 1, "M01", 1, "be", 544],
     44  // ["chinese", 0, 12, "M11", 21, undefined, undefined], // (out of specified range)
     45  ["coptic", -283, 5, "M05", 8, "am", -283],
     46  // ["dangi", 0, 12, "M11", 21, undefined, undefined], // (out of specified range)
     47  ["ethioaa", 5493, 5, "M05", 8, "aa", 5493],
     48  ["ethiopic", -7, 5, "M05", 8, "aa", 5493],
     49  ["gregory", 1, 1, "M01", 1, "ce", 1],
     50  ["hebrew", 3761, 4, "M04", 18, "am", 3761],
     51  ["indian", -78, 10, "M10", 11, "shaka", -78],
     52  ["islamic-civil", -640, 5, "M05", 18, "bh", 641],
     53  ["islamic-tbla", -640, 5, "M05", 19, "bh", 641],
     54  ["islamic-umalqura", -640, 5, "M05", 18, "bh", 641],
     55  ["japanese", 1, 1, "M01", 1, "ce", 1],
     56  ["persian", -621, 10, "M10", 11, "ap", -621],
     57  ["roc", -1910, 1, "M01", 1, "broc", 1911],
     58 ];
     59 
     60 for (const [calendar, year, month, monthCode, day, era, eraYear, descr] of year1Cases) {
     61  const string = `0001-01-01[u-ca=${calendar}]`;
     62  const dateFromString = Temporal.PlainDate.from(string);
     63  TemporalHelpers.assertPlainDate(
     64    dateFromString,
     65    year, month, monthCode, day,
     66    `${descr} - created from string ${string}`,
     67    era, eraYear);
     68 }
     69 
     70 // Additional cases that were moved in from staging tests, or that we add to
     71 // catch regressions
     72 const additionalCases = [
     73  ["2004-03-21[u-ca=indian]", 1926, 1, "M01", 1, "shaka", 1926, "first day of leap year"],
     74  ["2005-03-22[u-ca=indian]", 1927, 1, "M01", 1, "shaka", 1927, "first day of common year"],
     75  ["2006-07-25[u-ca=islamic-umalqura]", 1427, 6, "M06", 29, "ah", 1427, "ICU4C/ICU4X discrepancy"],
     76  ["2025-04-19[u-ca=persian]", 1404, 1, "M01", 30, "ap", 1404, "ICU4C/ICU4X discrepancy"],
     77  ["2046-10-30[u-ca=hebrew]", 5807, 1, "M01", 30, "am", 5807, "ICU4C/ICU4X discrepancy"],
     78 ];
     79 
     80 for (const [string, year, month, monthCode, day, era, eraYear, descr] of additionalCases) {
     81  const dateFromString = Temporal.PlainDate.from(string);
     82  TemporalHelpers.assertPlainDate(
     83    dateFromString,
     84    year, month, monthCode, day,
     85    `${descr} - created from string ${string}`,
     86    era, eraYear);
     87 }
     88 
     89 reportCompare(0, 0);