Port tests for PlainTime.

This commit is contained in:
Ms2ger 2022-02-16 15:57:55 +01:00 committed by Rick Waldron
parent 1fe9bd3951
commit 18ce639a4c
32 changed files with 1002 additions and 84 deletions

View File

@ -0,0 +1,23 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.round
description: Tests roundingIncrement restrictions.
features: [Temporal]
---*/
const plainTime = Temporal.PlainTime.from("08:22:36.123456789");
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "hours", roundingIncrement: 11 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "minutes", roundingIncrement: 29 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "seconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "nanoseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "hours", roundingIncrement: 24 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "minutes", roundingIncrement: 60 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "seconds", roundingIncrement: 60 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "milliseconds", roundingIncrement: 1000 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "microseconds", roundingIncrement: 1000 }));
assert.throws(RangeError, () => plainTime.round({ smallestUnit: "nanoseconds", roundingIncrement: 1000 }));

View File

@ -0,0 +1,36 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.round
description: Tests calculations with roundingMode "ceil".
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const plainTime = Temporal.PlainTime.from("13:46:23.123456789");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hour", roundingMode: "ceil" }),
14, 0, 0, 0, 0, 0, "hour");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "minute", roundingMode: "ceil" }),
13, 47, 0, 0, 0, 0, "minute");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "second", roundingMode: "ceil" }),
13, 46, 24, 0, 0, 0, "second");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "millisecond", roundingMode: "ceil" }),
13, 46, 23, 124, 0, 0, "millisecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microsecond", roundingMode: "ceil" }),
13, 46, 23, 123, 457, 0, "microsecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "nanosecond", roundingMode: "ceil" }),
13, 46, 23, 123, 456, 789, "nanosecond");

View File

@ -0,0 +1,35 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.round
description: Tests calculations with roundingMode "floor".
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const plainTime = Temporal.PlainTime.from("13:46:23.123456789");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hour", roundingMode: "floor" }),
13, 0, 0, 0, 0, 0, "hour");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "minute", roundingMode: "floor" }),
13, 46, 0, 0, 0, 0, "minute");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "second", roundingMode: "floor" }),
13, 46, 23, 0, 0, 0, "second");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "millisecond", roundingMode: "floor" }),
13, 46, 23, 123, 0, 0, "millisecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microsecond", roundingMode: "floor" }),
13, 46, 23, 123, 456, 0, "microsecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "nanosecond", roundingMode: "floor" }),
13, 46, 23, 123, 456, 789, "nanosecond");

View File

@ -0,0 +1,35 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.round
description: Tests calculations with roundingMode "floor".
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const plainTime = Temporal.PlainTime.from("13:46:23.123456789");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hour", roundingMode: "halfExpand" }),
14, 0, 0, 0, 0, 0, "hour");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "minute", roundingMode: "halfExpand" }),
13, 46, 0, 0, 0, 0, "minute");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "second", roundingMode: "halfExpand" }),
13, 46, 23, 0, 0, 0, "second");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "millisecond", roundingMode: "halfExpand" }),
13, 46, 23, 123, 0, 0, "millisecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microsecond", roundingMode: "halfExpand" }),
13, 46, 23, 123, 457, 0, "microsecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "nanosecond", roundingMode: "halfExpand" }),
13, 46, 23, 123, 456, 789, "nanosecond");

View File

@ -0,0 +1,35 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.round
description: Tests calculations with roundingMode "trunc".
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const plainTime = Temporal.PlainTime.from("13:46:23.123456789");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hour", roundingMode: "trunc" }),
13, 0, 0, 0, 0, 0, "hour");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "minute", roundingMode: "trunc" }),
13, 46, 0, 0, 0, 0, "minute");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "second", roundingMode: "trunc" }),
13, 46, 23, 0, 0, 0, "second");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "millisecond", roundingMode: "trunc" }),
13, 46, 23, 123, 0, 0, "millisecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microsecond", roundingMode: "trunc" }),
13, 46, 23, 123, 456, 0, "microsecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "nanosecond", roundingMode: "trunc" }),
13, 46, 23, 123, 456, 789, "nanosecond");

