Skip to content

Commit d904b4b

Browse files
Ms2gerptomato
authored andcommitted
Editorial: Clarify Infinity handling in PlainYearMonth constructor.
1 parent b21ab31 commit d904b4b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/ecmascript.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ const ES2020 = {
150150

151151
export const ES = ObjectAssign({}, ES2020, {
152152
ToPositiveInteger: ToPositiveInteger,
153+
ToFiniteInteger: (value) => {
154+
const integer = ES.ToInteger(value);
155+
if (!NumberIsFinite(integer)) {
156+
throw new RangeError('infinity is out of range');
157+
}
158+
return integer;
159+
},
153160
IsTemporalInstant: (item) => HasSlot(item, EPOCHNANOSECONDS) && !HasSlot(item, TIME_ZONE, CALENDAR),
154161
IsTemporalTimeZone: (item) => HasSlot(item, TIMEZONE_ID),
155162
IsTemporalCalendar: (item) => HasSlot(item, CALENDAR_ID),

lib/plainyearmonth.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const DISALLOWED_UNITS = ['week', 'day', 'hour', 'minute', 'second', 'millisecon
99

1010
export class PlainYearMonth {
1111
constructor(isoYear, isoMonth, calendar = ES.GetISO8601Calendar(), referenceISODay = 1) {
12-
isoYear = ES.ToInteger(isoYear);
13-
isoMonth = ES.ToInteger(isoMonth);
12+
isoYear = ES.ToFiniteInteger(isoYear);
13+
isoMonth = ES.ToFiniteInteger(isoMonth);
1414
calendar = ES.ToTemporalCalendar(calendar);
15-
referenceISODay = ES.ToInteger(referenceISODay);
15+
referenceISODay = ES.ToFiniteInteger(referenceISODay);
1616

1717
// Note: if the arguments are not passed, ToInteger(undefined) will have returned 0, which will
1818
// be rejected by RejectISODate in CreateTemporalYearMonthSlots. This

0 commit comments

Comments
 (0)