From 678c434dab3ca97753dbdaedfa39869666fa11eb Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 30 Oct 2025 15:23:01 -0700 Subject: [PATCH] Temporal: Add tests for correct rounding of epoch milliseconds in toString() --- .../toString/fractionalseconddigits-negative.js | 12 ++++++++++++ .../toString/fractionalseconddigits-negative.js | 12 ++++++++++++ .../toString/fractionalseconddigits-negative.js | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 test/built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-negative.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/toString/fractionalseconddigits-negative.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-negative.js diff --git a/test/built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-negative.js b/test/built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-negative.js new file mode 100644 index 0000000000..64ca1134fb --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-negative.js @@ -0,0 +1,12 @@ +// 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.tostring +description: Epoch milliseconds should be rounded down before adding negative micro/nanoseconds back in +features: [BigInt, Temporal] +---*/ + +const instant = new Temporal.Instant(-1000000000000001000n); +assert.sameValue(instant.toString(), "1938-04-24T22:13:19.999999Z", + "epoch milliseconds should be rounded down to compute seconds"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/fractionalseconddigits-negative.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/fractionalseconddigits-negative.js new file mode 100644 index 0000000000..34fbf2332b --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/fractionalseconddigits-negative.js @@ -0,0 +1,12 @@ +// 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.plaindatetime.prototype.tostring +description: Epoch milliseconds should be rounded down before adding negative micro/nanoseconds back in +features: [Temporal] +---*/ + +const pdt = new Temporal.PlainDateTime(1938, 4, 24, 22, 13, 19, 999, 999); +assert.sameValue(pdt.toString(), "1938-04-24T22:13:19.999999", + "epoch milliseconds should be rounded down to compute seconds"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-negative.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-negative.js new file mode 100644 index 0000000000..4d78a0a811 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/fractionalseconddigits-negative.js @@ -0,0 +1,12 @@ +// 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.zoneddatetime.prototype.tostring +description: Epoch milliseconds should be rounded down before adding negative micro/nanoseconds back in +features: [BigInt, Temporal] +---*/ + +const zdt = new Temporal.ZonedDateTime(-1000000000000001000n, "UTC"); +assert.sameValue(zdt.toString(), "1938-04-24T22:13:19.999999+00:00[UTC]", + "epoch milliseconds should be rounded down to compute seconds");