Skip to content

Commit 36082aa

Browse files
Ms2gerptomato
authored andcommitted
Editorial: Avoid dividing by zero in ZonedDateTime#round.
Ref. #1502.
1 parent be88a9e commit 36082aa

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/zoneddatetime.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ export class ZonedDateTime {
644644
const instantStart = ES.BuiltinTimeZoneGetInstantFor(timeZone, dtStart, 'compatible');
645645
const endNs = ES.AddZonedDateTime(instantStart, timeZone, calendar, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0);
646646
const dayLengthNs = endNs.subtract(GetSlot(instantStart, EPOCHNANOSECONDS));
647+
if (dayLengthNs.isZero()) {
648+
throw new RangeError('can not round a ZonedDateTime in a calendar with zero-length days');
649+
}
647650
({ year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } = ES.RoundISODateTime(
648651
year,
649652
month,

0 commit comments

Comments
 (0)