Skip to content

Should CalendarDaysInMonth be called in Temporal.PlainYearMonth.prototype.subtract #1863

@FrankYFTang

Description

@FrankYFTang

While I try to debug my implementation of test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-daysinmonth-wrong-value.js

I found the test does not align with the spec. My guess is we have a spec issue but could be the test has issue.

The test said
"daysInMonth is only called if we are subtracting a positive duration"

const duration = new Temporal.Duration(1, 1);

[Infinity, -Infinity, -42].forEach((badValue) => {
  const calendar = new CalendarDaysInMonthWrongValue(badValue);
  const yearMonth = new Temporal.PlainYearMonth(2000, 5, calendar);
  assert.throws(RangeError, () => yearMonth.subtract(duration), `daysInMonth ${badValue}`);

but if we look at the spec text
https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype.subtract
9.3.13 Temporal.PlainYearMonth.prototype.subtract ( temporalDurationLike [ , options ] )

8. Let sign be ! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], balanceResult.[[Days]], 0, 0, 0, 0, 0, 0).
9. If sign < 0, then
a. Let dayFromCalendar be ? CalendarDaysInMonth(calendar, yearMonth).
b. Let day be ? ToPositiveInteger(dayFromCalendar).
10. Else,
a. Let day be 1.

The CalendarDaysInMonth is only called while "sign < 0," NOT "sign > 0,"

Should "9. If sign < 0, then" be "9. If sign > 0, then" instead? or the test should be changed?

@ptomato @Ms2ger @ryzokuken @jugglinmike

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions