Temporal: Tests for duration rounding and totaling (#4662)

* Temporal: Tests for duration rounding and totaling

This provides coverage for the bug in https://github.com/tc39/proposal-temporal/issues/3168

* Update test/built-ins/Temporal/Duration/prototype/total/rounding-window.js

---------

Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
This commit is contained in:
Tim Chevalier 2025-11-18 15:15:51 -08:00 committed by GitHub
parent d086cbc2a8
commit 29e8305d0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// 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.duration.prototype.round
description: See https://github.com/tc39/proposal-temporal/issues/3168
includes: [temporalHelpers.js]
features: [Temporal]
---*/
var d = new Temporal.Duration(1, 0, 0, 0, 1);
var relativeTo = new Temporal.PlainDate(2020, 2, 29);
TemporalHelpers.assertDuration(d.round({ smallestUnit: 'years', relativeTo }),
1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
d = new Temporal.Duration(0, 1, 0, 0, 10);
relativeTo = new Temporal.PlainDate(2020, 1, 31);
TemporalHelpers.assertDuration(d.round({ smallestUnit: 'months', roundingMode: 'expand', relativeTo }),
0, 2, 0, 0, 0, 0, 0, 0, 0, 0);
d = new Temporal.Duration(2345, 0, 0, 0, 12);
relativeTo = new Temporal.PlainDate(2020, 2, 29)
TemporalHelpers.assertDuration(d.round({ smallestUnit: 'years', roundingMode: 'expand', relativeTo }),
2346, 0, 0, 0, 0, 0, 0, 0, 0, 0);
d = new Temporal.Duration(1);
relativeTo = new Temporal.PlainDate(2020, 2, 29)
TemporalHelpers.assertDuration(d.round({ smallestUnit: 'months', relativeTo }),
1, 0, 0, 0, 0, 0, 0, 0, 0, 0);

View File

@ -0,0 +1,16 @@
// 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.duration.prototype.total
description: See https://github.com/tc39/proposal-temporal/issues/3168
features: [Temporal]
---*/
var d = new Temporal.Duration(1, 0, 0, 0, 1);
var relativeTo = new Temporal.PlainDate(2020, 2, 29);
assert.sameValue(d.total({ unit: 'years', relativeTo }), 1.0001141552511414);
d = new Temporal.Duration(0, 1, 0, 0, 10);
relativeTo = new Temporal.PlainDate(2020, 1, 31);
assert.sameValue(d.total({ unit: 'months', relativeTo }), 1.0134408602150538);