mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Temporal: Add test for balancing up to weeks when year/month are present (#4305)
See tc39/proposal-temporal#2813
This commit is contained in:
parent
4053ff2eaf
commit
901dd6e920
70
test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js
vendored
Normal file
70
test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// Copyright (C) 2024 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: Rounds 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);
|
||||||
|
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,
|
||||||
|
smallestUnit: 'weeks',
|
||||||
|
roundingIncrement: 99,
|
||||||
|
roundingMode: 'ceil'
|
||||||
|
}));
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(oneMonthOneDay.round({
|
||||||
|
relativeTo,
|
||||||
|
largestUnit: 'weeks',
|
||||||
|
smallestUnit: 'weeks',
|
||||||
|
roundingIncrement: 99,
|
||||||
|
roundingMode: 'ceil'
|
||||||
|
}), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(oneMonthOneDay.round({
|
||||||
|
relativeTo,
|
||||||
|
largestUnit: 'weeks',
|
||||||
|
smallestUnit: 'weeks',
|
||||||
|
roundingIncrement: 6,
|
||||||
|
roundingMode: 'ceil'
|
||||||
|
}), 0, 0, 6, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({
|
||||||
|
relativeTo,
|
||||||
|
largestUnit: 'weeks',
|
||||||
|
smallestUnit: 'weeks',
|
||||||
|
roundingIncrement: 99,
|
||||||
|
roundingMode: 'ceil'
|
||||||
|
}), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({
|
||||||
|
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);
|
Loading…
x
Reference in New Issue
Block a user