From d140b70cde83ba4944c130072a5f84bd225cb858 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 4 Nov 2024 13:38:13 -0800 Subject: [PATCH 1/4] Temporal: Add test for balancing up to weeks when year/month are present See https://github.com/tc39/proposal-temporal/issues/2813 --- .../prototype/round/balances-up-to-weeks.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js diff --git a/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js new file mode 100644 index 00000000000..c3d6c898016 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js @@ -0,0 +1,52 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: Balances up to weeks correctly when years and months are present. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const oneMonthOneDay = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0); +const oneYearOneMonthOneDay = new Temporal.Duration(1, 1, 0, 1, 0, 0, 0, 0, 0, 0); + +// largestUnit must be included +assert.throws(RangeError, () => oneMonthOneDay.round({ + relativeTo: '2024-01-01', + smallestUnit: 'weeks', + roundingIncrement: 99, + roundingMode: 'ceil' +})); + +TemporalHelpers.assertDuration(oneMonthOneDay.round({ + relativeTo: '2024-01-01', + largestUnit: 'weeks', + smallestUnit: 'weeks', + roundingIncrement: 99, + roundingMode: 'ceil' +}), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0); + +TemporalHelpers.assertDuration(oneMonthOneDay.round({ + relativeTo: '2024-01-01', + largestUnit: 'weeks', + smallestUnit: 'weeks', + roundingIncrement: 6, + roundingMode: 'ceil' +}), 0, 0, 6, 0, 0, 0, 0, 0, 0, 0); + +TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({ + relativeTo: '2024-01-01', + largestUnit: 'weeks', + smallestUnit: 'weeks', + roundingIncrement: 99, + roundingMode: 'ceil' +}), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0); + +TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({ + relativeTo: '2024-01-01', + largestUnit: 'weeks', + smallestUnit: 'weeks', + roundingIncrement: 57, + roundingMode: 'ceil' +}), 0, 0, 57, 0, 0, 0, 0, 0, 0, 0); From dda3f4c493227c5099fea2f4c12121e87792fc3f Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 11 Nov 2024 14:37:49 -0800 Subject: [PATCH 2/4] Update test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js Co-authored-by: Philip Chimento --- .../Temporal/Duration/prototype/round/balances-up-to-weeks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js index c3d6c898016..a6a3264cb06 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js +++ b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// Copyright (C) 2024 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- From d6bdfbde5154c6fbcae0c5698fdc8972f347592d Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 11 Nov 2024 14:38:08 -0800 Subject: [PATCH 3/4] Update test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js Co-authored-by: Philip Chimento --- .../Temporal/Duration/prototype/round/balances-up-to-weeks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js index a6a3264cb06..9fc72f01e70 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js +++ b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js @@ -3,7 +3,7 @@ /*--- esid: sec-temporal.duration.prototype.round -description: Balances up to weeks correctly when years and months are present. +description: Rounds up to weeks correctly when years and months are present. includes: [temporalHelpers.js] features: [Temporal] ---*/ From ef93787546cf55f614ea8d221dc6ad6c25feb7fd Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 11 Nov 2024 14:45:14 -0800 Subject: [PATCH 4/4] Factored out relativeTo and added test for rounding 29 days up to weeks --- .../prototype/round/balances-up-to-weeks.js | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js index 9fc72f01e70..56c563a873e 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js +++ b/test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js @@ -10,17 +10,19 @@ features: [Temporal] const oneMonthOneDay = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0); const oneYearOneMonthOneDay = new Temporal.Duration(1, 1, 0, 1, 0, 0, 0, 0, 0, 0); +const severalWeeksInDays = new Temporal.Duration(0, 0, 0, 29, 0, 0, 0, 0, 0, 0); +const relativeTo = new Temporal.PlainDate(2024, 1, 1); // largestUnit must be included assert.throws(RangeError, () => oneMonthOneDay.round({ - relativeTo: '2024-01-01', + relativeTo, smallestUnit: 'weeks', roundingIncrement: 99, roundingMode: 'ceil' })); TemporalHelpers.assertDuration(oneMonthOneDay.round({ - relativeTo: '2024-01-01', + relativeTo, largestUnit: 'weeks', smallestUnit: 'weeks', roundingIncrement: 99, @@ -28,7 +30,7 @@ TemporalHelpers.assertDuration(oneMonthOneDay.round({ }), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0); TemporalHelpers.assertDuration(oneMonthOneDay.round({ - relativeTo: '2024-01-01', + relativeTo, largestUnit: 'weeks', smallestUnit: 'weeks', roundingIncrement: 6, @@ -36,7 +38,7 @@ TemporalHelpers.assertDuration(oneMonthOneDay.round({ }), 0, 0, 6, 0, 0, 0, 0, 0, 0, 0); TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({ - relativeTo: '2024-01-01', + relativeTo, largestUnit: 'weeks', smallestUnit: 'weeks', roundingIncrement: 99, @@ -44,9 +46,25 @@ TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({ }), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0); TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({ - relativeTo: '2024-01-01', + relativeTo, largestUnit: 'weeks', smallestUnit: 'weeks', roundingIncrement: 57, roundingMode: 'ceil' }), 0, 0, 57, 0, 0, 0, 0, 0, 0, 0); + +TemporalHelpers.assertDuration(severalWeeksInDays.round({ + relativeTo, + largestUnit: 'weeks', + smallestUnit: 'weeks', + roundingIncrement: 5, + roundingMode: 'ceil' +}), 0, 0, 5, 0, 0, 0, 0, 0, 0, 0); + +TemporalHelpers.assertDuration(severalWeeksInDays.round({ + relativeTo, + largestUnit: 'weeks', + smallestUnit: 'weeks', + roundingIncrement: 8, + roundingMode: 'ceil' +}), 0, 0, 8, 0, 0, 0, 0, 0, 0, 0);