Skip to content

Commit

Permalink
Temporal: added a test reproducing tc39/proposal-temporal#2508
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guijemont authored and ptomato committed Apr 10, 2023
1 parent 6d0978d commit 2d37892
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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}`);

0 comments on commit 2d37892

Please sign in to comment.