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:
Guillaume Emont 2023-03-07 18:44:35 +01:00 committed by Philip Chimento
parent 6d0978de60
commit 13778441ad
1 changed files with 24 additions and 0 deletions

View 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}`);