tor-browser

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

extreme-dates.js (5448B)


      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.plaindatetime.from
      7 description: from() gives sensible output at extremes of supported range
      8 features: [Temporal, Intl.Era-monthcode]
      9 includes: [temporalHelpers.js]
     10 ---*/
     11 
     12 // Lunisolar/lunar calendars can't accurately predict celestial orbits for dates
     13 // far into the past/future. Skip `chinese` and `dangi`. `islamic-umalqura` is
     14 // okay because it is specified to fall back to `islamic-civil` outside the
     15 // range of accuracy.
     16 
     17 const testData = [
     18  ["buddhist", -271278, 4, "M04", 19, "be", -271278, 276303, 9, "M09", 13, "be", 276303],
     19  ["coptic", -272099, 3, "M03", 23, "am", -272099, 275471, 5, "M05", 22, "am", 275471],
     20  ["ethioaa", -266323, 3, "M03", 23, "aa", -266323, 281247, 5, "M05", 22, "aa", 281247],
     21  ["ethiopic", -271823, 3, "M03", 23, "aa", -266323, 275747, 5, "M05", 22, "am", 275747],
     22  ["gregory", -271821, 4, "M04", 19, "bce", 271822, 275760, 9, "M09", 13, "ce", 275760],
     23  ["hebrew", -268058, 11, "M11", 4, "am", -268058, 279517, 10, "M09", 11, "am", 279517],
     24  ["indian", -271899, 1, "M01", 29, "shaka", -271899, 275682, 6, "M06", 22, "shaka", 275682],
     25  ["islamic-civil", -280804, 3, "M03", 21, "bh", 280805, 283583, 5, "M05", 23, "ah", 283583],
     26  ["islamic-tbla", -280804, 3, "M03", 22, "bh", 280805, 283583, 5, "M05", 24, "ah", 283583],
     27  ["islamic-umalqura", -280804, 3, "M03", 21, "bh", 280805, 283583, 5, "M05", 23, "ah", 283583],
     28  ["japanese", -271821, 4, "M04", 19, "bce", 271822, 275760, 9, "M09", 13, "reiwa", 273742],
     29  ["persian", -272442, 1, "M01", 9, "ap", -272442, 275139, 7, "M07", 12, "ap", 275139],
     30  ["roc", -273732, 4, "M04", 19, "broc", 273733, 273849, 9, "M09", 13, "roc", 273849],
     31 ];
     32 
     33 for (const [calendar, minYear, minMonth, minMonthCode, minDay, minEra, minEraYear, maxYear, maxMonth, maxMonthCode, maxDay, maxEra, maxEraYear] of testData) {
     34  const min = Temporal.PlainDateTime.from({
     35    calendar,
     36    year: minYear,
     37    era: minEra,
     38    eraYear: minEraYear,
     39    month: minMonth,
     40    monthCode: minMonthCode,
     41    day: minDay,
     42    nanosecond: 1,
     43  });
     44  TemporalHelpers.assertPlainDateTime(min,
     45    minYear, minMonth, minMonthCode, minDay, 0, 0, 0, 0, 0, 1,
     46    `${calendar} minimum supported date`,
     47    minEra, minEraYear);
     48 
     49  const max = Temporal.PlainDateTime.from({
     50    calendar,
     51    year: maxYear,
     52    era: maxEra,
     53    eraYear: maxEraYear,
     54    month: maxMonth,
     55    monthCode: maxMonthCode,
     56    day: maxDay,
     57    hour: 23,
     58    minute: 59,
     59    second: 59,
     60    millisecond: 999,
     61    microsecond: 999,
     62    nanosecond: 999,
     63  });
     64  TemporalHelpers.assertPlainDateTime(max,
     65    maxYear, maxMonth, maxMonthCode, maxDay, 23, 59, 59, 999, 999, 999,
     66    `${calendar} maximum supported date`,
     67    maxEra, maxEraYear);
     68 }
     69 
     70 {
     71  const calendar = "chinese";
     72  const minNonApproximated = Temporal.PlainDateTime.from({ calendar, year: 1900, month: 1, day: 1 });
     73  const maxNonApproximated = Temporal.PlainDateTime.from({ calendar, year: 2100, month: 12, day: 29, hour: 23, minute: 59, second: 59, millisecond: 999, microsecond: 999, nanosecond: 999 });
     74  TemporalHelpers.assertPlainDateTime(minNonApproximated,
     75    1900, 1, "M01", 1, 0, 0, 0, 0, 0, 0,
     76    `${calendar} minimum non-approximated date`);
     77  TemporalHelpers.assertPlainDateTime(maxNonApproximated,
     78    2100, 12, "M12", 29, 23, 59, 59, 999, 999, 999,
     79    `${calendar} maximum non-approximated date`);
     80 
     81  // Create dates far in the past and future but don't care about the conversion
     82  Temporal.PlainDateTime.from({ calendar, year: -250000, month: 1, day: 1 });
     83  Temporal.PlainDateTime.from({ calendar, year: 250000, month: 1, day: 1 });
     84 }
     85 
     86 {
     87  const calendar = "dangi";
     88  const minNonApproximated = Temporal.PlainDateTime.from({ calendar, year: 1900, month: 1, day: 1 });
     89  const maxNonApproximated = Temporal.PlainDateTime.from({ calendar, year: 2050, month: 13, day: 29, hour: 23, minute: 59, second: 59, millisecond: 999, microsecond: 999, nanosecond: 999 });
     90  TemporalHelpers.assertPlainDateTime(minNonApproximated,
     91    1900, 1, "M01", 1, 0, 0, 0, 0, 0, 0, `${calendar} minimum non-approximated date`);
     92  TemporalHelpers.assertPlainDateTime(maxNonApproximated,
     93    2050, 13, "M12", 29, 23, 59, 59, 999, 999, 999, `${calendar} maximum non-approximated date`);
     94 
     95  // Create dates far in the past and future but don't care about the conversion
     96  Temporal.PlainDateTime.from({ calendar, year: -250000, month: 1, day: 1 });
     97  Temporal.PlainDateTime.from({ calendar, year: 250000, month: 1, day: 1 });
     98 }
     99 
    100 // Additionally test the range of islamic-umalqura in which it does not fall
    101 // back to islamic-civil
    102 {
    103  const calendar = "islamic-umalqura";
    104  const minNonApproximated = Temporal.PlainDateTime.from({ calendar, year: 1300, month: 1, day: 1 });
    105  const maxNonApproximated = Temporal.PlainDateTime.from({ calendar, year: 1500, month: 12, day: 30, hour: 23, minute: 59, second: 59, millisecond: 999, microsecond: 999, nanosecond: 999 });
    106  TemporalHelpers.assertPlainDateTime(minNonApproximated,
    107    1300, 1, "M01", 1, 0, 0, 0, 0, 0, 0, `${calendar} minimum non-approximated date`,
    108    "ah", 1300);
    109  TemporalHelpers.assertPlainDateTime(maxNonApproximated,
    110    1500, 12, "M12", 30, 23, 59, 59, 999, 999, 999, `${calendar} maximum non-approximated date`,
    111    "ah", 1500);
    112 }
    113 
    114 reportCompare(0, 0);