Skip to content

Commit

Permalink
Temporal: Add test for balancing up to weeks when year/month are present
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Nov 4, 2024
1 parent ab69bd4 commit d140b70
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit d140b70

Please sign in to comment.