tor-browser

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

extreme-dates.js (5035B)


      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: 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 // Note that the earliest PlainYearMonth that can be constructed in a calendar
     18 // is the earliest month whose first day occurs after ISO -271821-04-19
     19 
     20 const testData = [
     21  ["buddhist", -271278, 5, "M05", "be", -271278, 1, 276303, 9, "M09", "be", 276303, 1],
     22  ["coptic", -272099, 4, "M04", "am", -272099, 27, 275471, 5, "M05", "am", 275471, 23],
     23  ["ethioaa", -266323, 4, "M04", "aa", -266323, 27, 281247, 5, "M05", "aa", 281247, 23],
     24  ["ethiopic", -271823, 4, "M04", "aa", -266323, 27, 275747, 5, "M05", "am", 275747, 23],
     25  ["gregory", -271821, 5, "M05", "bce", 271822, 1, 275760, 9, "M09", "ce", 275760, 1],
     26  ["hebrew", -268058, 12, "M12", "am", -268058, 16, 279517, 10, "M09", "am", 279517, 3],
     27  ["indian", -271899, 2, "M02", "shaka", -271899, 21, 275682, 6, "M06", "shaka", 275682, 23],
     28  ["islamic-civil", -280804, 4, "M04", "bh", 280805, 29, 283583, 5, "M05", "ah", 283583, 22],
     29  ["islamic-tbla", -280804, 4, "M04", "bh", 280805, 28, 283583, 5, "M05", "ah", 283583, 21],
     30  ["islamic-umalqura", -280804, 4, "M04", "bh", 280805, 29, 283583, 5, "M05", "ah", 283583, 22],
     31  ["japanese", -271821, 5, "M05", "bce", 271822, 1, 275760, 9, "M09", "reiwa", 273742, 1],
     32  ["persian", -272442, 2, "M02", "ap", -272442, 12, 275139, 7, "M07", "ap", 275139, 2],
     33  ["roc", -273732, 5, "M05", "broc", 273733, 1, 273849, 9, "M09", "roc", 273849, 1],
     34 ];
     35 
     36 for (const [calendar, minYear, minMonth, minMonthCode, minEra, minEraYear, minISODay, maxYear, maxMonth, maxMonthCode, maxEra, maxEraYear, maxISODay] of testData) {
     37  const min = Temporal.PlainYearMonth.from({
     38    calendar,
     39    year: minYear,
     40    era: minEra,
     41    eraYear: minEraYear,
     42    month: minMonth,
     43    monthCode: minMonthCode,
     44  });
     45  TemporalHelpers.assertPlainYearMonth(min,
     46    minYear, minMonth, minMonthCode,
     47    `${calendar} minimum supported date`,
     48    minEra, minEraYear, minISODay);
     49 
     50  const max = Temporal.PlainYearMonth.from({
     51    calendar,
     52    year: maxYear,
     53    era: maxEra,
     54    eraYear: maxEraYear,
     55    month: maxMonth,
     56    monthCode: maxMonthCode,
     57  });
     58  TemporalHelpers.assertPlainYearMonth(max,
     59    maxYear, maxMonth, maxMonthCode,
     60    `${calendar} maximum supported date`,
     61    maxEra, maxEraYear, maxISODay);
     62 }
     63 
     64 {
     65  const calendar = "chinese";
     66  const minNonApproximated = Temporal.PlainYearMonth.from({ calendar, year: 1900, month: 1 });
     67  const maxNonApproximated = Temporal.PlainYearMonth.from({ calendar, year: 2100, month: 12 });
     68  TemporalHelpers.assertPlainYearMonth(minNonApproximated,
     69    1900, 1, "M01",
     70    `${calendar} minimum non-approximated date`,
     71    undefined, undefined, 31);
     72  TemporalHelpers.assertPlainYearMonth(maxNonApproximated,
     73    2100, 12, "M12", `${calendar} maximum non-approximated date`,
     74    undefined, undefined, 31);
     75 
     76  // Create dates far in the past and future but don't care about the conversion
     77  Temporal.PlainYearMonth.from({ calendar, year: -250000, month: 1 });
     78  Temporal.PlainYearMonth.from({ calendar, year: 250000, month: 1 });
     79 }
     80 
     81 {
     82  const calendar = "dangi";
     83  const minNonApproximated = Temporal.PlainYearMonth.from({ calendar, year: 1900, month: 1 });
     84  const maxNonApproximated = Temporal.PlainYearMonth.from({ calendar, year: 2050, month: 13 });
     85  TemporalHelpers.assertPlainYearMonth(minNonApproximated,
     86    1900, 1, "M01", `${calendar} minimum non-approximated date`,
     87    undefined, undefined, 31);
     88  TemporalHelpers.assertPlainYearMonth(maxNonApproximated,
     89    2050, 13, "M12", `${calendar} maximum non-approximated date`,
     90    undefined, undefined, 13);
     91 
     92  // Create dates far in the past and future but don't care about the conversion
     93  Temporal.PlainYearMonth.from({ calendar, year: -250000, month: 1 });
     94  Temporal.PlainYearMonth.from({ calendar, year: 250000, month: 1 });
     95 }
     96 
     97 // Additionally test the range of islamic-umalqura in which it does not fall
     98 // back to islamic-civil
     99 {
    100  const calendar = "islamic-umalqura";
    101  const minNonApproximated = Temporal.PlainYearMonth.from({ calendar, year: 1300, month: 1 });
    102  const maxNonApproximated = Temporal.PlainYearMonth.from({ calendar, year: 1500, month: 12 });
    103  TemporalHelpers.assertPlainYearMonth(minNonApproximated,
    104    1300, 1, "M01", `${calendar} minimum non-approximated date`,
    105    "ah", 1300, 12);
    106  TemporalHelpers.assertPlainYearMonth(maxNonApproximated,
    107    1500, 12, "M12", `${calendar} maximum non-approximated date`,
    108    "ah", 1500, 18);
    109 }
    110 
    111 reportCompare(0, 0);