Temporal.PlainTime property bags

Tests for the normative change to Temporal made in
https://github.com/tc39/proposal-temporal/pull/1862
This commit is contained in:
Philip Chimento 2021-10-07 11:44:44 -07:00 committed by Rick Waldron
parent f782971ad2
commit 4158545044
18 changed files with 243 additions and 0 deletions

View File

@ -17,8 +17,14 @@ features: [Temporal]
const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

View File

@ -17,8 +17,14 @@ features: [Temporal]
const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

View File

@ -0,0 +1,15 @@
// 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.duration.prototype.add
description: Missing time units in relativeTo property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Duration(1, 0, 0, 1);
let relativeTo = { year: 2000, month: 1, day: 1 };
const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "missing time units default to 0");

View File

@ -17,8 +17,14 @@ features: [Temporal]
const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

View File

@ -0,0 +1,15 @@
// 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.duration.prototype.round
description: Missing time units in relativeTo property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
let relativeTo = { year: 2000, month: 1, day: 1 };
const result = instance.round({ largestUnit: "years", relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "missing time units default to 0");

View File

@ -17,8 +17,14 @@ features: [Temporal]
const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

View File

@ -0,0 +1,15 @@
// 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.duration.prototype.subtract
description: Missing time units in relativeTo property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.Duration(1, 0, 0, 1);
let relativeTo = { year: 2000, month: 1, day: 1 };
const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo });
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "missing time units default to 0");

View File

@ -17,8 +17,14 @@ features: [Temporal]
const expected = [
"day",
"hour",
"microsecond",
"millisecond",
"minute",
"month",
"monthCode",
"nanosecond",
"second",
"year",
];

View File

@ -0,0 +1,14 @@
// 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.duration.prototype.total
description: Missing time units in relativeTo property bag default to 0
features: [Temporal]
---*/
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
let relativeTo = { year: 2000, month: 1, day: 1 };
const result = instance.total({ unit: "days", relativeTo });
assert.sameValue(result, 367, "missing time units default to 0");

View File

@ -0,0 +1,18 @@
// 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.plaindate.prototype.toplaindatetime
description: Missing time units in property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.PlainDate(2000, 1, 1);
const props = {};
assert.throws(TypeError, () => instance.toPlainDateTime(props), "TypeError if at least one property is not present");
props.minute = 30;
const result = instance.toPlainDateTime(props);
TemporalHelpers.assertPlainDateTime(result, 2000, 1, "M01", 1, 0, 30, 0, 0, 0, 0, "missing time units default to 0");

View File

@ -0,0 +1,17 @@
// 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.plaindate.prototype.tozoneddatetime
description: Missing time units in property bag default to 0
features: [Temporal]
---*/
const instance = new Temporal.PlainDate(2000, 1, 1);
const props = {};
assert.throws(TypeError, () => instance.toZonedDateTime({ plainTime: props, timeZone: "UTC" }), "TypeError if at least one property is not present");
props.minute = 30;
const result = instance.toZonedDateTime({ plainTime: props, timeZone: "UTC" });
assert.sameValue(result.epochNanoseconds, 946686600_000_000_000n, "missing time units default to 0");

View File

@ -0,0 +1,18 @@
// 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.plaindatetime.prototype.withplaintime
description: Missing time units in property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const instance = new Temporal.PlainDateTime(2000, 1, 1, 12, 30, 45, 123, 456, 789);
const props = {};
assert.throws(TypeError, () => instance.withPlainTime(props), "TypeError if at least one property is not present");
props.minute = 30;
const result = instance.withPlainTime(props);
TemporalHelpers.assertPlainDateTime(result, 2000, 1, "M01", 1, 0, 30, 0, 0, 0, 0, "missing time units default to 0");

View File

@ -0,0 +1,15 @@
// 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.compare
description: Missing time units in property bag default to 0
features: [Temporal]
---*/
const props = {};
assert.throws(TypeError, () => Temporal.PlainTime.compare(props, new Temporal.PlainTime(0, 30)), "TypeError if at least one property is not present");
props.minute = 30;
const result = Temporal.PlainTime.compare(props, new Temporal.PlainTime(0, 30));
assert.sameValue(result, 0, "missing time units default to 0");

View File

@ -0,0 +1,16 @@
// 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.from
description: Missing time units in property bag default to 0
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const props = {};
assert.throws(TypeError, () => Temporal.PlainTime.from(props), "TypeError if at least one property is not present");
props.minute = 30;
const result = Temporal.PlainTime.from(props);
TemporalHelpers.assertPlainTime(result, 0, 30, 0, 0, 0, 0, "missing time units default to 0");

View File

@ -0,0 +1,17 @@
// 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.equals
description: Missing time units in property bag default to 0
features: [Temporal]
---*/
const instance = new Temporal.PlainTime(0, 30, 0, 0, 0, 0);
const props = {};
assert.throws(TypeError, () => instance.equals(props), "TypeError if at least one property is not present");
props.minute = 30;
const result = instance.equals(props);
assert.sameValue(result, true, "missing time units default to 0");

View File

@ -0,0 +1,18 @@
// 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,18 @@
// 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,17 @@
// 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.zoneddatetime.prototype.withplaintime
description: Missing time units in property bag default to 0
features: [Temporal]
---*/
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
const props = {};
assert.throws(TypeError, () => instance.withPlainTime(props), "TypeError if at least one property is not present");
props.minute = 30;
const result = instance.withPlainTime(props);
assert.sameValue(result.epochNanoseconds, 999995400_000_000_000n, "missing time units default to 0");