|
| 1 | +// Copyright (C) 2026 Igalia, S.L. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-temporal.plaindate.from |
| 6 | +description: from() throws for month before earlier supported month, and month after latest supported month |
| 7 | +features: [Temporal, Intl.Era-monthcode] |
| 8 | +---*/ |
| 9 | + |
| 10 | +// Lunisolar/lunar calendars can't accurately predict celestial orbits for dates |
| 11 | +// far into the past/future. Skip `chinese` and `dangi`. `islamic-umalqura` is |
| 12 | +// okay because it is specified to fall back to `islamic-civil` outside the |
| 13 | +// range of accuracy. |
| 14 | + |
| 15 | +// Note that the earliest PlainYearMonth that can be constructed in a calendar |
| 16 | +// is the earliest month whose first day occurs after ISO -271821-04-19 |
| 17 | + |
| 18 | +const testData = [ |
| 19 | + ["buddhist", -271278, 3, "M03", "be", -271278, 276303, 10, "M10", "be", 276303], |
| 20 | + ["coptic", -272099, 3, "M03", "am", -272099, 275471, 6, "M06", "am", 275471], |
| 21 | + ["ethioaa", -266323, 3, "M03", "aa", -266323, 281247, 6, "M06", "aa", 281247], |
| 22 | + ["ethiopic", -271823, 3, "M03", "aa", -266323, 275747, 6, "M06", "am", 275747], |
| 23 | + ["gregory", -271821, 3, "M03", "bce", 271822, 275760, 10, "M10", "ce", 275760], |
| 24 | + ["hebrew", -268058, 11, "M11", "am", -268058, 279517, 11, "M11", "am", 279517], |
| 25 | + ["indian", -271899, 1, "M01", "shaka", -271899, 275682, 7, "M07", "shaka", 275682], |
| 26 | + ["islamic-civil", -280804, 3, "M03", "bh", 280805, 283583, 6, "M06", "ah", 283583], |
| 27 | + ["islamic-tbla", -280804, 3, "M03", "bh", 280805, 283583, 6, "M06", "ah", 283583], |
| 28 | + ["islamic-umalqura", -280804, 3, "M03", "bh", 280805, 283583, 6, "M06", "ah", 283583], |
| 29 | + ["japanese", -271821, 3, "M03", "bce", 271822, 275760, 10, "M10", "reiwa", 273742], |
| 30 | + ["persian", -272442, 1, "M01", "ap", -272442, 275139, 8, "M08", "ap", 275139], |
| 31 | + ["roc", -273732, 3, "M03", "broc", 273733, 273849, 10, "M10", "roc", 273849], |
| 32 | +]; |
| 33 | + |
| 34 | +for (const [calendar, minYear, minMonth, minMonthCode, minEra, minEraYear, maxYear, maxMonth, maxMonthCode, maxEra, maxEraYear] of testData) { |
| 35 | + assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ |
| 36 | + calendar, |
| 37 | + year: minYear, |
| 38 | + era: minEra, |
| 39 | + eraYear: minEraYear, |
| 40 | + month: minMonth, |
| 41 | + monthCode: minMonthCode, |
| 42 | + }), `calendar ${calendar}: month before min month should throw`); |
| 43 | + |
| 44 | + assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ |
| 45 | + calendar, |
| 46 | + year: maxYear, |
| 47 | + era: maxEra, |
| 48 | + eraYear: maxEraYear, |
| 49 | + month: maxMonth, |
| 50 | + monthCode: maxMonthCode, |
| 51 | + }), `calendar ${calendar}: month after max month should throw`); |
| 52 | +} |
0 commit comments