View File

@ -1,26 +1,53 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.round
description: Fallback value for roundingMode option
includes: [temporalHelpers.js]
description: Tests calculations with roundingMode undefined.
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
const plainTime = Temporal.PlainTime.from("13:46:23.123456789");
const explicit1 = time.round({ smallestUnit: "microsecond", roundingMode: undefined });
TemporalHelpers.assertPlainTime(explicit1, 12, 34, 56, 123, 988, 0, "default roundingMode is halfExpand");
const implicit1 = time.round({ smallestUnit: "microsecond" });
TemporalHelpers.assertPlainTime(implicit1, 12, 34, 56, 123, 988, 0, "default roundingMode is halfExpand");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hour", roundingMode: undefined }),
14, 0, 0, 0, 0, 0, "hour");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "hour" }),
14, 0, 0, 0, 0, 0, "hour");
const explicit2 = time.round({ smallestUnit: "millisecond", roundingMode: undefined });
TemporalHelpers.assertPlainTime(explicit2, 12, 34, 56, 124, 0, 0, "default roundingMode is halfExpand");
const implicit2 = time.round({ smallestUnit: "millisecond" });
TemporalHelpers.assertPlainTime(implicit2, 12, 34, 56, 124, 0, 0, "default roundingMode is halfExpand");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "minute", roundingMode: undefined }),
13, 46, 0, 0, 0, 0, "minute");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "minute" }),
13, 46, 0, 0, 0, 0, "minute");
const explicit3 = time.round({ smallestUnit: "second", roundingMode: undefined });
TemporalHelpers.assertPlainTime(explicit3, 12, 34, 56, 0, 0, 0, "default roundingMode is halfExpand");
const implicit3 = time.round({ smallestUnit: "second" });
TemporalHelpers.assertPlainTime(implicit3, 12, 34, 56, 0, 0, 0, "default roundingMode is halfExpand");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "second", roundingMode: undefined }),
13, 46, 23, 0, 0, 0, "second");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "second" }),
13, 46, 23, 0, 0, 0, "second");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "millisecond", roundingMode: undefined }),
13, 46, 23, 123, 0, 0, "millisecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "millisecond" }),
13, 46, 23, 123, 0, 0, "millisecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microsecond", roundingMode: undefined }),
13, 46, 23, 123, 457, 0, "microsecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "microsecond" }),
13, 46, 23, 123, 457, 0, "microsecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "nanosecond", roundingMode: undefined }),
13, 46, 23, 123, 456, 789, "nanosecond");
TemporalHelpers.assertPlainTime(
plainTime.round({ smallestUnit: "nanosecond" }),
13, 46, 23, 123, 456, 789, "nanosecond");

View File

@ -8,4 +8,7 @@ features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
assert.throws(RangeError, () => time.round({ smallestUnit: "other string" }));
const values = ["era", "year", "month", "week", "day", "years", "months", "weeks", "days", "nonsense", "other string"];
for (const smallestUnit of values) {
assert.throws(RangeError, () => time.round({ smallestUnit }));
}

View File

@ -0,0 +1,13 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.round
description: RangeError thrown when smallestUnit option is missing
features: [Temporal]
---*/
const plainTime = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
assert.throws(TypeError, () => plainTime.round());
assert.throws(RangeError, () => plainTime.round({}));
assert.throws(RangeError, () => plainTime.round({ roundingIncrement: 1, roundingMode: "ceil" }));

View File

@ -0,0 +1,18 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Casts the argument
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const plainTime = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
TemporalHelpers.assertDuration(plainTime.since("16:34"),
0, 0, 0, 0, /* hours = */ -1, /* minutes = */ -10, /* seconds = */ -29, -876, -543, -211, "string");
TemporalHelpers.assertDuration(plainTime.since({ hour: 16, minute: 34 }),
0, 0, 0, 0, /* hours = */ -1, /* minutes = */ -10, /* seconds = */ -29, -876, -543, -211, "object");
assert.throws(TypeError, () => plainTime.since({}), "empty");
assert.throws(TypeError, () => plainTime.since({ minutes: 30 }), "only plural 'minutes'");

