From 13778441ad48f383824f6ecd025393966325e167 Mon Sep 17 00:00:00 2001 From: Guillaume Emont Date: Tue, 7 Mar 2023 18:44:35 +0100 Subject: [PATCH] Temporal: added a test reproducing tc39/proposal-temporal#2508 Before the issue is fixed, rounding a duration such as 'PT2400h' with months as largest unit fails to balance it properly and gives a result with days being the largest unit. The test ensures that such rounding happens properly. --- .../round/largestunit-correct-rebalancing.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/built-ins/Temporal/Duration/prototype/round/largestunit-correct-rebalancing.js diff --git a/test/built-ins/Temporal/Duration/prototype/round/largestunit-correct-rebalancing.js b/test/built-ins/Temporal/Duration/prototype/round/largestunit-correct-rebalancing.js new file mode 100644 index 0000000000..7106936db3 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/largestunit-correct-rebalancing.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: Balancing from hours or smaller to weeks or bigger happens correctly. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const day_duration = 100; + +const tests = [ ["days", { days: day_duration }], + ["hours", { hours: day_duration * 24 }], + ["minutes", { minutes: day_duration * 24 * 60 }], + ["seconds", { seconds: day_duration * 24 * 60 * 60 }], + ["milliseconds", { milliseconds: day_duration * 24 * 60 * 60 * 1000 }], + ["microseconds", { microseconds: day_duration * 24 * 60 * 60 * 1000 * 1000 }], + ["nanoseconds", { nanoseconds: day_duration * 24 * 60 * 60 * 1000 * 1000 * 1000 }]]; + +for ([unit, duration_desc] of tests) + TemporalHelpers.assertDuration(Temporal.Duration.from(duration_desc).round({ relativeTo: '2023-02-21', largestUnit: 'month' }), + 0, 3, 0, 11, 0, 0, 0, 0, 0, 0, `rounding from ${unit}`); +