mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
Temporal: Remove BigInt arithmetic and loops in BalanceDurationRelative
A few results change because the algorithm previously used for rounding didn't always add duration units to dates in RFC 5545 order, and we also introduce a special case for rounding with largestUnit years or months and smallestUnit weeks.
This commit is contained in:
parent
50abc12d97
commit
e43e20a885
@ -20,13 +20,11 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|||||||
// RoundDuration ->
|
// RoundDuration ->
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||||
// MoveRelativeDate -> calendar.dateAdd()
|
// MoveRelativeDate -> calendar.dateAdd()
|
||||||
// BalanceDurationRelative ->
|
// BalanceDateDurationRelative -> calendar.dateAdd()
|
||||||
// MoveRelativeDate -> calendar.dateAdd() (2x)
|
|
||||||
// calendar.dateAdd()
|
|
||||||
|
|
||||||
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance1.round({ smallestUnit: "weeks", relativeTo });
|
instance1.round({ smallestUnit: "weeks", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 5, "rounding with calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 3, "rounding with calendar smallestUnit");
|
||||||
|
|
||||||
// Rounding with a non-default largestUnit to cover the path in
|
// Rounding with a non-default largestUnit to cover the path in
|
||||||
// UnbalanceDurationRelative where larger units are converted into smaller
|
// UnbalanceDurationRelative where larger units are converted into smaller
|
||||||
@ -37,8 +35,7 @@ assert.sameValue(calendar.dateAddCallCount, 5, "rounding with calendar smallestU
|
|||||||
// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd()
|
// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd()
|
||||||
// RoundDuration ->
|
// RoundDuration ->
|
||||||
// MoveRelativeDate -> calendar.dateAdd() (5x)
|
// MoveRelativeDate -> calendar.dateAdd() (5x)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative -> calendar.dateAdd()
|
||||||
// MoveRelativeDate -> calendar.dateAdd()
|
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||||
|
|
||||||
calendar.dateAddCallCount = 0;
|
calendar.dateAddCallCount = 0;
|
||||||
@ -52,12 +49,10 @@ assert.sameValue(calendar.dateAddCallCount, 8, "rounding with non-default larges
|
|||||||
// Duration.round() ->
|
// Duration.round() ->
|
||||||
// RoundDuration ->
|
// RoundDuration ->
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||||
// BalanceDurationRelative ->
|
// BalanceDateDurationRelative -> calendar.dateAdd()
|
||||||
// MoveRelativeDate -> calendar.dateAdd() (2x)
|
|
||||||
// calendar.dateAdd()
|
|
||||||
|
|
||||||
calendar.dateAddCallCount = 0;
|
calendar.dateAddCallCount = 0;
|
||||||
|
|
||||||
const instance3 = new Temporal.Duration(1, 1, 1, 1, 1);
|
const instance3 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance3.round({ smallestUnit: "days", relativeTo });
|
instance3.round({ smallestUnit: "days", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 4, "rounding with days smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 2, "rounding with days smallestUnit");
|
||||||
|
@ -74,8 +74,8 @@ features: [Temporal]
|
|||||||
// should result in one call to dateUntil() originating from
|
// should result in one call to dateUntil() originating from
|
||||||
// AdjustRoundedDurationDays, with largestUnit equal to the largest unit in
|
// AdjustRoundedDurationDays, with largestUnit equal to the largest unit in
|
||||||
// the duration higher than "day".
|
// the duration higher than "day".
|
||||||
// Additionally one call with largestUnit: "month" in BalanceDurationRelative
|
// Additionally one call in BalanceDateDurationRelative with the same
|
||||||
// when the largestUnit given to round() is "year".
|
// largestUnit.
|
||||||
// Other calls have largestUnit: "day" so the difference is taken in ISO
|
// Other calls have largestUnit: "day" so the difference is taken in ISO
|
||||||
// calendar space.
|
// calendar space.
|
||||||
|
|
||||||
@ -99,9 +99,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
duration.round({ largestUnit, roundingIncrement: 2, roundingMode: 'ceil', relativeTo });
|
duration.round({ largestUnit, roundingIncrement: 2, roundingMode: 'ceil', relativeTo });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
years: ["year", "month"],
|
years: ["year", "year"],
|
||||||
months: ["month"],
|
months: ["month", "month"],
|
||||||
weeks: ["week"],
|
weeks: ["week", "week"],
|
||||||
days: [],
|
days: [],
|
||||||
hours: [],
|
hours: [],
|
||||||
minutes: [],
|
minutes: [],
|
||||||
@ -122,9 +122,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
duration.round({ largestUnit, relativeTo });
|
duration.round({ largestUnit, relativeTo });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
years: ["month", "month", "month", "month", "month", "month"],
|
years: ["year"],
|
||||||
months: ["month"],
|
months: ["month", "month"],
|
||||||
weeks: [],
|
weeks: ["week"],
|
||||||
days: [],
|
days: [],
|
||||||
hours: [],
|
hours: [],
|
||||||
minutes: [],
|
minutes: [],
|
||||||
@ -147,8 +147,8 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
duration.round({ largestUnit, smallestUnit: largestUnit, relativeTo });
|
duration.round({ largestUnit, smallestUnit: largestUnit, relativeTo });
|
||||||
}, {
|
}, {
|
||||||
years: ["year"],
|
years: ["year"],
|
||||||
months: [],
|
months: ["month"],
|
||||||
weeks: [],
|
weeks: ["week"],
|
||||||
days: []
|
days: []
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -45,8 +45,8 @@ assert.throws(
|
|||||||
"rounding a week Duration fails without largest/smallest unit"
|
"rounding a week Duration fails without largest/smallest unit"
|
||||||
);
|
);
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(duration3.round(relativeToYears), 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, "round week duration to years");
|
TemporalHelpers.assertDuration(duration3.round(relativeToYears), 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, "round week duration to years");
|
||||||
TemporalHelpers.assertDuration(duration3.round(relativeToMonths), 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, "round week duration to months");
|
TemporalHelpers.assertDuration(duration3.round(relativeToMonths), 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, "round week duration to months");
|
||||||
TemporalHelpers.assertDuration(duration3.round(relativeToWeeks), 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, "round week duration to weeks");
|
TemporalHelpers.assertDuration(duration3.round(relativeToWeeks), 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, "round week duration to weeks");
|
||||||
TemporalHelpers.assertDuration(duration3.round(relativeToDays), 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, "round week duration to days");
|
TemporalHelpers.assertDuration(duration3.round(relativeToDays), 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, "round week duration to days");
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
/*---
|
/*---
|
||||||
esid: sec-temporal.duration.prototype.round
|
esid: sec-temporal.duration.prototype.round
|
||||||
description: >
|
description: >
|
||||||
When consulting calendar.dateUntil() to calculate the number of months in a
|
When consulting calendar.dateUntil() to balance or unbalance a duration, no
|
||||||
year, the months property is not accessed on the result Duration
|
properties are accessed on the result Duration
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
includes: [compareArray.js, temporalHelpers.js]
|
||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
@ -16,7 +16,10 @@ class CalendarDateUntilObservable extends Temporal.Calendar {
|
|||||||
dateUntil(...args) {
|
dateUntil(...args) {
|
||||||
actual.push("call dateUntil");
|
actual.push("call dateUntil");
|
||||||
const returnValue = super.dateUntil(...args);
|
const returnValue = super.dateUntil(...args);
|
||||||
|
TemporalHelpers.observeProperty(actual, returnValue, "years", Infinity);
|
||||||
TemporalHelpers.observeProperty(actual, returnValue, "months", Infinity);
|
TemporalHelpers.observeProperty(actual, returnValue, "months", Infinity);
|
||||||
|
TemporalHelpers.observeProperty(actual, returnValue, "weeks", Infinity);
|
||||||
|
TemporalHelpers.observeProperty(actual, returnValue, "days", Infinity);
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,28 +27,12 @@ class CalendarDateUntilObservable extends Temporal.Calendar {
|
|||||||
const calendar = new CalendarDateUntilObservable("iso8601");
|
const calendar = new CalendarDateUntilObservable("iso8601");
|
||||||
const relativeTo = new Temporal.PlainDate(2018, 10, 12, calendar);
|
const relativeTo = new Temporal.PlainDate(2018, 10, 12, calendar);
|
||||||
|
|
||||||
// One path, through UnbalanceDateDurationRelative, calls dateUntil()
|
const expected = [
|
||||||
|
"call dateUntil", // UnbalanceDateDurationRelative
|
||||||
const expected1 = [
|
"call dateUntil", // BalanceDateDurationRelative
|
||||||
"call dateUntil",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const years = new Temporal.Duration(2);
|
const years = new Temporal.Duration(2);
|
||||||
const result1 = years.round({ largestUnit: "months", relativeTo });
|
const result = years.round({ largestUnit: "months", relativeTo });
|
||||||
TemporalHelpers.assertDuration(result1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, "result");
|
TemporalHelpers.assertDuration(result, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, "result");
|
||||||
assert.compareArray(actual, expected1, "operations");
|
assert.compareArray(actual, expected, "operations");
|
||||||
|
|
||||||
// There is a second path, through BalanceDurationRelative, that calls
|
|
||||||
// dateUntil() in a loop for each year in the duration plus one extra time
|
|
||||||
|
|
||||||
actual.splice(0); // reset calls for next test
|
|
||||||
const expected2 = [
|
|
||||||
"call dateUntil",
|
|
||||||
"call dateUntil",
|
|
||||||
"call dateUntil",
|
|
||||||
];
|
|
||||||
|
|
||||||
const months = new Temporal.Duration(0, 24);
|
|
||||||
const result2 = months.round({ largestUnit: "years", relativeTo });
|
|
||||||
TemporalHelpers.assertDuration(result2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "result");
|
|
||||||
assert.compareArray(actual, expected2, "operations");
|
|
||||||
|
@ -10,8 +10,8 @@ features: [Temporal]
|
|||||||
|
|
||||||
// Based on a test case by André Bargull <andre.bargull@gmail.com>
|
// Based on a test case by André Bargull <andre.bargull@gmail.com>
|
||||||
|
|
||||||
// Note: February in a leap year.
|
// Note: One day after February in a leap year.
|
||||||
const relativeTo = new Temporal.PlainDate(1972, 2, 1);
|
const relativeTo = new Temporal.PlainDate(1972, 3, 1);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
largestUnit: "years",
|
largestUnit: "years",
|
||||||
|
@ -139,10 +139,8 @@ const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
|
|||||||
"call options.relativeTo.calendar.dateAdd", // 7.s MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 7.s MoveRelativeDate
|
||||||
"call options.relativeTo.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// BalanceDateDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call options.relativeTo.calendar.dateUntil", // 9.d
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.k
|
|
||||||
"call options.relativeTo.calendar.dateUntil", // 11.p
|
|
||||||
]);
|
]);
|
||||||
const instanceYears = new Temporal.Duration(1, 12, 0, 0, /* hours = */ 2400);
|
const instanceYears = new Temporal.Duration(1, 12, 0, 0, /* hours = */ 2400);
|
||||||
instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo }));
|
instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo }));
|
||||||
@ -159,8 +157,9 @@ const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([
|
|||||||
"call options.relativeTo.calendar.dateAdd", // 10.e
|
"call options.relativeTo.calendar.dateAdd", // 10.e
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
], Array(2).fill("call options.relativeTo.calendar.dateAdd"), [ // 2× 10.n.iii MoveRelativeDate
|
], Array(2).fill("call options.relativeTo.calendar.dateAdd"), [ // 2× 10.n.iii MoveRelativeDate
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd",
|
"call options.relativeTo.calendar.dateAdd", // 10.d
|
||||||
|
"call options.relativeTo.calendar.dateUntil", // 10.e
|
||||||
]);
|
]);
|
||||||
const instance2 = new Temporal.Duration(1, 0, 0, 62);
|
const instance2 = new Temporal.Duration(1, 0, 0, 62);
|
||||||
instance2.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "months", relativeTo: plainRelativeTo }));
|
instance2.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "months", relativeTo: plainRelativeTo }));
|
||||||
@ -174,8 +173,9 @@ const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.d MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 11.d MoveRelativeDate
|
||||||
], Array(58).fill("call options.relativeTo.calendar.dateAdd"), [ // 58× 11.g.iii MoveRelativeDate (52 + 4 + 2)
|
], Array(58).fill("call options.relativeTo.calendar.dateAdd"), [ // 58× 11.g.iii MoveRelativeDate (52 + 4 + 2)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 12.c
|
"call options.relativeTo.calendar.dateAdd", // 16
|
||||||
|
"call options.relativeTo.calendar.dateUntil", // 17
|
||||||
]);
|
]);
|
||||||
const instance3 = new Temporal.Duration(1, 1, 0, 15);
|
const instance3 = new Temporal.Duration(1, 1, 0, 15);
|
||||||
instance3.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo: plainRelativeTo }));
|
instance3.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo: plainRelativeTo }));
|
||||||
@ -191,14 +191,10 @@ instance4.round(createOptionsObserver({ largestUnit: "days", smallestUnit: "days
|
|||||||
assert.compareArray(actual, expectedOpsForDayRounding, "order of operations with largestUnit = smallestUnit = days");
|
assert.compareArray(actual, expectedOpsForDayRounding, "order of operations with largestUnit = smallestUnit = days");
|
||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
|
|
||||||
// code path through BalanceDurationRelative balancing from days up to years:
|
// code path through BalanceDateDurationRelative balancing from days up to years:
|
||||||
const expectedOpsForDayToYearBalancing = expectedOpsForPlainRelativeTo.concat([
|
const expectedOpsForDayToYearBalancing = expectedOpsForPlainRelativeTo.concat([
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.b MoveRelativeDate
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.e.iv MoveRelativeDate
|
"call options.relativeTo.calendar.dateUntil", // 9.d
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.f MoveRelativeDate
|
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.i.iv MoveRelativeDate
|
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.j
|
|
||||||
"call options.relativeTo.calendar.dateUntil", // 10.n
|
|
||||||
]);
|
]);
|
||||||
const instance5 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 396 * 24);
|
const instance5 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 396 * 24);
|
||||||
instance5.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "days", relativeTo: plainRelativeTo }));
|
instance5.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "days", relativeTo: plainRelativeTo }));
|
||||||
@ -211,13 +207,9 @@ const expectedOpsForMonthToYearBalancing = expectedOpsForPlainRelativeTo.concat(
|
|||||||
"call options.relativeTo.calendar.dateAdd", // 10.c
|
"call options.relativeTo.calendar.dateAdd", // 10.c
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.e
|
"call options.relativeTo.calendar.dateAdd", // 10.e
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.b MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.f MoveRelativeDate
|
"call options.relativeTo.calendar.dateUntil", // 9.d
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.j
|
|
||||||
"call options.relativeTo.calendar.dateUntil", // 10.n
|
|
||||||
"call options.relativeTo.calendar.dateAdd", // 10.p.iv
|
|
||||||
"call options.relativeTo.calendar.dateUntil", // 10.p.vii
|
|
||||||
]);
|
]);
|
||||||
const instance6 = new Temporal.Duration(0, 12);
|
const instance6 = new Temporal.Duration(0, 12);
|
||||||
instance6.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "months", relativeTo: plainRelativeTo }));
|
instance6.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "months", relativeTo: plainRelativeTo }));
|
||||||
@ -225,9 +217,8 @@ assert.compareArray(actual, expectedOpsForMonthToYearBalancing, "order of operat
|
|||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
|
|
||||||
const expectedOpsForDayToMonthBalancing = expectedOpsForPlainRelativeTo.concat([
|
const expectedOpsForDayToMonthBalancing = expectedOpsForPlainRelativeTo.concat([
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.b MoveRelativeDate
|
"call options.relativeTo.calendar.dateUntil", // 10.e
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.e.iv MoveRelativeDate
|
|
||||||
]);
|
]);
|
||||||
const instance7 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 32 * 24);
|
const instance7 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 32 * 24);
|
||||||
instance7.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "days", relativeTo: plainRelativeTo }));
|
instance7.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "days", relativeTo: plainRelativeTo }));
|
||||||
@ -235,9 +226,8 @@ assert.compareArray(actual, expectedOpsForDayToMonthBalancing, "order of operati
|
|||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
|
|
||||||
const expectedOpsForDayToWeekBalancing = expectedOpsForPlainRelativeTo.concat([
|
const expectedOpsForDayToWeekBalancing = expectedOpsForPlainRelativeTo.concat([
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 12.c MoveRelativeDate
|
"call options.relativeTo.calendar.dateUntil", // 17
|
||||||
"call options.relativeTo.calendar.dateAdd", // 12.f.iv MoveRelativeDate
|
|
||||||
]);
|
]);
|
||||||
const instance8 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 8 * 24);
|
const instance8 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 8 * 24);
|
||||||
instance8.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "days", relativeTo: plainRelativeTo }));
|
instance8.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "days", relativeTo: plainRelativeTo }));
|
||||||
@ -403,10 +393,8 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
|
|||||||
"call options.relativeTo.calendar.dateAdd", // 7.s MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 7.s MoveRelativeDate
|
||||||
"call options.relativeTo.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// BalanceDateDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call options.relativeTo.calendar.dateUntil", // 9.d
|
||||||
"call options.relativeTo.calendar.dateAdd", // 11.k
|
|
||||||
"call options.relativeTo.calendar.dateUntil", // 11.p
|
|
||||||
]);
|
]);
|
||||||
instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo }));
|
instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo }));
|
||||||
assert.compareArray(
|
assert.compareArray(
|
||||||
@ -431,12 +419,35 @@ const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call options.relativeTo.calendar.dateAdd", // 8.g MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 8.g MoveRelativeDate
|
||||||
// BalanceDateDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call options.relativeTo.calendar.dateAdd", // 13.c MoveRelativeDate
|
"call options.relativeTo.calendar.dateAdd", // 10.d
|
||||||
|
"call options.relativeTo.calendar.dateUntil", // 10.e
|
||||||
|
]);
|
||||||
|
new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "years", smallestUnit: "weeks", relativeTo: zonedRelativeTo }));
|
||||||
|
assert.compareArray(
|
||||||
|
actual,
|
||||||
|
expectedOpsForUnbalanceRoundBalance,
|
||||||
|
"order of operations with largestUnit = years, smallestUnit = weeks, and ZonedDateTime relativeTo"
|
||||||
|
);
|
||||||
|
actual.splice(0); // clear
|
||||||
|
|
||||||
|
// code path that skips user code calls in BalanceDateDurationRelative due to
|
||||||
|
// special case for largestUnit months and smallestUnit weeks
|
||||||
|
const expectedOpsForWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([
|
||||||
|
// ToTemporalDate
|
||||||
|
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
|
// lookup in Duration.p.round
|
||||||
|
"get options.relativeTo.calendar.dateAdd",
|
||||||
|
"get options.relativeTo.calendar.dateUntil",
|
||||||
|
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
|
||||||
|
"call options.relativeTo.calendar.dateAdd",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor
|
||||||
|
// RoundDuration
|
||||||
|
"call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate
|
||||||
]);
|
]);
|
||||||
new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo }));
|
new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo }));
|
||||||
assert.compareArray(
|
assert.compareArray(
|
||||||
actual,
|
actual,
|
||||||
expectedOpsForUnbalanceRoundBalance,
|
expectedOpsForWeeksSpecialCase,
|
||||||
"order of operations with largestUnit = months, smallestUnit = weeks, and ZonedDateTime relativeTo"
|
"order of operations with largestUnit = months, smallestUnit = weeks, and ZonedDateTime relativeTo"
|
||||||
);
|
);
|
||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.duration.prototype.round
|
|
||||||
description: >
|
|
||||||
BalanceDurationRelative computes on exact mathematical values.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
months: Number.MAX_SAFE_INTEGER,
|
|
||||||
days: 31 + 28 + 31,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "months",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
0, 9007199254740994, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
months: Number.MAX_SAFE_INTEGER,
|
|
||||||
days: 31 + 28 + 31 + 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "months",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
0, 9007199254740994, 0, 1,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.duration.prototype.round
|
|
||||||
description: >
|
|
||||||
BalanceDurationRelative computes on exact mathematical values.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
weeks: Number.MAX_SAFE_INTEGER,
|
|
||||||
days: 7 * 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "weeks",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
0, 0, 9007199254740994, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
weeks: Number.MAX_SAFE_INTEGER,
|
|
||||||
days: 7 * 3 + 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "weeks",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
0, 0, 9007199254740994, 1,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.duration.prototype.round
|
|
||||||
description: >
|
|
||||||
BalanceDurationRelative computes on exact mathematical values.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
years: Number.MAX_SAFE_INTEGER,
|
|
||||||
days: 366 + 365 + 365,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "years",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
9007199254740994, 0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
years: Number.MAX_SAFE_INTEGER,
|
|
||||||
days: 366 + 365 + 365 + 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "years",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
9007199254740994, 0, 0, 1,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.duration.prototype.round
|
|
||||||
description: >
|
|
||||||
BalanceDurationRelative computes on exact mathematical values.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
years: Number.MAX_SAFE_INTEGER,
|
|
||||||
months: 12 * 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "years",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
9007199254740994, 0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
years: Number.MAX_SAFE_INTEGER,
|
|
||||||
months: 12 * 3 + 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "years",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
9007199254740994, 1, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
// Copyright (C) 2022 André Bargull. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.duration.prototype.round
|
|
||||||
description: >
|
|
||||||
BalanceDurationRelative computes on exact mathematical values.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
let calendar = new class extends Temporal.Calendar {
|
|
||||||
#dateUntil = 0;
|
|
||||||
dateUntil(one, two, options) {
|
|
||||||
this.#dateUntil++;
|
|
||||||
|
|
||||||
// Subtract one six times from 9007199254740996.
|
|
||||||
if (this.#dateUntil <= 6) {
|
|
||||||
return Temporal.Duration.from({months: 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
// After subtracting six in total, months is 9007199254740996 - 6 = 9007199254740990.
|
|
||||||
// |MAX_SAFE_INTEGER| = 9007199254740991 is larger than 9007199254740990, so we exit
|
|
||||||
// from the loop.
|
|
||||||
if (this.#dateUntil === 7) {
|
|
||||||
return Temporal.Duration.from({months: Number.MAX_SAFE_INTEGER});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Any additional calls to dateUntil are incorrect.
|
|
||||||
throw new Test262Error("dateUntil called more times than expected");
|
|
||||||
}
|
|
||||||
}("iso8601");
|
|
||||||
|
|
||||||
let date = new Temporal.PlainDate(1970, 1, 1, calendar);
|
|
||||||
|
|
||||||
let duration = Temporal.Duration.from({
|
|
||||||
years: 0,
|
|
||||||
months: Number.MAX_SAFE_INTEGER + 4, // 9007199254740996
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = duration.round({
|
|
||||||
largestUnit: "years",
|
|
||||||
relativeTo: date,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Years is equal to the number of times we returned one month from dateUntil.
|
|
||||||
// Months is equal to 9007199254740996 - 6.
|
|
||||||
TemporalHelpers.assertDuration(
|
|
||||||
result,
|
|
||||||
6, 9007199254740990, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
0, 0, 0,
|
|
||||||
);
|
|
@ -11,13 +11,13 @@ includes: [temporalHelpers.js]
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(1);
|
const instance = new Temporal.Duration(0, 0, 0, 1);
|
||||||
const options = {
|
const options = {
|
||||||
smallestUnit: "years",
|
smallestUnit: "days",
|
||||||
roundingMode: "expand",
|
roundingMode: "expand",
|
||||||
relativeTo: new Temporal.PlainDate(2000, 1, 1),
|
relativeTo: new Temporal.PlainDate(2000, 1, 1),
|
||||||
};
|
};
|
||||||
const result = instance.round({ ...options, roundingIncrement: 2.5 });
|
const result = instance.round({ ...options, roundingIncrement: 2.5 });
|
||||||
TemporalHelpers.assertDuration(result, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
|
TemporalHelpers.assertDuration(result, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
|
||||||
const result2 = instance.round({ ...options, roundingIncrement: 1e9 + 0.5 });
|
const result2 = instance.round({ ...options, roundingIncrement: 1e9 + 0.5 });
|
||||||
TemporalHelpers.assertDuration(result2, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");
|
TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [6], [-5]],
|
["years", [6], [-5]],
|
||||||
["months", [5, 8], [-5, -7]],
|
["months", [5, 8], [-5, -7]],
|
||||||
["weeks", [5, 6, 9], [-5, -6, -8]],
|
["weeks", [5, 6, 9], [-5, -6, -8]],
|
||||||
["days", [5, 6, 7, 10], [-5, -6, -7, -9]],
|
["days", [5, 7, 0, 28], [-5, -7, 0, -27]],
|
||||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -16]],
|
["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -16]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 31], [-5, -6, -7, -9, -16, -30]],
|
["minutes", [5, 7, 0, 27, 16, 31], [-5, -7, 0, -27, -16, -30]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 21], [-5, -6, -7, -9, -16, -30, -20]],
|
["seconds", [5, 7, 0, 27, 16, 30, 21], [-5, -7, 0, -27, -16, -30, -20]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -123]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 124], [-5, -7, 0, -27, -16, -30, -20, -123]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 988], [-5, -6, -7, -9, -16, -30, -20, -123, -987]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 988], [-5, -7, 0, -27, -16, -30, -20, -123, -987]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "ceil";
|
const roundingMode = "ceil";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [6], [-6]],
|
["years", [6], [-6]],
|
||||||
["months", [5, 8], [-5, -8]],
|
["months", [5, 8], [-5, -8]],
|
||||||
["weeks", [5, 6, 9], [-5, -6, -9]],
|
["weeks", [5, 6, 9], [-5, -6, -9]],
|
||||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
["days", [5, 7, 0, 28], [-5, -7, 0, -28]],
|
||||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 31], [-5, -6, -7, -9, -16, -31]],
|
["minutes", [5, 7, 0, 27, 16, 31], [-5, -7, 0, -27, -16, -31]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 21], [-5, -6, -7, -9, -16, -30, -21]],
|
["seconds", [5, 7, 0, 27, 16, 30, 21], [-5, -7, 0, -27, -16, -30, -21]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 124], [-5, -7, 0, -27, -16, -30, -20, -124]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 988], [-5, -6, -7, -9, -16, -30, -20, -123, -988]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 988], [-5, -7, 0, -27, -16, -30, -20, -123, -988]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "expand";
|
const roundingMode = "expand";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [5], [-6]],
|
["years", [5], [-6]],
|
||||||
["months", [5, 7], [-5, -8]],
|
["months", [5, 7], [-5, -8]],
|
||||||
["weeks", [5, 6, 8], [-5, -6, -9]],
|
["weeks", [5, 6, 8], [-5, -6, -9]],
|
||||||
["days", [5, 6, 7, 9], [-5, -6, -7, -10]],
|
["days", [5, 7, 0, 27], [-5, -7, 0, -28]],
|
||||||
["hours", [5, 6, 7, 9, 16], [-5, -6, -7, -9, -17]],
|
["hours", [5, 7, 0, 27, 16], [-5, -7, 0, -27, -17]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -31]],
|
["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -31]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -21]],
|
["seconds", [5, 7, 0, 27, 16, 30, 20], [-5, -7, 0, -27, -16, -30, -21]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 123], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 123], [-5, -7, 0, -27, -16, -30, -20, -124]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -988]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987], [-5, -7, 0, -27, -16, -30, -20, -123, -988]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "floor";
|
const roundingMode = "floor";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [6], [-6]],
|
["years", [6], [-6]],
|
||||||
["months", [5, 8], [-5, -8]],
|
["months", [5, 8], [-5, -8]],
|
||||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
["days", [5, 7, 0, 28], [-5, -7, 0, -28]],
|
||||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
["seconds", [5, 7, 0, 27, 16, 30, 20], [-5, -7, 0, -27, -16, -30, -20]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 124], [-5, -7, 0, -27, -16, -30, -20, -124]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 988], [-5, -6, -7, -9, -16, -30, -20, -123, -987]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 988], [-5, -7, 0, -27, -16, -30, -20, -123, -987]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "halfCeil";
|
const roundingMode = "halfCeil";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [6], [-6]],
|
["years", [6], [-6]],
|
||||||
["months", [5, 8], [-5, -8]],
|
["months", [5, 8], [-5, -8]],
|
||||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
["days", [5, 7, 0, 28], [-5, -7, 0, -28]],
|
||||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
["seconds", [5, 7, 0, 27, 16, 30, 20], [-5, -7, 0, -27, -16, -30, -20]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 124], [-5, -7, 0, -27, -16, -30, -20, -124]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 988], [-5, -6, -7, -9, -16, -30, -20, -123, -988]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 988], [-5, -7, 0, -27, -16, -30, -20, -123, -988]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "halfEven";
|
const roundingMode = "halfEven";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [6], [-6]],
|
["years", [6], [-6]],
|
||||||
["months", [5, 8], [-5, -8]],
|
["months", [5, 8], [-5, -8]],
|
||||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
["days", [5, 7, 0, 28], [-5, -7, 0, -28]],
|
||||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
["seconds", [5, 7, 0, 27, 16, 30, 20], [-5, -7, 0, -27, -16, -30, -20]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 124], [-5, -7, 0, -27, -16, -30, -20, -124]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 988], [-5, -6, -7, -9, -16, -30, -20, -123, -988]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 988], [-5, -7, 0, -27, -16, -30, -20, -123, -988]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "halfExpand";
|
const roundingMode = "halfExpand";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [6], [-6]],
|
["years", [6], [-6]],
|
||||||
["months", [5, 8], [-5, -8]],
|
["months", [5, 8], [-5, -8]],
|
||||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
["days", [5, 7, 0, 28], [-5, -7, 0, -28]],
|
||||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
["seconds", [5, 7, 0, 27, 16, 30, 20], [-5, -7, 0, -27, -16, -30, -20]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 124], [-5, -7, 0, -27, -16, -30, -20, -124]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -988]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987], [-5, -7, 0, -27, -16, -30, -20, -123, -988]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "halfFloor";
|
const roundingMode = "halfFloor";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [6], [-6]],
|
["years", [6], [-6]],
|
||||||
["months", [5, 8], [-5, -8]],
|
["months", [5, 8], [-5, -8]],
|
||||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]],
|
["days", [5, 7, 0, 28], [-5, -7, 0, -28]],
|
||||||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]],
|
["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
["seconds", [5, 7, 0, 27, 16, 30, 20], [-5, -7, 0, -27, -16, -30, -20]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 124], [-5, -7, 0, -27, -16, -30, -20, -124]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -987]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987], [-5, -7, 0, -27, -16, -30, -20, -123, -987]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "halfTrunc";
|
const roundingMode = "halfTrunc";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -9,19 +9,23 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 987, 500);
|
||||||
const relativeTo = new Temporal.PlainDate(2020, 1, 1);
|
// Chosen such that 8 months forwards from relativeToForwards is the
|
||||||
|
// same number of days as 8 months backwards from relativeToBackwards
|
||||||
|
// (for convenience)
|
||||||
|
const relativeToForwards = new Temporal.PlainDate(2020, 4, 1);
|
||||||
|
const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
["years", [5], [-5]],
|
["years", [5], [-5]],
|
||||||
["months", [5, 7], [-5, -7]],
|
["months", [5, 7], [-5, -7]],
|
||||||
["weeks", [5, 6, 8], [-5, -6, -8]],
|
["weeks", [5, 6, 8], [-5, -6, -8]],
|
||||||
["days", [5, 6, 7, 9], [-5, -6, -7, -9]],
|
["days", [5, 7, 0, 27], [-5, -7, 0, -27]],
|
||||||
["hours", [5, 6, 7, 9, 16], [-5, -6, -7, -9, -16]],
|
["hours", [5, 7, 0, 27, 16], [-5, -7, 0, -27, -16]],
|
||||||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]],
|
["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]],
|
||||||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]],
|
["seconds", [5, 7, 0, 27, 16, 30, 20], [-5, -7, 0, -27, -16, -30, -20]],
|
||||||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 123], [-5, -6, -7, -9, -16, -30, -20, -123]],
|
["milliseconds", [5, 7, 0, 27, 16, 30, 20, 123], [-5, -7, 0, -27, -16, -30, -20, -123]],
|
||||||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -987]],
|
["microseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987], [-5, -7, 0, -27, -16, -30, -20, -123, -987]],
|
||||||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 987, 500], [-5, -6, -7, -9, -16, -30, -20, -123, -987, -500]],
|
["nanoseconds", [5, 7, 0, 27, 16, 30, 20, 123, 987, 500], [-5, -7, 0, -27, -16, -30, -20, -123, -987, -500]],
|
||||||
];
|
];
|
||||||
|
|
||||||
const roundingMode = "trunc";
|
const roundingMode = "trunc";
|
||||||
@ -30,12 +34,12 @@ expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => {
|
|||||||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive;
|
||||||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative;
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.round({ smallestUnit, relativeTo, roundingMode }),
|
instance.round({ smallestUnit, relativeTo: relativeToForwards, roundingMode }),
|
||||||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns,
|
||||||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)`
|
||||||
);
|
);
|
||||||
TemporalHelpers.assertDuration(
|
TemporalHelpers.assertDuration(
|
||||||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }),
|
instance.negated().round({ smallestUnit, relativeTo: relativeToBackwards, roundingMode }),
|
||||||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns,
|
||||||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)`
|
||||||
);
|
);
|
||||||
|
@ -15,9 +15,11 @@ var duration = Temporal.Duration.from({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var cal = new class extends Temporal.Calendar {
|
var cal = new class extends Temporal.Calendar {
|
||||||
|
called = 0;
|
||||||
dateUntil(one, two, options) {
|
dateUntil(one, two, options) {
|
||||||
|
++this.called;
|
||||||
var result = super.dateUntil(one, two, options);
|
var result = super.dateUntil(one, two, options);
|
||||||
return result.negated();
|
return this.called === 1 ? result.negated() : result;
|
||||||
}
|
}
|
||||||
}("iso8601");
|
}("iso8601");
|
||||||
|
|
||||||
|
@ -138,11 +138,9 @@ const expectedOpsForYearRounding = expected.concat([
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -167,11 +165,9 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 7.g
|
"call this.calendar.dateAdd", // 7.g
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.o not called because months and weeks == 0)
|
// (7.o not called because months and weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.since(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
instance.since(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
||||||
@ -189,8 +185,9 @@ const expectedOpsForMonthRounding = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
|
"call this.calendar.dateUntil" // 10.e
|
||||||
]);
|
]);
|
||||||
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
||||||
@ -206,8 +203,9 @@ const expectedOpsForWeekRounding = expected.concat([
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
||||||
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 16
|
||||||
|
"call this.calendar.dateUntil" // 17
|
||||||
]);
|
]);
|
||||||
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
||||||
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
||||||
|
@ -139,11 +139,9 @@ const expectedOpsForYearRounding = expected.concat([
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -168,11 +166,9 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 7.g
|
"call this.calendar.dateAdd", // 7.g
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.o not called because months and weeks == 0)
|
// (7.o not called because months and weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
||||||
@ -190,8 +186,9 @@ const expectedOpsForMonthRounding = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
|
"call this.calendar.dateUntil" // 10.e
|
||||||
]);
|
]);
|
||||||
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
||||||
@ -207,8 +204,9 @@ const expectedOpsForWeekRounding = expected.concat([
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
||||||
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 16
|
||||||
|
"call this.calendar.dateUntil" // 17
|
||||||
]);
|
]);
|
||||||
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
||||||
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
||||||
|
@ -168,11 +168,9 @@ const expectedOpsForYearRounding = expected.concat([
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -203,11 +201,9 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 7.g
|
"call this.calendar.dateAdd", // 7.g
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.o not called because months and weeks == 0)
|
// (7.o not called because months and weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
||||||
@ -225,8 +221,9 @@ const expectedOpsForMonthRounding = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
|
"call this.calendar.dateUntil", // 10.e
|
||||||
]);
|
]);
|
||||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
||||||
@ -242,8 +239,9 @@ const expectedOpsForWeekRounding = expected.concat([
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
||||||
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 16
|
||||||
|
"call this.calendar.dateUntil", // 17
|
||||||
]);
|
]);
|
||||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
||||||
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
||||||
|
@ -168,11 +168,9 @@ const expectedOpsForYearRounding = expected.concat([
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -203,11 +201,9 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 7.g
|
"call this.calendar.dateAdd", // 7.g
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.o not called because months and weeks == 0)
|
// (7.o not called because months and weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
|
||||||
@ -225,8 +221,9 @@ const expectedOpsForMonthRounding = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
|
"call this.calendar.dateUntil" // 10.e
|
||||||
]);
|
]);
|
||||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = years");
|
||||||
@ -242,8 +239,9 @@ const expectedOpsForWeekRounding = expected.concat([
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
||||||
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 16
|
||||||
|
"call this.calendar.dateUntil" // 17
|
||||||
]);
|
]);
|
||||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
||||||
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
||||||
|
@ -146,11 +146,9 @@ const expectedOpsForYearRounding = expected.concat([
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -168,11 +166,9 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 7.g
|
"call this.calendar.dateAdd", // 7.g
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.o not called because months and weeks == 0)
|
// (7.o not called because months and weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.since(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
instance.since(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months");
|
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months");
|
||||||
@ -185,11 +181,9 @@ const expectedOpsForMonthRounding = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 10.e
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 }));
|
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
||||||
|
@ -20,5 +20,6 @@ const earlier = new Temporal.PlainYearMonth(2000, 5);
|
|||||||
const later = new Temporal.PlainYearMonth(2000, 10);
|
const later = new Temporal.PlainYearMonth(2000, 10);
|
||||||
const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" });
|
const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" });
|
||||||
TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
|
TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
|
||||||
const result2 = later.since(earlier, { largestUnit: "months", smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
|
// Cannot test the upper bound of 1e9 + 0.5 here, because the duration is
|
||||||
TemporalHelpers.assertDuration(result2, 0, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");
|
// rounded relative to the receiver PlainYearMonth, and 1e9 months is outside of
|
||||||
|
// the PlainYearMonth range.
|
||||||
|
@ -146,11 +146,9 @@ const expectedOpsForYearRounding = expected.concat([
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -168,11 +166,9 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 7.g
|
"call this.calendar.dateAdd", // 7.g
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.o not called because months and weeks == 0)
|
// (7.o not called because months and weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months");
|
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months");
|
||||||
@ -185,11 +181,9 @@ const expectedOpsForMonthRounding = expected.concat([
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 10.e
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 }));
|
instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
||||||
|
@ -20,5 +20,6 @@ const earlier = new Temporal.PlainYearMonth(2000, 5);
|
|||||||
const later = new Temporal.PlainYearMonth(2000, 10);
|
const later = new Temporal.PlainYearMonth(2000, 10);
|
||||||
const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" });
|
const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" });
|
||||||
TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
|
TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
|
||||||
const result2 = earlier.until(later, { largestUnit: "months", smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
|
// Cannot test the upper bound of 1e9 + 0.5 here, because the duration is
|
||||||
TemporalHelpers.assertDuration(result2, 0, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");
|
// rounded relative to the receiver PlainYearMonth, and 1e9 months is outside of
|
||||||
|
// the PlainYearMonth range.
|
||||||
|
@ -77,9 +77,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
later.since(earlier, { largestUnit, roundingIncrement: 2, roundingMode: 'ceil' });
|
later.since(earlier, { largestUnit, roundingIncrement: 2, roundingMode: 'ceil' });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
years: ["year", "year", "month"],
|
years: ["year", "year", "year"],
|
||||||
months: ["month", "month"],
|
months: ["month", "month", "month"],
|
||||||
weeks: ["week", "week"],
|
weeks: ["week", "week", "week"],
|
||||||
days: [],
|
days: [],
|
||||||
hours: [],
|
hours: [],
|
||||||
minutes: [],
|
minutes: [],
|
||||||
@ -100,9 +100,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
later.since(earlier, { smallestUnit });
|
later.since(earlier, { smallestUnit });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
years: ["year", "year", "month"],
|
years: ["year", "year", "year"],
|
||||||
months: ["month"],
|
months: ["month", "month"],
|
||||||
weeks: ["week"],
|
weeks: ["week", "week"],
|
||||||
days: [],
|
days: [],
|
||||||
hours: [],
|
hours: [],
|
||||||
minutes: [],
|
minutes: [],
|
||||||
|
@ -364,11 +364,9 @@ const expectedOpsForYearRounding = expected.concat(expectedOpsForCalendarDiffere
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -381,8 +379,9 @@ const expectedOpsForMonthRounding = expected.concat(expectedOpsForCalendarDiffer
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
|
"call this.calendar.dateUntil", // 10.e
|
||||||
]);
|
]);
|
||||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
||||||
@ -393,8 +392,9 @@ const expectedOpsForWeekRounding = expected.concat(expectedOpsForCalendarDiffere
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
||||||
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 16
|
||||||
|
"call this.calendar.dateUntil", // 17
|
||||||
]);
|
]);
|
||||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
||||||
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
||||||
|
@ -77,9 +77,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
earlier.until(later, { largestUnit, roundingIncrement: 2, roundingMode: 'ceil' });
|
earlier.until(later, { largestUnit, roundingIncrement: 2, roundingMode: 'ceil' });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
years: ["year", "year", "month"],
|
years: ["year", "year", "year"],
|
||||||
months: ["month", "month"],
|
months: ["month", "month", "month"],
|
||||||
weeks: ["week", "week"],
|
weeks: ["week", "week", "week"],
|
||||||
days: [],
|
days: [],
|
||||||
hours: [],
|
hours: [],
|
||||||
minutes: [],
|
minutes: [],
|
||||||
@ -100,9 +100,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
earlier.until(later, { smallestUnit });
|
earlier.until(later, { smallestUnit });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
years: ["year", "year", "month"],
|
years: ["year", "year", "year"],
|
||||||
months: ["month"],
|
months: ["month", "month"],
|
||||||
weeks: ["week"],
|
weeks: ["week", "week"],
|
||||||
days: [],
|
days: [],
|
||||||
hours: [],
|
hours: [],
|
||||||
minutes: [],
|
minutes: [],
|
||||||
|
@ -364,11 +364,9 @@ const expectedOpsForYearRounding = expected.concat(expectedOpsForCalendarDiffere
|
|||||||
"call this.calendar.dateUntil", // 7.o
|
"call this.calendar.dateUntil", // 7.o
|
||||||
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
|
||||||
// (7.s not called because other units can't add up to >1 year at this point)
|
// (7.s not called because other units can't add up to >1 year at this point)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 9.c
|
||||||
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
|
"call this.calendar.dateUntil" // 9.d
|
||||||
"call this.calendar.dateAdd", // 11.k
|
|
||||||
"call this.calendar.dateUntil" // 11.n
|
|
||||||
]);
|
]);
|
||||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||||
@ -381,8 +379,9 @@ const expectedOpsForMonthRounding = expected.concat(expectedOpsForCalendarDiffer
|
|||||||
"call this.calendar.dateAdd", // 10.e
|
"call this.calendar.dateAdd", // 10.e
|
||||||
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
|
||||||
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
// (10.n.iii MoveRelativeDate not called because weeks == 0)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
|
"call this.calendar.dateAdd", // 10.d
|
||||||
|
"call this.calendar.dateUntil", // 10.e
|
||||||
]);
|
]);
|
||||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
|
||||||
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
|
||||||
@ -393,8 +392,9 @@ const expectedOpsForWeekRounding = expected.concat(expectedOpsForCalendarDiffere
|
|||||||
// RoundDuration
|
// RoundDuration
|
||||||
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
|
||||||
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
// (11.g.iii MoveRelativeDate not called because days already balanced)
|
||||||
// BalanceDurationRelative
|
// BalanceDateDurationRelative
|
||||||
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
|
"call this.calendar.dateAdd", // 16
|
||||||
|
"call this.calendar.dateUntil", // 17
|
||||||
]);
|
]);
|
||||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
|
||||||
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
|
||||||
|
@ -208,7 +208,7 @@ assert.sameValue(`${ hours25.round({
|
|||||||
assert.sameValue(`${ d.round({
|
assert.sameValue(`${ d.round({
|
||||||
smallestUnit: "seconds",
|
smallestUnit: "seconds",
|
||||||
relativeTo
|
relativeTo
|
||||||
}) }`, "P5Y5M5W5DT5H5M5S");
|
}) }`, "P5Y6M10DT5H5M5S");
|
||||||
});
|
});
|
||||||
|
|
||||||
// does not accept non-string primitives for relativeTo
|
// does not accept non-string primitives for relativeTo
|
||||||
@ -325,24 +325,24 @@ var roundAndBalanceResults = {
|
|||||||
years: "P6Y",
|
years: "P6Y",
|
||||||
months: "P5Y6M",
|
months: "P5Y6M",
|
||||||
weeks: "P5Y5M6W",
|
weeks: "P5Y5M6W",
|
||||||
days: "P5Y5M5W5D",
|
days: "P5Y6M10D",
|
||||||
hours: "P5Y5M5W5DT5H",
|
hours: "P5Y6M10DT5H",
|
||||||
minutes: "P5Y5M5W5DT5H5M",
|
minutes: "P5Y6M10DT5H5M",
|
||||||
seconds: "P5Y5M5W5DT5H5M5S",
|
seconds: "P5Y6M10DT5H5M5S",
|
||||||
milliseconds: "P5Y5M5W5DT5H5M5.005S",
|
milliseconds: "P5Y6M10DT5H5M5.005S",
|
||||||
microseconds: "P5Y5M5W5DT5H5M5.005005S",
|
microseconds: "P5Y6M10DT5H5M5.005005S",
|
||||||
nanoseconds: "P5Y5M5W5DT5H5M5.005005005S"
|
nanoseconds: "P5Y6M10DT5H5M5.005005005S"
|
||||||
},
|
},
|
||||||
months: {
|
months: {
|
||||||
months: "P66M",
|
months: "P66M",
|
||||||
weeks: "P65M6W",
|
weeks: "P65M6W",
|
||||||
days: "P65M5W5D",
|
days: "P66M10D",
|
||||||
hours: "P65M5W5DT5H",
|
hours: "P66M10DT5H",
|
||||||
minutes: "P65M5W5DT5H5M",
|
minutes: "P66M10DT5H5M",
|
||||||
seconds: "P65M5W5DT5H5M5S",
|
seconds: "P66M10DT5H5M5S",
|
||||||
milliseconds: "P65M5W5DT5H5M5.005S",
|
milliseconds: "P66M10DT5H5M5.005S",
|
||||||
microseconds: "P65M5W5DT5H5M5.005005S",
|
microseconds: "P66M10DT5H5M5.005005S",
|
||||||
nanoseconds: "P65M5W5DT5H5M5.005005005S"
|
nanoseconds: "P66M10DT5H5M5.005005005S"
|
||||||
},
|
},
|
||||||
weeks: {
|
weeks: {
|
||||||
weeks: "P288W",
|
weeks: "P288W",
|
||||||
@ -521,42 +521,42 @@ assert.sameValue(`${ d.round({
|
|||||||
smallestUnit: "hours",
|
smallestUnit: "hours",
|
||||||
roundingIncrement: 3,
|
roundingIncrement: 3,
|
||||||
relativeTo
|
relativeTo
|
||||||
}) }`, "P5Y5M5W5DT6H");
|
}) }`, "P5Y6M10DT6H");
|
||||||
|
|
||||||
// rounds to an increment of minutes
|
// rounds to an increment of minutes
|
||||||
assert.sameValue(`${ d.round({
|
assert.sameValue(`${ d.round({
|
||||||
smallestUnit: "minutes",
|
smallestUnit: "minutes",
|
||||||
roundingIncrement: 30,
|
roundingIncrement: 30,
|
||||||
relativeTo
|
relativeTo
|
||||||
}) }`, "P5Y5M5W5DT5H");
|
}) }`, "P5Y6M10DT5H");
|
||||||
|
|
||||||
// rounds to an increment of seconds
|
// rounds to an increment of seconds
|
||||||
assert.sameValue(`${ d.round({
|
assert.sameValue(`${ d.round({
|
||||||
smallestUnit: "seconds",
|
smallestUnit: "seconds",
|
||||||
roundingIncrement: 15,
|
roundingIncrement: 15,
|
||||||
relativeTo
|
relativeTo
|
||||||
}) }`, "P5Y5M5W5DT5H5M");
|
}) }`, "P5Y6M10DT5H5M");
|
||||||
|
|
||||||
// rounds to an increment of milliseconds
|
// rounds to an increment of milliseconds
|
||||||
assert.sameValue(`${ d.round({
|
assert.sameValue(`${ d.round({
|
||||||
smallestUnit: "milliseconds",
|
smallestUnit: "milliseconds",
|
||||||
roundingIncrement: 10,
|
roundingIncrement: 10,
|
||||||
relativeTo
|
relativeTo
|
||||||
}) }`, "P5Y5M5W5DT5H5M5.01S");
|
}) }`, "P5Y6M10DT5H5M5.01S");
|
||||||
|
|
||||||
// rounds to an increment of microseconds
|
// rounds to an increment of microseconds
|
||||||
assert.sameValue(`${ d.round({
|
assert.sameValue(`${ d.round({
|
||||||
smallestUnit: "microseconds",
|
smallestUnit: "microseconds",
|
||||||
roundingIncrement: 10,
|
roundingIncrement: 10,
|
||||||
relativeTo
|
relativeTo
|
||||||
}) }`, "P5Y5M5W5DT5H5M5.00501S");
|
}) }`, "P5Y6M10DT5H5M5.00501S");
|
||||||
|
|
||||||
// rounds to an increment of nanoseconds
|
// rounds to an increment of nanoseconds
|
||||||
assert.sameValue(`${ d.round({
|
assert.sameValue(`${ d.round({
|
||||||
smallestUnit: "nanoseconds",
|
smallestUnit: "nanoseconds",
|
||||||
roundingIncrement: 10,
|
roundingIncrement: 10,
|
||||||
relativeTo
|
relativeTo
|
||||||
}) }`, "P5Y5M5W5DT5H5M5.00500501S");
|
}) }`, "P5Y6M10DT5H5M5.00500501S");
|
||||||
|
|
||||||
// valid hour increments divide into 24
|
// valid hour increments divide into 24
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user