View File

@ -0,0 +1,22 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Basic usage
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const one = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
const two = new Temporal.PlainTime(14, 23, 30, 123, 456, 789);
const three = new Temporal.PlainTime(13, 30, 30, 123, 456, 789);
TemporalHelpers.assertDuration(one.since(two),
0, 0, 0, 0, /* hours = */ 1, 0, 0, 0, 0, 0);
TemporalHelpers.assertDuration(two.since(one),
0, 0, 0, 0, /* hours = */ -1, 0, 0, 0, 0, 0);
TemporalHelpers.assertDuration(one.since(three),
0, 0, 0, 0, /* hours = */ 1, 53, 0, 0, 0, 0);
TemporalHelpers.assertDuration(three.since(one),
0, 0, 0, 0, /* hours = */ -1, -53, 0, 0, 0, 0);

View File

@ -3,13 +3,14 @@
/*---
esid: sec-temporal.plaintime.prototype.since
description: Specify behavior of PlainTime.since when largest specified unit is years or months.
description: PlainTime.since with various largestUnit values.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const fourFortyEight = new Temporal.PlainTime(4, 48, 55);
const elevenFiftyNine = new Temporal.PlainTime(11, 59, 58);
TemporalHelpers.assertDuration(elevenFiftyNine.since(fourFortyEight), 0, 0, 0, 0, 7, 11, 3, 0, 0, 0, 'does not include higher units than necessary (largest unit unspecified)');
TemporalHelpers.assertDuration(elevenFiftyNine.since(fourFortyEight, { largestUnit: 'auto' }), 0, 0, 0, 0, 7, 11, 3, 0, 0, 0, 'does not include higher units than necessary (largest unit is auto)');
TemporalHelpers.assertDuration(elevenFiftyNine.since(fourFortyEight, { largestUnit: 'hours' }), 0, 0, 0, 0, 7, 11, 3, 0, 0, 0, 'does not include higher units than necessary (largest unit is hours)');
TemporalHelpers.assertDuration(elevenFiftyNine.since(fourFortyEight, { largestUnit: 'minutes' }), 0, 0, 0, 0, 0, 431, 3, 0, 0, 0, 'does not include higher units than necessary (largest unit is minutes)');
TemporalHelpers.assertDuration(elevenFiftyNine.since(fourFortyEight, { largestUnit: 'seconds' }), 0, 0, 0, 0, 0, 0, 25863, 0, 0, 0, 'does not include higher units than necessary (largest unit is seconds)');

View File

@ -1,18 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Missing time units in property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.PlainTime(1, 0, 0, 0, 0, 1);
const props = {};
assert.throws(TypeError, () => instance.since(props), "TypeError if at least one property is not present");
props.minute = 30;
const result = instance.since(props);
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 30, 0, 0, 0, 1, "missing time units default to 0");

View File

@ -0,0 +1,21 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Supports sub-second precision
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const time1 = Temporal.PlainTime.from("10:23:15");
const time2 = Temporal.PlainTime.from("17:15:57.250250250");
TemporalHelpers.assertDuration(time2.since(time1, { largestUnit: "milliseconds" }),
0, 0, 0, 0, 0, 0, 0, /* milliseconds = */ 24762250, 250, 250, "milliseconds");
TemporalHelpers.assertDuration(time2.since(time1, { largestUnit: "microseconds" }),
0, 0, 0, 0, 0, 0, 0, /* milliseconds = */ 0, 24762250250, 250, "microseconds");
TemporalHelpers.assertDuration(time2.since(time1, { largestUnit: "nanoseconds" }),
0, 0, 0, 0, 0, 0, 0, /* milliseconds = */ 0, 0, 24762250250250, "nanoseconds");

View File

