| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2023 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.calendar.prototype.yearmonthfromfields |
| 7 |
description: Reference ISO day is chosen to be the first of the calendar month |
| 8 |
info: | |
| 9 |
6.d. Perform ! CreateDataPropertyOrThrow(_fields_, *"day"*, *1*<sub>𝔽</sub>). |
| 10 |
e. Let _result_ be ? CalendarDateToISO(_calendar_.[[Identifier]], _fields_, _options_). |
| 11 |
includes: [temporalHelpers.js] |
| 12 |
features: [Temporal] |
| 13 |
---*/ |
| 14 |
|
| 15 |
const result4 = Temporal.PlainYearMonth.from({ year: 5782, monthCode: "M04", day: 20, calendar: "hebrew" }); |
| 16 |
TemporalHelpers.assertPlainYearMonth( |
| 17 |
result4, |
| 18 |
5782, 4, "M04", |
| 19 |
"reference day is the first of the calendar month even if day is given", |
| 20 |
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 5 |
| 21 |
); |
| 22 |
const isoYearMonth = result4.toString().slice(0, 7); |
| 23 |
assert.sameValue(isoYearMonth, "2021-12", "Tevet 5782 begins in ISO 2021-12"); |
| 24 |
|
| 25 |
const result5 = Temporal.PlainYearMonth.from({ year: 5783, monthCode: "M05L", calendar: "hebrew" }, { overflow: "constrain" }); |
| 26 |
TemporalHelpers.assertPlainYearMonth( |
| 27 |
result5, |
| 28 |
5783, 6, "M06", |
| 29 |
"month code M05L does not exist in year 5783 (overflow constrain); Hebrew calendar constrains Adar I to Adar", |
| 30 |
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 22 |
| 31 |
); |
| 32 |
|
| 33 |
assert.throws( |
| 34 |
RangeError, |
| 35 |
() => Temporal.PlainYearMonth.from({ year: 5783, monthCode: "M05L", calendar: "hebrew" }, { overflow: "reject" }), |
| 36 |
"month code M05L does not exist in year 5783 (overflow reject)", |
| 37 |
); |
| 38 |
|
| 39 |
const result6 = Temporal.PlainYearMonth.from({ year: 5783, month: 13, calendar: "hebrew" }, { overflow: "constrain" }); |
| 40 |
TemporalHelpers.assertPlainYearMonth( |
| 41 |
result6, |
| 42 |
5783, 12, "M12", |
| 43 |
"month 13 does not exist in year 5783 (overflow constrain)", |
| 44 |
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 18 |
| 45 |
); |
| 46 |
|
| 47 |
assert.throws( |
| 48 |
RangeError, |
| 49 |
() => Temporal.PlainYearMonth.from({ year: 5783, month: 13, calendar: "hebrew" }, { overflow: "reject" }), |
| 50 |
"month 13 does not exist in year 5783 (overflow reject)", |
| 51 |
); |
| 52 |
|
| 53 |
const result7 = Temporal.PlainYearMonth.from({ year: 5782, monthCode: "M04", day: 50, calendar: "hebrew" }, { overflow: "constrain" }); |
| 54 |
TemporalHelpers.assertPlainYearMonth( |
| 55 |
result7, |
| 56 |
5782, 4, "M04", |
| 57 |
"reference day is set correctly even if day is out of range (overflow constrain)", |
| 58 |
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 5 |
| 59 |
); |
| 60 |
|
| 61 |
const result8 = Temporal.PlainYearMonth.from({ year: 5782, monthCode: "M04", day: 50, calendar: "hebrew" }, { overflow: "reject" }); |
| 62 |
TemporalHelpers.assertPlainYearMonth( |
| 63 |
result8, |
| 64 |
5782, 4, "M04", |
| 65 |
"reference day is set correctly even if day is out of range (overflow reject)", |
| 66 |
/* era = */ undefined, /* era year = */ undefined, /* reference day = */ 5 |
| 67 |
); |
| 68 |
|
| 69 |
reportCompare(0, 0); |