test262 icon indicating copy to clipboard operation
test262 copied to clipboard

Add test for skipped initial days in Temporal.Calendar.prototype.yearMonthFromFields

Open anba opened this issue 1 year ago • 1 comments

The polyfill doesn't pass this test:

let pym = Temporal.PlainYearMonth.from({calendar: "japanese", era: "heisei", eraYear: 1, month: 1});
console.log(pym.getISOFields().isoDay);  // Prints 1
console.log(pym.era);  // Prints "showa"

Is this a bug in the polyfill or did I misinterpret this step from Temporal.Calendar.prototype.yearMonthFromFields?

7.c Let firstDayIndex be the 1-based index of the first day of the month described by fields (i.e., 1 unless the month's first day is skipped by this calendar.)

anba avatar May 14 '24 14:05 anba

I think that might indeed be a misinterpretation of that step. That January spans two era/eraYear pairs, Showa 64 and Heisei 1. It's not two separate Januaries, so the PlainYearMonth correctly resolves to the era/eraYear pair in effect at the beginning of the month.

firstDayIndex is only intended to not be 1 if the calendar skips days at the beginning of the month outright, which none of the current ICU calendars do. (The only occurrence I'm aware of is in the switch from Julian to Gregorian calendar in some European regions, where they skipped days at the beginning of the month rather than in the middle.)

See also tc39/proposal-temporal#1315 and tc39/proposal-temporal#1300.

ptomato avatar May 14 '24 17:05 ptomato