@ -0,0 +1,24 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Tests roundingIncrement restrictions.
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "hours", roundingIncrement: 11 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "minutes", roundingIncrement: 29 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "seconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "milliseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "microseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "nanoseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "hours", roundingIncrement: 24 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "minutes", roundingIncrement: 60 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "seconds", roundingIncrement: 60 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "milliseconds", roundingIncrement: 1000 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "microseconds", roundingIncrement: 1000 }));
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "nanoseconds", roundingIncrement: 1000 }));

View File

@ -0,0 +1,54 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Tests calculations with roundingMode "ceil".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "hours", roundingMode: "ceil" }),
0, 0, 0, 0, 5, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "hours", roundingMode: "ceil" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "minutes", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 18, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "minutes", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "seconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "seconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 4, 865, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -0,0 +1,55 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Tests calculations with roundingMode "floor".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "hours", roundingMode: "floor" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "hours", roundingMode: "floor" }),
0, 0, 0, 0, -5, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "minutes", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "minutes", roundingMode: "floor" }),
0, 0, 0, 0, -4, -18, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "seconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "seconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -4, -865, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -0,0 +1,54 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Tests calculations with roundingMode "halfExpand".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "hours", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "hours", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -10,6 +10,6 @@ features: [Temporal]
const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0);
const later = new Temporal.PlainTime(13, 35, 57, 123, 987, 500);
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l"]) {
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l", "auto"]) {
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "microsecond", roundingMode }));
}

View File

