From a5b94ee20dcb9fedbe4539cac6b6bc65894109f2 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 3 Dec 2025 17:46:32 -0800 Subject: [PATCH] TemporalHelpers: Add feature for auto-computing PlainYearMonth ref day There are cases where we don't care exactly what the PlainYearMonth's ISO reference day is, just that it is consistent with PlainDate. To enable writing tests for this, add a feature to TemporalHelpers.assertPlainYearMonth() where you can pass null as the referenceISODay argument, and it will be checked for consistency with PlainDate but not asserted to be any particular value. I considered making this the default argument, but the default argument was already 1, which is valuable for calendars that are ISO-like, and I didn't want to have to go back and change all callers. --- harness/temporalHelpers.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index 45e12ef9d7..42341d0644 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -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), @@ -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; + assert.sameValue(isoDay, expectedISODay, `${prefix}referenceISODay result:`); }, /*