diff --git a/test/built-ins/Temporal/Duration/prototype/round/rounding-window.js b/test/built-ins/Temporal/Duration/prototype/round/rounding-window.js new file mode 100644 index 0000000000..71c8065f56 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/rounding-window.js @@ -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); diff --git a/test/built-ins/Temporal/Duration/prototype/total/rounding-window.js b/test/built-ins/Temporal/Duration/prototype/total/rounding-window.js new file mode 100644 index 0000000000..4a6e3bbc21 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/total/rounding-window.js @@ -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);