@ -0,0 +1,54 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.since
description: Tests calculations with roundingMode "trunc".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "hours", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "hours", roundingMode: "trunc" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "minutes", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "minutes", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "seconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "seconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "microseconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "microseconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -8,20 +8,83 @@ includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0);
const later = new Temporal.PlainTime(13, 35, 57, 123, 987, 500);
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
const explicit1 = later.since(earlier, { smallestUnit: "microsecond", roundingMode: undefined });
TemporalHelpers.assertDuration(explicit1, 0, 0, 0, 0, 1, 1, 1, 123, 987, 0, "default roundingMode is trunc");
const implicit1 = later.since(earlier, { smallestUnit: "microsecond" });
TemporalHelpers.assertDuration(implicit1, 0, 0, 0, 0, 1, 1, 1, 123, 987, 0, "default roundingMode is trunc");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "hours", roundingMode: undefined }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "hours" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "hours", roundingMode: undefined }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "hours" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
const explicit2 = later.since(earlier, { smallestUnit: "millisecond", roundingMode: undefined });
TemporalHelpers.assertDuration(explicit2, 0, 0, 0, 0, 1, 1, 1, 123, 0, 0, "default roundingMode is trunc");
const implicit2 = later.since(earlier, { smallestUnit: "millisecond" });
TemporalHelpers.assertDuration(implicit2, 0, 0, 0, 0, 1, 1, 1, 123, 0, 0, "default roundingMode is trunc");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "minutes", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "minutes" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "minutes", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "minutes" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
const explicit3 = later.since(earlier, { smallestUnit: "second", roundingMode: undefined });
TemporalHelpers.assertDuration(explicit3, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, "default roundingMode is trunc");
const implicit3 = later.since(earlier, { smallestUnit: "second" });
TemporalHelpers.assertDuration(implicit3, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, "default roundingMode is trunc");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "seconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "seconds" }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "seconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "seconds" }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "milliseconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "milliseconds" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "milliseconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "milliseconds" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "microseconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "microseconds" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "microseconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "microseconds" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
later.since(earlier, { smallestUnit: "nanoseconds" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
TemporalHelpers.assertDuration(
earlier.since(later, { smallestUnit: "nanoseconds" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -0,0 +1,18 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Casts the argument
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const plainTime = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
TemporalHelpers.assertDuration(plainTime.until("16:34"),
0, 0, 0, 0, /* hours = */ 1, /* minutes = */ 10, /* seconds = */ 29, 876, 543, 211, "string");
TemporalHelpers.assertDuration(plainTime.until({ hour: 16, minute: 34 }),
0, 0, 0, 0, /* hours = */ 1, /* minutes = */ 10, /* seconds = */ 29, 876, 543, 211, "object");
assert.throws(TypeError, () => plainTime.until({}), "empty");
assert.throws(TypeError, () => plainTime.until({ minutes: 30 }), "only plural 'minutes'");

View File

@ -0,0 +1,22 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Basic usage
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const one = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
const two = new Temporal.PlainTime(16, 23, 30, 123, 456, 789);
const three = new Temporal.PlainTime(17, 0, 30, 123, 456, 789);
TemporalHelpers.assertDuration(one.until(two),
0, 0, 0, 0, /* hours = */ 1, 0, 0, 0, 0, 0);
TemporalHelpers.assertDuration(two.until(one),
0, 0, 0, 0, /* hours = */ -1, 0, 0, 0, 0, 0);
TemporalHelpers.assertDuration(one.until(three),
0, 0, 0, 0, /* hours = */ 1, 37, 0, 0, 0, 0);
TemporalHelpers.assertDuration(three.until(one),
0, 0, 0, 0, /* hours = */ -1, -37, 0, 0, 0, 0);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: PlainTime.until with various largestUnit values.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const fourFortyEight = new Temporal.PlainTime(4, 48, 55);
const elevenFiftyNine = new Temporal.PlainTime(11, 59, 58);
TemporalHelpers.assertDuration(fourFortyEight.until(elevenFiftyNine), 0, 0, 0, 0, 7, 11, 3, 0, 0, 0, "does not include higher units than necessary (largest unit unspecified)");
TemporalHelpers.assertDuration(fourFortyEight.until(elevenFiftyNine, { largestUnit: "auto" }), 0, 0, 0, 0, 7, 11, 3, 0, 0, 0, "does not include higher units than necessary (largest unit is auto)");
TemporalHelpers.assertDuration(fourFortyEight.until(elevenFiftyNine, { largestUnit: "hours" }), 0, 0, 0, 0, 7, 11, 3, 0, 0, 0, "does not include higher units than necessary (largest unit is hours)");
TemporalHelpers.assertDuration(fourFortyEight.until(elevenFiftyNine, { largestUnit: "minutes" }), 0, 0, 0, 0, 0, 431, 3, 0, 0, 0, "does not include higher units than necessary (largest unit is minutes)");
TemporalHelpers.assertDuration(fourFortyEight.until(elevenFiftyNine, { largestUnit: "seconds" }), 0, 0, 0, 0, 0, 0, 25863, 0, 0, 0, "does not include higher units than necessary (largest unit is seconds)");

View File

@ -1,18 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Missing time units in property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.PlainTime(1, 0, 0, 0, 0, 1);
const props = {};
assert.throws(TypeError, () => instance.until(props), "TypeError if at least one property is not present");
props.minute = 30;
const result = instance.until(props);
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, -30, 0, 0, 0, -1, "missing time units default to 0");

View File

@ -0,0 +1,21 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Supports sub-second precision
includes: [temporalHelpers.js]
features: [Temporal, arrow-function]
---*/
const time1 = Temporal.PlainTime.from("10:23:15");
const time2 = Temporal.PlainTime.from("17:15:57.250250250");
TemporalHelpers.assertDuration(time1.until(time2, { largestUnit: "milliseconds" }),
0, 0, 0, 0, 0, 0, 0, /* milliseconds = */ 24762250, 250, 250, "milliseconds");
TemporalHelpers.assertDuration(time1.until(time2, { largestUnit: "microseconds" }),
0, 0, 0, 0, 0, 0, 0, /* milliseconds = */ 0, 24762250250, 250, "microseconds");
TemporalHelpers.assertDuration(time1.until(time2, { largestUnit: "nanoseconds" }),
0, 0, 0, 0, 0, 0, 0, /* milliseconds = */ 0, 0, 24762250250250, "nanoseconds");

View File

@ -0,0 +1,24 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Tests roundingIncrement restrictions.
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "hours", roundingIncrement: 11 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "minutes", roundingIncrement: 29 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "seconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "milliseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "microseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "nanoseconds", roundingIncrement: 29 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "hours", roundingIncrement: 24 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "minutes", roundingIncrement: 60 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "seconds", roundingIncrement: 60 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "milliseconds", roundingIncrement: 1000 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "microseconds", roundingIncrement: 1000 }));
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "nanoseconds", roundingIncrement: 1000 }));

View File

@ -0,0 +1,54 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Tests calculations with roundingMode "ceil".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "hours", roundingMode: "ceil" }),
0, 0, 0, 0, 5, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "hours", roundingMode: "ceil" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "minutes", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 18, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "minutes", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "seconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "seconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 4, 865, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "ceil" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -0,0 +1,54 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Tests calculations with roundingMode "floor".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "hours", roundingMode: "floor" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "hours", roundingMode: "floor" }),
0, 0, 0, 0, -5, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "minutes", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "minutes", roundingMode: "floor" }),
0, 0, 0, 0, -4, -18, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "seconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "seconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -4, -865, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "floor" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -0,0 +1,54 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Tests calculations with roundingMode "halfExpand".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "hours", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "hours", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "minutes", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "seconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -9,6 +9,7 @@ features: [Temporal]
const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0);
const later = new Temporal.PlainTime(13, 35, 57, 123, 987, 500);
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l"]) {
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l", "auto"]) {
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "microsecond", roundingMode }));
}

