From 4d9f01fcf49d23f03e5f775efb0ec82b19365e63 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 30 Oct 2025 16:48:32 -0700 Subject: [PATCH] Temporal: Add a test for rounding negative instants --- .../prototype/round/negative-instant.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/built-ins/Temporal/Instant/prototype/round/negative-instant.js diff --git a/test/built-ins/Temporal/Instant/prototype/round/negative-instant.js b/test/built-ins/Temporal/Instant/prototype/round/negative-instant.js new file mode 100644 index 0000000000..ca249b25e6 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/negative-instant.js @@ -0,0 +1,67 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.round +description: RoundNumberToIncrementAsIfPositive should multiply the remainder by an extra sign + before comparing it +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(-1000000000000000000n); // 1938-04-24T22:13:20Z +const roundedDown = new Temporal.Instant(-1000000800000000000n); // 1938-04-24T22:00:00Z +const roundedUp = new Temporal.Instant(-999997200000000000n); // 1938-04-24T23:00:00Z + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "halfCeil" }).epochNanoseconds, + roundedDown.epochNanoseconds, + "Rounding with halfCeil rounds to the closest hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "halfFloor" }).epochNanoseconds, + roundedDown.epochNanoseconds, + "Rounding with halfFloor rounds to the closest hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "halfExpand" }).epochNanoseconds, + roundedDown.epochNanoseconds, + "Rounding with halfExpand rounds to the closest hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "halfTrunc" }).epochNanoseconds, + roundedDown.epochNanoseconds, + "Rounding with halfTrunc rounds to the closest hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "halfEven" }).epochNanoseconds, + roundedDown.epochNanoseconds, + "Rounding with halfEven rounds to the closest hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "ceil" }).epochNanoseconds, + roundedUp.epochNanoseconds, + "Rounding with ceil rounds to the next hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "floor" }).epochNanoseconds, + roundedDown.epochNanoseconds, + "Rounding with floor rounds to the closest hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "expand" }).epochNanoseconds, + roundedUp.epochNanoseconds, + "Rounding with expand rounds to the next hour" +); + +assert.sameValue( + instance.round({ smallestUnit: "hour", roundingIncrement: 1, roundingMode: "trunc" }).epochNanoseconds, + roundedDown.epochNanoseconds, + "Rounding with trunc rounds to the closest hour" +);