tor-browser

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

extreme-dates.js (5503B)


      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: 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", 20, "be", -271278, 276303, 9, "M09", 13, "be", 276303],
     19  ["coptic", -272099, 3, "M03", 24, "am", -272099, 275471, 5, "M05", 22, "am", 275471],
     20  ["ethioaa", -266323, 3, "M03", 24, "aa", -266323, 281247, 5, "M05", 22, "aa", 281247],
     21  ["ethiopic", -271823, 3, "M03", 24, "aa", -266323, 275747, 5, "M05", 22, "am", 275747],
     22  ["gregory", -271821, 4, "M04", 20, "bce", 271822, 275760, 9, "M09", 13, "ce", 275760],
     23  ["hebrew", -268058, 11, "M11", 5, "am", -268058, 279517, 10, "M09", 11, "am", 279517],
     24  ["indian", -271899, 1, "M01", 30, "shaka", -271899, 275682, 6, "M06", 22, "shaka", 275682],
     25  ["islamic-civil", -280804, 3, "M03", 22, "bh", 280805, 283583, 5, "M05", 23, "ah", 283583],
     26  ["islamic-tbla", -280804, 3, "M03", 23, "bh", 280805, 283583, 5, "M05", 24, "ah", 283583],
     27  ["islamic-umalqura", -280804, 3, "M03", 22, "bh", 280805, 283583, 5, "M05", 23, "ah", 283583],
     28  ["japanese", -271821, 4, "M04", 20, "bce", 271822, 275760, 9, "M09", 13, "reiwa", 273742],
     29  ["persian", -272442, 1, "M01", 10, "ap", -272442, 275139, 7, "M07", 12, "ap", 275139],
     30  ["roc", -273732, 4, "M04", 20, "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.ZonedDateTime.from({
     35    calendar,
     36    year: minYear,
     37    era: minEra,
     38    eraYear: minEraYear,
     39    month: minMonth,
     40    monthCode: minMonthCode,
     41    day: minDay,
     42    timeZone: "UTC",
     43  });
     44  assert.sameValue(min.epochNanoseconds, -86400_0000_0000_000_000_000n, `${calendar} minimum supported date`)
     45 
     46  const max = Temporal.ZonedDateTime.from({
     47    calendar,
     48    year: maxYear,
     49    era: maxEra,
     50    eraYear: maxEraYear,
     51    month: maxMonth,
     52    monthCode: maxMonthCode,
     53    day: maxDay,
     54    timeZone: "UTC",
     55  });
     56  assert.sameValue(max.epochNanoseconds, 86400_0000_0000_000_000_000n, `${calendar} maximum supported date`)
     57 }
     58 
     59 {
     60  const calendar = "chinese";
     61  const minNonApproximated = Temporal.ZonedDateTime.from({ calendar, year: 1900, month: 1, day: 1, timeZone: "UTC" });
     62  const maxNonApproximated = Temporal.ZonedDateTime.from({ calendar, year: 2100, month: 12, day: 29, hour: 23, minute: 59, second: 59, millisecond: 999, microsecond: 999, nanosecond: 999, timeZone: "UTC" });
     63  TemporalHelpers.assertPlainDateTime(minNonApproximated.toPlainDateTime(),
     64    1900, 1, "M01", 1, 0, 0, 0, 0, 0, 0,
     65    `${calendar} minimum non-approximated date`);
     66  TemporalHelpers.assertPlainDateTime(maxNonApproximated.toPlainDateTime(),
     67    2100, 12, "M12", 29, 23, 59, 59, 999, 999, 999,
     68    `${calendar} maximum non-approximated date`);
     69 
     70  // Create dates far in the past and future but don't care about the conversion
     71  Temporal.ZonedDateTime.from({ calendar, year: -250000, month: 1, day: 1, timeZone: "UTC" });
     72  Temporal.ZonedDateTime.from({ calendar, year: 250000, month: 1, day: 1, timeZone: "UTC" });
     73 }
     74 
     75 {
     76  const calendar = "dangi";
     77  const minNonApproximated = Temporal.ZonedDateTime.from({ calendar, year: 1900, month: 1, day: 1, timeZone: "UTC" });
     78  const maxNonApproximated = Temporal.ZonedDateTime.from({ calendar, year: 2050, month: 13, day: 29, hour: 23, minute: 59, second: 59, millisecond: 999, microsecond: 999, nanosecond: 999, timeZone: "UTC" });
     79  TemporalHelpers.assertPlainDateTime(minNonApproximated.toPlainDateTime(),
     80    1900, 1, "M01", 1, 0, 0, 0, 0, 0, 0, `${calendar} minimum non-approximated date`);
     81  TemporalHelpers.assertPlainDateTime(maxNonApproximated.toPlainDateTime(),
     82    2050, 13, "M12", 29, 23, 59, 59, 999, 999, 999, `${calendar} maximum non-approximated date`);
     83 
     84  // Create dates far in the past and future but don't care about the conversion
     85  Temporal.ZonedDateTime.from({ calendar, year: -250000, month: 1, day: 1, timeZone: "UTC" });
     86  Temporal.ZonedDateTime.from({ calendar, year: 250000, month: 1, day: 1, timeZone: "UTC" });
     87 }
     88 
     89 // Additionally test the range of islamic-umalqura in which it does not fall
     90 // back to islamic-civil
     91 {
     92  const calendar = "islamic-umalqura";
     93  const minNonApproximated = Temporal.ZonedDateTime.from({ calendar, year: 1300, month: 1, day: 1, timeZone: "UTC" });
     94  const maxNonApproximated = Temporal.ZonedDateTime.from({ calendar, year: 1500, month: 12, day: 30, hour: 23, minute: 59, second: 59, millisecond: 999, microsecond: 999, nanosecond: 999, timeZone: "UTC" });
     95  TemporalHelpers.assertPlainDateTime(minNonApproximated.toPlainDateTime(),
     96    1300, 1, "M01", 1, 0, 0, 0, 0, 0, 0, `${calendar} minimum non-approximated date`,
     97    "ah", 1300);
     98  TemporalHelpers.assertPlainDateTime(maxNonApproximated.toPlainDateTime(),
     99    1500, 12, "M12", 30, 23, 59, 59, 999, 999, 999, `${calendar} maximum non-approximated date`,
    100    "ah", 1500);
    101 }
    102 
    103 reportCompare(0, 0);