diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/round/smallest-unit-day-rounding-modes.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/round/smallest-unit-day-rounding-modes.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/round/smallest-unit-day-rounding-modes.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/round/smallest-unit-day-rounding-modes.js b/js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/round/smallest-unit-day-rounding-modes.js new file mode 100644 index 0000000000..f694712457 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/round/smallest-unit-day-rounding-modes.js @@ -0,0 +1,97 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2022 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.round +description: > + Round smallestUnit "day" with various rounding modes. +info: | + Temporal.ZonedDateTime.prototype.round ( roundTo ) + ... + 18. Let dayLengthNs be ℝ(endNs - startNs). + ... + 20. Let roundResult be ! RoundISODateTime(temporalDateTime.[[ISOYear]], + temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], temporalDateTime.[[ISOHour]], + temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], + temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], + temporalDateTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode, + dayLengthNs). + ... + + RoundISODateTime ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, + increment, unit, roundingMode [ , dayLength ] ) + ... + 4. Let roundedTime be ! RoundTime(hour, minute, second, millisecond, microsecond, nanosecond, + increment, unit, roundingMode, dayLength). + ... + + RoundTime ( hour, minute, second, millisecond, microsecond, nanosecond, increment, unit, + roundingMode [ , dayLengthNs ] ) + ... + 4. If unit is "day", then + ... + b. Let quantity be (((((hour × 60 + minute) × 60 + second) × 1000 + millisecond) × 1000 + + microsecond) × 1000 + nanosecond) / dayLengthNs. + ... +features: [Temporal] +---*/ + +class TimeZone extends Temporal.TimeZone { + #count = 0; + #nanoseconds; + + constructor(nanoseconds) { + super("UTC"); + this.#nanoseconds = nanoseconds; + } + getPossibleInstantsFor(dateTime) { + if (++this.#count === 2) { + return [new Temporal.Instant(this.#nanoseconds)]; + } + return super.getPossibleInstantsFor(dateTime); + } +} + +function test(epochNanoseconds, tomorrowEpochNanoseconds, testCases) { + for (let [roundingMode, expected] of Object.entries(testCases)) { + let timeZone = new TimeZone(tomorrowEpochNanoseconds); + let zoned = new Temporal.ZonedDateTime(epochNanoseconds, timeZone); + let result = zoned.round({ smallestUnit: "days", roundingMode }); + assert.sameValue(result.epochNanoseconds, expected); + } +} + +const oneDay = 24n * 60n * 60n * 1000n * 1000n * 1000n; + +// Test positive divisor (dayLengthNs). +test(3n, 10n, { + ceil: oneDay, + floor: 0n, + trunc: 0n, + halfExpand: 0n, +}); + +test(-3n, 10n, { + ceil: 0n, + floor: -oneDay, + trunc: -oneDay, + halfExpand: 0n, +}); + +test(-3n, -10n, { + ceil: oneDay, + floor: 0n, + trunc: 0n, + halfExpand: 0n, +}); + +// Test values at int64 boundaries. +test(3n, /*INT64_MAX=*/ 9223372036854775807n, { + ceil: oneDay, + floor: 0n, + trunc: 0n, + halfExpand: 0n, +}); + +reportCompare(0, 0); |