Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,15 @@ var TemporalHelpers = {
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the value of yearMonth.calendarId.)
*
* Pass null as the referenceISODay if you don't want to give it explicitly.
* In that case, the expected referenceISODay will be computed using PlainDate
* and only verified for consistency, not for equality with a specific value.
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
const prefix = description ? `${description}: ` : "";
assert(typeof referenceISODay === "number" || referenceISODay === null,
`TemporalHelpers.assertPlainYearMonth() referenceISODay argument should be a number or null, not ${referenceISODay}`);
assert(yearMonth instanceof Temporal.PlainYearMonth, `${prefix}instanceof`);
assert.sameValue(
TemporalHelpers.canonicalizeCalendarEra(yearMonth.calendarId, yearMonth.era),
Expand All @@ -348,7 +354,8 @@ var TemporalHelpers = {
assert.sameValue(yearMonth.month, month, `${prefix}month result:`);
assert.sameValue(yearMonth.monthCode, monthCode, `${prefix}monthCode result:`);
const isoDay = Number(yearMonth.toString({ calendarName: "always" }).slice(1).split("-")[2].slice(0, 2));
assert.sameValue(isoDay, referenceISODay, `${prefix}referenceISODay result:`);
const expectedISODay = referenceISODay ?? yearMonth.toPlainDate({ day: 1 }).withCalendar("iso8601").day;
Comment thread
ptomato marked this conversation as resolved.
assert.sameValue(isoDay, expectedISODay, `${prefix}referenceISODay result:`);
},

/*
Expand Down
26 changes: 26 additions & 0 deletions test/intl402/Temporal/PlainYearMonth/from/basic-hebrew.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.plainyearmonth.from
description: Basic functionality of resolving fields in hebrew calendar
features: [Temporal, Intl.Era-monthcode]
includes: [temporalHelpers.js]
---*/

const calendar = "hebrew";
const options = { overflow: "reject" };

const commonYear = 5783;

for (let month = 1; month < 13; month++) {
const monthCode = `M${String(month).padStart(2, '0')}`;

const startOfMonth = Temporal.PlainYearMonth.from({ year: commonYear, month, calendar }, options);
TemporalHelpers.assertPlainYearMonth(
startOfMonth,
commonYear, month, monthCode,
`${monthCode} in common year`,
"am", commonYear, null
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.plainyearmonth.from
description: CalendarResolveFields throws TypeError before RangeError (gregory 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 (and no era/eraYear) should throw TypeError even with month/monthCode conflict
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.from({ calendar: "gregory", monthCode: "M05", month: 6 }),
"Missing year/era throws TypeError before month/monthCode conflict throws RangeError"
);

// undefined year should throw TypeError even with month/monthCode conflict
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.from({ calendar: "gregory", year: undefined, monthCode: "M05", month: 6 }),
"undefined year throws TypeError before month/monthCode conflict throws RangeError"
);

// After type validation passes, range validation should throw RangeError
assert.throws(
RangeError,
() => Temporal.PlainYearMonth.from({ calendar: "gregory", year: 2020, monthCode: "M05", month: 6 }),
"month/monthCode conflict throws RangeError when all types are valid"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.plainyearmonth.from
description: Non-positive era years are remapped in ethiopic calendar
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/

const calendar = "ethiopic";
const options = { overflow: "reject" };

const am0 = Temporal.PlainYearMonth.from({ era: "am", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
am0,
0, 1, "M01", "AM 0 resolves to AA 5500",
"aa", 5500, null);

const am1n = Temporal.PlainYearMonth.from({ era: "am", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
am1n,
-1, 1, "M01", "AM -1 resolves to AA 5499",
"aa", 5499, null);

const aa0 = Temporal.PlainYearMonth.from({ era: "aa", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
aa0,
-5500, 1, "M01", "AA 0 is not remapped",
"aa", 0, null);

const aa1n = Temporal.PlainYearMonth.from({ era: "aa", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
aa1n,
-5501, 1, "M01", "AA -1 is not remapped",
"aa", -1, null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.plainyearmonth.from
description: Non-positive era years are remapped in gregory calendar
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/

const calendar = "gregory";
const options = { overflow: "reject" };

const ce0 = Temporal.PlainYearMonth.from({ era: "ce", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ce0,
0, 1, "M01", "CE 0 resolves to BCE 1",
"bce", 1);

const ce1n = Temporal.PlainYearMonth.from({ era: "ce", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ce1n,
-1, 1, "M01", "CE -1 resolves to BCE 2",
"bce", 2);

const bce0 = Temporal.PlainYearMonth.from({ era: "bce", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bce0,
1, 1, "M01", "BCE 0 resolves to CE 1",
"ce", 1);

const bce1n = Temporal.PlainYearMonth.from({ era: "bce", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bce1n,
2, 1, "M01", "BCE -1 resolves to CE 2",
"ce", 2);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.plainyearmonth.from
description: Non-positive era years are remapped in islamic-civil calendar
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/

const calendar = "islamic-civil";
const options = { overflow: "reject" };

const ah0 = Temporal.PlainYearMonth.from({ era: "ah", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ah0,
0, 1, "M01", "AH 0 resolves to BH 1",
"bh", 1, null);

const ah1n = Temporal.PlainYearMonth.from({ era: "ah", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ah1n,
-1, 1, "M01", "AH -1 resolves to BH 2",
"bh", 2, null);

const bh0 = Temporal.PlainYearMonth.from({ era: "bh", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bh0,
1, 1, "M01", "BH 0 resolves to AH 1",
"ah", 1, null);

const bh1n = Temporal.PlainYearMonth.from({ era: "bh", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bh1n,
2, 1, "M01", "BH -1 resolves to AH 2",
"ah", 2, null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.plainyearmonth.from
description: Non-positive era years are remapped in islamic-tbla calendar
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/

const calendar = "islamic-tbla";
const options = { overflow: "reject" };

const ah0 = Temporal.PlainYearMonth.from({ era: "ah", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ah0,
0, 1, "M01", "AH 0 resolves to BH 1",
"bh", 1, null);

const ah1n = Temporal.PlainYearMonth.from({ era: "ah", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ah1n,
-1, 1, "M01", "AH -1 resolves to BH 2",
"bh", 2, null);

const bh0 = Temporal.PlainYearMonth.from({ era: "bh", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bh0,
1, 1, "M01", "BH 0 resolves to AH 1",
"ah", 1, null);

const bh1n = Temporal.PlainYearMonth.from({ era: "bh", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bh1n,
2, 1, "M01", "BH -1 resolves to AH 2",
"ah", 2, null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.plainyearmonth.from
description: Non-positive era years are remapped in islamic-umalqura calendar
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/

const calendar = "islamic-umalqura";
const options = { overflow: "reject" };

const ah0 = Temporal.PlainYearMonth.from({ era: "ah", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ah0,
0, 1, "M01", "AH 0 resolves to BH 1",
"bh", 1, null);

const ah1n = Temporal.PlainYearMonth.from({ era: "ah", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
ah1n,
-1, 1, "M01", "AH -1 resolves to BH 2",
"bh", 2, null);

const bh0 = Temporal.PlainYearMonth.from({ era: "bh", eraYear: 0, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bh0,
1, 1, "M01", "BH 0 resolves to AH 1",
"ah", 1, null);

const bh1n = Temporal.PlainYearMonth.from({ era: "bh", eraYear: -1, monthCode: "M01", calendar }, options);
TemporalHelpers.assertPlainYearMonth(
bh1n,
2, 1, "M01", "BH -1 resolves to AH 2",
"ah", 2, null);
Loading