extreme-dates.js (4785B)
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 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.PlainDate.from({ 35 calendar, 36 year: minYear, 37 era: minEra, 38 eraYear: minEraYear, 39 month: minMonth, 40 monthCode: minMonthCode, 41 day: minDay, 42 }); 43 TemporalHelpers.assertPlainDate(min, 44 minYear, minMonth, minMonthCode, minDay, 45 `${calendar} minimum supported date`, 46 minEra, minEraYear); 47 48 const max = Temporal.PlainDate.from({ 49 calendar, 50 year: maxYear, 51 era: maxEra, 52 eraYear: maxEraYear, 53 month: maxMonth, 54 monthCode: maxMonthCode, 55 day: maxDay, 56 }); 57 TemporalHelpers.assertPlainDate(max, 58 maxYear, maxMonth, maxMonthCode, maxDay, 59 `${calendar} maximum supported date`, 60 maxEra, maxEraYear); 61 } 62 63 { 64 const calendar = "chinese"; 65 const minNonApproximated = Temporal.PlainDate.from({ calendar, year: 1900, month: 1, day: 1 }); 66 const maxNonApproximated = Temporal.PlainDate.from({ calendar, year: 2100, month: 12, day: 29 }); 67 TemporalHelpers.assertPlainDate(minNonApproximated, 68 1900, 1, "M01", 1, `${calendar} minimum non-approximated date`); 69 TemporalHelpers.assertPlainDate(maxNonApproximated, 70 2100, 12, "M12", 29, `${calendar} maximum non-approximated date`); 71 72 // Create dates far in the past and future but don't care about the conversion 73 Temporal.PlainDate.from({ calendar, year: -250000, month: 1, day: 1 }); 74 Temporal.PlainDate.from({ calendar, year: 250000, month: 1, day: 1 }); 75 } 76 77 { 78 const calendar = "dangi"; 79 const minNonApproximated = Temporal.PlainDate.from({ calendar, year: 1900, month: 1, day: 1 }); 80 const maxNonApproximated = Temporal.PlainDate.from({ calendar, year: 2050, month: 13, day: 29 }); 81 TemporalHelpers.assertPlainDate(minNonApproximated, 82 1900, 1, "M01", 1, `${calendar} minimum non-approximated date`); 83 TemporalHelpers.assertPlainDate(maxNonApproximated, 84 2050, 13, "M12", 29, `${calendar} maximum non-approximated date`); 85 86 // Create dates far in the past and future but don't care about the conversion 87 Temporal.PlainDate.from({ calendar, year: -250000, month: 1, day: 1 }); 88 Temporal.PlainDate.from({ calendar, year: 250000, month: 1, day: 1 }); 89 } 90 91 // Additionally test the range of islamic-umalqura in which it does not fall 92 // back to islamic-civil 93 { 94 const calendar = "islamic-umalqura"; 95 const minNonApproximated = Temporal.PlainDate.from({ calendar, year: 1300, month: 1, day: 1 }); 96 const maxNonApproximated = Temporal.PlainDate.from({ calendar, year: 1500, month: 12, day: 30 }); 97 TemporalHelpers.assertPlainDate(minNonApproximated, 98 1300, 1, "M01", 1, `${calendar} minimum non-approximated date`, 99 "ah", 1300); 100 TemporalHelpers.assertPlainDate(maxNonApproximated, 101 1500, 12, "M12", 30, `${calendar} maximum non-approximated date`, 102 "ah", 1500); 103 } 104 105 reportCompare(0, 0);