summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/round/div-zero.js
blob: 776cb7454f5e57a60c58f73652101217c0546cb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.zoneddatetime.prototype.round
description: RangeError thrown if the calculated day length is zero
features: [Temporal]
---*/

class TimeZone extends Temporal.TimeZone {
  #calls = 0;
  getPossibleInstantsFor(dateTime) {
    if (++this.#calls === 2) {
      return super.getPossibleInstantsFor(dateTime.withCalendar("iso8601").subtract({ days: 1 }));
    }
    return super.getPossibleInstantsFor(dateTime);
  }
}

const units = ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"];
for (const smallestUnit of units) {
  const zdt = new Temporal.ZonedDateTime(0n, new TimeZone("UTC"));
  assert.throws(RangeError, () => zdt.round({ smallestUnit, roundingIncrement: 2 }), `zero day-length with smallestUnit ${smallestUnit}`);
}

reportCompare(0, 0);