Skip to content

Commit

Permalink
Factored out relativeTo and added test for rounding 29 days up to weeks
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Nov 11, 2024
1 parent d6bdfbd commit ef93787
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,61 @@ 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,
roundingMode: 'ceil'
}), 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,
roundingMode: 'ceil'
}), 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,
roundingMode: 'ceil'
}), 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);

0 comments on commit ef93787

Please sign in to comment.