mirror of
https://github.com/tc39/test262.git
synced 2025-11-29 18:13:13 +01:00
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:
parent
d086cbc2a8
commit
29e8305d0f
29
test/built-ins/Temporal/Duration/prototype/round/rounding-window.js
vendored
Normal file
29
test/built-ins/Temporal/Duration/prototype/round/rounding-window.js
vendored
Normal 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);
|
||||||
16
test/built-ins/Temporal/Duration/prototype/total/rounding-window.js
vendored
Normal file
16
test/built-ins/Temporal/Duration/prototype/total/rounding-window.js
vendored
Normal 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);
|
||||||
Loading…
x
Reference in New Issue
Block a user