View File

@ -0,0 +1,54 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.plaintime.prototype.until
description: Tests calculations with roundingMode "trunc".
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "hours", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "hours", roundingMode: "trunc" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "minutes", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "minutes", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "seconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "seconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "microseconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "microseconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "trunc" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");

View File

@ -8,20 +8,83 @@ includes: [temporalHelpers.js]
features: [Temporal]
---*/
const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0);
const later = new Temporal.PlainTime(13, 35, 57, 123, 987, 500);
const earlier = Temporal.PlainTime.from("08:22:36.123456789");
const later = Temporal.PlainTime.from("12:39:40.987654321");
const explicit1 = earlier.until(later, { smallestUnit: "microsecond", roundingMode: undefined });
TemporalHelpers.assertDuration(explicit1, 0, 0, 0, 0, 1, 1, 1, 123, 987, 0, "default roundingMode is trunc");
const implicit1 = earlier.until(later, { smallestUnit: "microsecond" });
TemporalHelpers.assertDuration(implicit1, 0, 0, 0, 0, 1, 1, 1, 123, 987, 0, "default roundingMode is trunc");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "hours", roundingMode: undefined }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "hours" }),
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "hours", roundingMode: undefined }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "hours" }),
0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours");
const explicit2 = earlier.until(later, { smallestUnit: "millisecond", roundingMode: undefined });
TemporalHelpers.assertDuration(explicit2, 0, 0, 0, 0, 1, 1, 1, 123, 0, 0, "default roundingMode is trunc");
const implicit2 = earlier.until(later, { smallestUnit: "millisecond" });
TemporalHelpers.assertDuration(implicit2, 0, 0, 0, 0, 1, 1, 1, 123, 0, 0, "default roundingMode is trunc");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "minutes", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "minutes" }),
0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "minutes", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "minutes" }),
0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes");
const explicit3 = earlier.until(later, { smallestUnit: "second", roundingMode: undefined });
TemporalHelpers.assertDuration(explicit3, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, "default roundingMode is trunc");
const implicit3 = earlier.until(later, { smallestUnit: "second" });
TemporalHelpers.assertDuration(implicit3, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, "default roundingMode is trunc");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "seconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "seconds" }),
0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "seconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "seconds" }),
0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "milliseconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "milliseconds" }),
0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "milliseconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "milliseconds" }),
0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "microseconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "microseconds" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "microseconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "microseconds" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: undefined }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
earlier.until(later, { smallestUnit: "nanoseconds" }),
0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: undefined }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");
TemporalHelpers.assertDuration(
later.until(earlier, { smallestUnit: "nanoseconds" }),
0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds");