mirror of https://github.com/tc39/test262.git
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.
This commit is contained in:
parent
6d0978de60
commit
13778441ad
24
test/built-ins/Temporal/Duration/prototype/round/largestunit-correct-rebalancing.js
vendored
Normal file
24
test/built-ins/Temporal/Duration/prototype/round/largestunit-correct-rebalancing.js
vendored
Normal file
|
@ -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}`);
|
||||
|
Loading…
Reference in New Issue