Source code
Revision control
Copy as Markdown
Other Tools
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plainmonthday.from
description: CalendarResolveFields throws TypeError before RangeError (hebrew calendar)
info: |
CalendarResolveFields validates field types before validating field ranges,
ensuring TypeError is thrown before RangeError when both conditions exist.
features: [Temporal, Intl.Era-monthcode]
---*/
// Missing year (required for month) should throw TypeError even with month/monthCode conflict
assert.throws(
TypeError,
() => Temporal.PlainMonthDay.from({ calendar: "hebrew", monthCode: "M04", month: 5, day: 1 }),
"Missing year throws TypeError before month/monthCode conflict throws RangeError"
);
// Missing monthCode/month should throw TypeError even with invalid day
assert.throws(
TypeError,
() => Temporal.PlainMonthDay.from({ calendar: "hebrew", year: 5784, day: 32 }, { overflow: "reject" }),
"Missing monthCode/month throws TypeError before out-of-range day throws RangeError"
);
// Missing day should throw TypeError even with month/monthCode conflict
assert.throws(
TypeError,
() => Temporal.PlainMonthDay.from({ calendar: "hebrew", year: 5784, monthCode: "M04", month: 5 }),
"Missing day throws TypeError before month/monthCode conflict throws RangeError"
);
// undefined year should throw TypeError even with month/monthCode conflict
assert.throws(
TypeError,
() => Temporal.PlainMonthDay.from({ calendar: "hebrew", year: undefined, monthCode: "M04", month: 5, day: 1 }),
"undefined year throws TypeError before month/monthCode conflict throws RangeError"
);
// After type validation passes, range validation should throw RangeError
assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from({ calendar: "hebrew", year: 5784, monthCode: "M04", month: 5, day: 1 }),
"month/monthCode conflict throws RangeError when all required fields present"
);
assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from({ calendar: "hebrew", year: 5784, monthCode: "M01", day: 32 }, { overflow: "reject" }),
"Out-of-range day throws RangeError when all required fields present"
);
// No RangeError if month is present and reference date has a different ordinal month.
var pmd = Temporal.PlainMonthDay.from({ calendar: "hebrew", year: 5784, monthCode: "M06", month: 7, day: 1 });
var pd = Temporal.PlainDate.from(pmd.toString());
assert.sameValue(pmd.monthCode, "M06", "Temporal.PlainMonthDay monthCode");
assert.sameValue(pd.monthCode, "M06", "Temporal.PlainDate monthCode");
assert.sameValue(pd.month, 6, "Temporal.PlainDate ordinal month");
reportCompare(0, 0);