Temporal: Remove methods with ISO-named pairs

See tc39/proposal-temporal#2846
This commit is contained in:
Philip Chimento 2024-05-24 15:44:56 -07:00 committed by Philip Chimento
parent 3c28e3a359
commit 58df8fb22a
111 changed files with 5 additions and 2659 deletions

View File

@ -1,24 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.prototype.tozoneddatetime
description: Throw a TypeError if the receiver is invalid
features: [Symbol, Temporal]
---*/
const toZonedDateTime = Temporal.Instant.prototype.toZonedDateTime;
assert.sameValue(typeof toZonedDateTime, "function");
const args = [{ calendar: new Temporal.Calendar("iso8601"), timeZone: new Temporal.TimeZone("UTC") }];
assert.throws(TypeError, () => toZonedDateTime.apply(undefined, args), "undefined");
assert.throws(TypeError, () => toZonedDateTime.apply(null, args), "null");
assert.throws(TypeError, () => toZonedDateTime.apply(true, args), "true");
assert.throws(TypeError, () => toZonedDateTime.apply("", args), "empty string");
assert.throws(TypeError, () => toZonedDateTime.apply(Symbol(), args), "symbol");
assert.throws(TypeError, () => toZonedDateTime.apply(1, args), "1");
assert.throws(TypeError, () => toZonedDateTime.apply({}, args), "plain object");
assert.throws(TypeError, () => toZonedDateTime.apply(Temporal.Instant, args), "Temporal.Instant");
assert.throws(TypeError, () => toZonedDateTime.apply(Temporal.Instant.prototype, args), "Temporal.Instant.prototype");

View File

@ -1,33 +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.instant.prototype.tozoneddatetime
description: >
Tests that Temporal.Instant.prototype.toZonedDateTime
meets the requirements for built-in objects defined by the
introduction of chapter 17 of the ECMAScript Language Specification.
info: |
Built-in functions that are not constructors do not have a "prototype" property unless
otherwise specified in the description of a particular function.
Unless specified otherwise, a built-in object that is callable as a function is a built-in
function object with the characteristics described in 10.3. Unless specified otherwise, the
[[Extensible]] internal slot of a built-in object initially has the value true.
Unless otherwise specified every built-in function and every built-in constructor has the
Function prototype object [...] as the value of its [[Prototype]] internal slot.
features: [Temporal]
---*/
assert.sameValue(Object.isExtensible(Temporal.Instant.prototype.toZonedDateTime),
true, "Built-in objects must be extensible.");
assert.sameValue(Object.prototype.toString.call(Temporal.Instant.prototype.toZonedDateTime),
"[object Function]", "Object.prototype.toString");
assert.sameValue(Object.getPrototypeOf(Temporal.Instant.prototype.toZonedDateTime),
Function.prototype, "prototype");
assert.sameValue(Temporal.Instant.prototype.toZonedDateTime.hasOwnProperty("prototype"),
false, "prototype property");

View File

@ -1,14 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: Calendar names are case-insensitive
features: [Temporal]
---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const arg = "iSo8601";
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");

View File

@ -1,24 +0,0 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.prototype.tozoneddatetime
description: An ISO 8601 string can be converted to a calendar ID in Calendar
features: [Temporal]
---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
for (const arg of [
"2020-01-01",
"2020-01-01[u-ca=iso8601]",
"2020-01-01T00:00:00.000000000",
"2020-01-01T00:00:00.000000000[u-ca=iso8601]",
"01-01",
"01-01[u-ca=iso8601]",
"2020-01",
"2020-01[u-ca=iso8601]",
]) {
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
}

View File

@ -1,25 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: A number is not allowed to be a calendar
features: [Temporal]
---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const numbers = [
1,
-19761118,
19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }),
"A number is not a valid ISO string for Calendar"
);
}

View File

@ -1,18 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: Leap second is a valid ISO string for Calendar
features: [Temporal]
---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const arg = "2016-12-31T23:59:60";
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(
result.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

View File

@ -1,15 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: A calendar ID is valid input for Calendar
features: [Temporal]
---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const arg = "iso8601";
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);

View File

@ -1,39 +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.instant.prototype.tozoneddatetime
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal-totemporalcalendar step 1.b:
b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js]
features: [Temporal]
---*/
const plainDate = new Temporal.PlainDate(2000, 5, 2);
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5);
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
[plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((arg) => {
const actual = [];
const expected = [];
const calendar = arg.getISOFields().calendar;
Object.defineProperty(arg, "calendar", {
get() {
actual.push("get calendar");
return calendar;
},
});
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.compareArray(actual, expected, "calendar getter not called");
});

View File

@ -1,39 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for Calendar
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of primitiveTests) {
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object that doesn't implement the protocol"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.Calendar, "Temporal.Calendar, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.prototype.tozoneddatetime
description: Temporal.Instant.prototype.toZonedDateTime.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Instant.prototype.toZonedDateTime, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,23 +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.instant.prototype.tozoneddatetime
description: Temporal.Instant.prototype.toZonedDateTime.name is "toZonedDateTime".
info: |
Every built-in function object, including constructors, that is not identified as an anonymous
function has a "name" property whose value is a String. Unless otherwise specified, this value
is the name that is given to the function in this specification.
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Instant.prototype.toZonedDateTime, "name", {
value: "toZonedDateTime",
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,21 +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.instant.prototype.tozoneddatetime
description: >
Temporal.Instant.prototype.toZonedDateTime does not implement [[Construct]], is not new-able
info: |
Built-in function objects that are not identified as constructors do not implement the
[[Construct]] internal method unless otherwise specified in the description of a particular
function.
includes: [isConstructor.js]
features: [Reflect.construct, Temporal]
---*/
assert.throws(TypeError, () => {
new Temporal.Instant.prototype.toZonedDateTime();
}, "Calling as constructor");
assert.sameValue(isConstructor(Temporal.Instant.prototype.toZonedDateTime), false,
"isConstructor(Temporal.Instant.prototype.toZonedDateTime)");

View File

@ -1,21 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.prototype.tozoneddatetime
description: The "toZonedDateTime" property of Temporal.Instant.prototype
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(
typeof Temporal.Instant.prototype.toZonedDateTime,
"function",
"`typeof Instant.prototype.toZonedDateTime` is `function`"
);
verifyProperty(Temporal.Instant.prototype, "toZonedDateTime", {
writable: true,
enumerable: false,
configurable: true,
});

View File

@ -1,14 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: Time zone names are case insensitive
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
const timeZone = 'uTc';
const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result.timeZoneId, 'UTC', `Time zone created from string "${timeZone}"`);

View File

@ -1,62 +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.instant.prototype.tozoneddatetime
description: Conversion of ISO date-time strings to Temporal.TimeZone instances
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
let timeZone = "2021-08-19T17:30";
assert.throws(RangeError, () => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }), "bare date-time string is not a time zone");
[
"2021-08-19T17:30-07:00:01",
"2021-08-19T17:30-07:00:00",
"2021-08-19T17:30-07:00:00.1",
"2021-08-19T17:30-07:00:00.0",
"2021-08-19T17:30-07:00:00.01",
"2021-08-19T17:30-07:00:00.00",
"2021-08-19T17:30-07:00:00.001",
"2021-08-19T17:30-07:00:00.000",
"2021-08-19T17:30-07:00:00.0001",
"2021-08-19T17:30-07:00:00.0000",
"2021-08-19T17:30-07:00:00.00001",
"2021-08-19T17:30-07:00:00.00000",
"2021-08-19T17:30-07:00:00.000001",
"2021-08-19T17:30-07:00:00.000000",
"2021-08-19T17:30-07:00:00.0000001",
"2021-08-19T17:30-07:00:00.0000000",
"2021-08-19T17:30-07:00:00.00000001",
"2021-08-19T17:30-07:00:00.00000000",
"2021-08-19T17:30-07:00:00.000000001",
"2021-08-19T17:30-07:00:00.000000000",
].forEach((timeZone) => {
assert.throws(
RangeError,
() => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }),
`ISO string ${timeZone} with a sub-minute offset is not a valid time zone`
);
});
timeZone = "2021-08-19T17:30Z";
const result1 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result1.timeZoneId, "UTC", "date-time + Z is UTC time zone");
timeZone = "2021-08-19T17:30-07:00";
const result2 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result2.timeZoneId, "-07:00", "date-time + offset is the offset time zone");
timeZone = "2021-08-19T17:30[UTC]";
const result3 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result3.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone");
timeZone = "2021-08-19T17:30Z[UTC]";
const result4 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result4.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
timeZone = "2021-08-19T17:30-07:00[UTC]";
const result5 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result5.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone");

View File

@ -1,17 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: Leap second is a valid ISO string for TimeZone
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
let timeZone = "2016-12-31T23:59:60+00:00[UTC]";
const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone");
timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]";
assert.throws(RangeError, () => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }), "leap second in time zone name not valid");

View File

@ -1,14 +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.instant.prototype.tozoneddatetime
description: Time zone parsing from ISO strings uses the bracketed offset, not the ISO string offset
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
const timeZone = "2021-08-19T17:30:45.123456789-12:12[+01:46]";
const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result.timeZoneId, "+01:46", "Time zone string determined from bracket name");

View File

@ -1,21 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+00:00[UTC]",
];
const instance = new Temporal.Instant(0n);
invalidStrings.forEach((timeZone) => {
assert.throws(
RangeError,
() => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }),
"reject minus zero as extended year"
);
});

View File

@ -1,36 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.Instant(0n);
["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`);
});
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -1,39 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for TimeZone
features: [BigInt, Symbol, Temporal]
---*/
const instance = new Temporal.Instant(0n);
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[19761118, "number that would convert to a valid ISO string in other contexts"],
[1n, "bigint"],
];
for (const [timeZone, description] of primitiveTests) {
assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "object not implementing time zone protocol"],
[new Temporal.Calendar("iso8601"), "calendar instance"],
];
for (const [timeZone, description] of typeErrorTests) {
assert.throws(TypeError, () => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.instant.prototype.tozoneddatetime
esid: sec-temporal.instant.prototype.tozoneddatetimeiso
description: TimeZone.getPlainDateTimeFor is not called
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
@ -21,7 +21,7 @@ const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
getPlainDateTimeFor: Temporal.PlainDateTime.from("1963-07-02T12:00:00.987654321"),
});
const result = instant.toZonedDateTime({ timeZone, calendar });
const result = instant.toZonedDateTimeISO(timeZone);
assert.sameValue(result.epochNanoseconds, instant.epochNanoseconds);
assert.compareArray(actual, expected);

View File

@ -1,13 +0,0 @@
// 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.now.plaindate
description: Calendar names are case-insensitive
features: [Temporal]
---*/
const arg = "iSo8601";
const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");

View File

@ -1,22 +0,0 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindate
description: An ISO 8601 string can be converted to a calendar ID in Calendar
features: [Temporal]
---*/
for (const arg of [
"2020-01-01",
"2020-01-01[u-ca=iso8601]",
"2020-01-01T00:00:00.000000000",
"2020-01-01T00:00:00.000000000[u-ca=iso8601]",
"01-01",
"01-01[u-ca=iso8601]",
"2020-01",
"2020-01[u-ca=iso8601]",
]) {
const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
}

View File

@ -1,23 +0,0 @@
// 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.now.plaindate
description: A number is not allowed to be a calendar
features: [Temporal]
---*/
const numbers = [
1,
-19761118,
19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.Now.plainDate(arg),
"A number is not a valid ISO string for Calendar"
);
}

View File

@ -1,16 +0,0 @@
// 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.now.plaindate
description: Leap second is a valid ISO string for Calendar
features: [Temporal]
---*/
const arg = "2016-12-31T23:59:60";
const result = Temporal.Now.plainDate(arg);
assert.sameValue(
result.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

View File

@ -1,13 +0,0 @@
// 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.now.plaindate
description: A calendar ID is valid input for Calendar
features: [Temporal]
---*/
const arg = "iso8601";
const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);

View File

@ -1,38 +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.now.plaindate
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal-totemporalcalendar step 1.b:
b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js]
features: [Temporal]
---*/
const plainDate = new Temporal.PlainDate(2000, 5, 2);
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5);
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
[plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((arg) => {
const actual = [];
const expected = [];
const calendar = arg.getISOFields().calendar;
Object.defineProperty(arg, "calendar", {
get() {
actual.push("get calendar");
return calendar;
},
});
const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.compareArray(actual, expected, "calendar getter not called");
});

View File

@ -1,11 +0,0 @@
// 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.now.plaindate
description: Throws when the calendar argument is undefined
features: [Temporal]
---*/
assert.throws(TypeError, () => Temporal.Now.plainDate(), "implicit");
assert.throws(TypeError, () => Temporal.Now.plainDate(undefined), "implicit");

View File

@ -1,37 +0,0 @@
// 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.now.plaindate
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for Calendar
features: [BigInt, Symbol, Temporal]
---*/
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of primitiveTests) {
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => Temporal.Now.plainDate(arg),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object that doesn't implement the protocol"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.Calendar, "Temporal.Calendar, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Now.plainDate(arg), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindate
description: Temporal.Now.plainDate.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Now.plainDate, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,17 +0,0 @@
// 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.now.plaindate
description: The "plainDate" property of Temporal.Now
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(typeof Temporal.Now.plainDate, "function", "typeof is function");
verifyProperty(Temporal.Now, "plainDate", {
enumerable: false,
writable: true,
configurable: true
});

View File

@ -1,15 +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.now.plaindate
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
features: [Temporal]
includes: [temporalHelpers.js]
---*/
[3600_000_000_000.5, NaN].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone));
});

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.now.plaindate
description: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach(notCallable => {
const timeZone = new Temporal.TimeZone("UTC");
timeZone.getOffsetNanosecondsFor = notCallable;
assert.throws(
TypeError,
() => Temporal.Now.plainDate('iso8601', timeZone),
`Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError`
);
});

View File

@ -1,15 +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.now.plaindate
description: RangeError thrown if time zone reports an offset that is out of range
features: [Temporal]
includes: [temporalHelpers.js]
---*/
[-86400_000_000_001, 86400_000_000_001, -Infinity, Infinity].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone));
});

View File

@ -1,24 +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.now.plaindate
description: TypeError thrown if time zone reports an offset that is not a Number
features: [Temporal]
includes: [temporalHelpers.js]
---*/
[
undefined,
null,
true,
"+01:00",
Symbol(),
3600_000_000_000n,
{},
{ valueOf() { return 3600_000_000_000; } },
].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
assert.throws(TypeError, () => Temporal.Now.plainDate("iso8601", timeZone));
});

View File

@ -1,61 +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.now.plaindate
description: Conversion of ISO date-time strings to Temporal.TimeZone instances
features: [Temporal]
---*/
let timeZone = "2021-08-19T17:30";
assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone), "bare date-time string is not a time zone");
[
"2021-08-19T17:30-07:00:01",
"2021-08-19T17:30-07:00:00",
"2021-08-19T17:30-07:00:00.1",
"2021-08-19T17:30-07:00:00.0",
"2021-08-19T17:30-07:00:00.01",
"2021-08-19T17:30-07:00:00.00",
"2021-08-19T17:30-07:00:00.001",
"2021-08-19T17:30-07:00:00.000",
"2021-08-19T17:30-07:00:00.0001",
"2021-08-19T17:30-07:00:00.0000",
"2021-08-19T17:30-07:00:00.00001",
"2021-08-19T17:30-07:00:00.00000",
"2021-08-19T17:30-07:00:00.000001",
"2021-08-19T17:30-07:00:00.000000",
"2021-08-19T17:30-07:00:00.0000001",
"2021-08-19T17:30-07:00:00.0000000",
"2021-08-19T17:30-07:00:00.00000001",
"2021-08-19T17:30-07:00:00.00000000",
"2021-08-19T17:30-07:00:00.000000001",
"2021-08-19T17:30-07:00:00.000000000",
].forEach((timeZone) => {
assert.throws(
RangeError,
() => Temporal.Now.plainDate("iso8601", timeZone),
`ISO string ${timeZone} with a sub-minute offset is not a valid time zone`
);
});
// The following are all valid strings so should not throw:
[
"2021-08-19T17:30Z",
"2021-08-19T1730Z",
"2021-08-19T17:30-07:00",
"2021-08-19T1730-07:00",
"2021-08-19T17:30-0700",
"2021-08-19T1730-0700",
"2021-08-19T17:30[UTC]",
"2021-08-19T1730[UTC]",
"2021-08-19T17:30Z[UTC]",
"2021-08-19T1730Z[UTC]",
"2021-08-19T17:30-07:00[UTC]",
"2021-08-19T1730-07:00[UTC]",
"2021-08-19T17:30-0700[UTC]",
"2021-08-19T1730-0700[UTC]",
].forEach((timeZone) => {
Temporal.Now.plainDate("iso8601", timeZone);
});

View File

@ -1,18 +0,0 @@
// 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.now.plaindate
description: Leap second is a valid ISO string for TimeZone
features: [Temporal]
---*/
let timeZone = "2016-12-31T23:59:60+00:00[UTC]";
// A string with a leap second is a valid ISO string, so the following
// operation should not throw
Temporal.Now.plainDate("iso8601", timeZone);
timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]";
assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone), "leap second in time zone name not valid");

View File

@ -1,20 +0,0 @@
// 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.now.plaindate
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+00:00[UTC]",
];
invalidStrings.forEach((timeZone) => {
assert.throws(
RangeError,
() => Temporal.Now.plainDate("iso8601", timeZone),
"reject minus zero as extended year"
);
});

View File

@ -1,35 +0,0 @@
// 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.now.plaindate
description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDate("iso8601", timeZone);
});
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -1,37 +0,0 @@
// 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.now.plaindate
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for TimeZone
features: [BigInt, Symbol, Temporal]
---*/
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[19761118, "number that would convert to a valid ISO string in other contexts"],
[1n, "bigint"],
];
for (const [timeZone, description] of primitiveTests) {
assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => Temporal.Now.plainDate("iso8601", timeZone),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "object not implementing time zone protocol"],
[new Temporal.Calendar("iso8601"), "calendar instance"],
];
for (const [timeZone, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Now.plainDate("iso8601", timeZone), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindate
esid: sec-temporal.now.plaindateiso
description: PlainDateTime.toPlainDate is not observably called
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
@ -33,7 +33,7 @@ const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
},
});
const result = Temporal.Now.plainDate("iso8601", timeZone);
const result = Temporal.Now.plainDateISO(timeZone);
assert.notSameValue(result, undefined);
assert.sameValue(result instanceof Temporal.PlainDate, true);

View File

@ -1,13 +0,0 @@
// 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.now.plaindatetime
description: Calendar names are case-insensitive
features: [Temporal]
---*/
const arg = "iSo8601";
const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");

View File

@ -1,61 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Behavior when provided calendar value is a function
includes: [compareArray.js, temporalHelpers.js]
features: [BigInt, Proxy, Temporal]
---*/
const actual = [];
const expected = [
'has timeZone.getOffsetNanosecondsFor',
'has timeZone.getPossibleInstantsFor',
'has timeZone.id',
'get timeZone.getOffsetNanosecondsFor',
'call timeZone.getOffsetNanosecondsFor'
];
const calendar = function() {};
calendar.dateAdd = () => {};
calendar.dateFromFields = () => {};
calendar.dateUntil = () => {};
calendar.day = () => {};
calendar.dayOfWeek = () => {};
calendar.dayOfYear = () => {};
calendar.daysInMonth = () => {};
calendar.daysInWeek = () => {};
calendar.daysInYear = () => {};
calendar.fields = () => {};
calendar.id = "test-calendar";
calendar.inLeapYear = () => {};
calendar.mergeFields = () => {};
calendar.month = () => {};
calendar.monthCode = () => {};
calendar.monthDayFromFields = () => {};
calendar.monthsInYear = () => {};
calendar.weekOfYear = () => {};
calendar.year = () => {};
calendar.yearMonthFromFields = () => {};
calendar.yearOfWeek = () => {};
const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
getOffsetNanosecondsFor(instant) {
return -Number(instant.epochNanoseconds % 86400000000000n);
},
});
Object.defineProperty(Temporal.Calendar, 'from', {
get() {
actual.push('get Temporal.Calendar.from');
return undefined;
}
});
const result = Temporal.Now.plainDateTime(calendar, timeZone);
for (const property of ['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond']) {
assert.sameValue(result[property], 0, 'The value of result[property] is expected to be 0');
}
assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected');

View File

@ -1,22 +0,0 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: An ISO 8601 string can be converted to a calendar ID in Calendar
features: [Temporal]
---*/
for (const arg of [
"2020-01-01",
"2020-01-01[u-ca=iso8601]",
"2020-01-01T00:00:00.000000000",
"2020-01-01T00:00:00.000000000[u-ca=iso8601]",
"01-01",
"01-01[u-ca=iso8601]",
"2020-01",
"2020-01[u-ca=iso8601]",
]) {
const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
}

View File

@ -1,23 +0,0 @@
// 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.now.plaindatetime
description: A number is not allowed to be a calendar
features: [Temporal]
---*/
const numbers = [
1,
-19761118,
19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.Now.plainDateTime(arg),
"A number is not a valid ISO string for Calendar"
);
}

View File

@ -1,49 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Observable interactions with the provided calendar-like object
includes: [compareArray.js, temporalHelpers.js]
features: [Proxy, Temporal]
---*/
const actual = [];
const expected = [
"has calendar.dateAdd",
"has calendar.dateFromFields",
"has calendar.dateUntil",
"has calendar.day",
"has calendar.dayOfWeek",
"has calendar.dayOfYear",
"has calendar.daysInMonth",
"has calendar.daysInWeek",
"has calendar.daysInYear",
"has calendar.fields",
"has calendar.id",
"has calendar.inLeapYear",
"has calendar.mergeFields",
"has calendar.month",
"has calendar.monthCode",
"has calendar.monthDayFromFields",
"has calendar.monthsInYear",
"has calendar.weekOfYear",
"has calendar.year",
"has calendar.yearMonthFromFields",
"has calendar.yearOfWeek",
];
const calendar = TemporalHelpers.calendarObserver(actual, "calendar", {
toString: "iso8601",
});
Object.defineProperty(Temporal.Calendar, 'from', {
get() {
actual.push('get Temporal.Calendar.from');
return undefined;
},
});
Temporal.Now.plainDateTime(calendar);
assert.compareArray(actual, expected, 'order of observable operations');

View File

@ -1,16 +0,0 @@
// 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.now.plaindatetime
description: Leap second is a valid ISO string for Calendar
features: [Temporal]
---*/
const arg = "2016-12-31T23:59:60";
const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(
result.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

View File

@ -1,13 +0,0 @@
// 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.now.plaindatetime
description: A calendar ID is valid input for Calendar
features: [Temporal]
---*/
const arg = "iso8601";
const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);

View File

@ -1,38 +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.now.plaindatetime
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal-totemporalcalendar step 1.b:
b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js]
features: [Temporal]
---*/
const plainDate = new Temporal.PlainDate(2000, 5, 2);
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5);
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
[plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((arg) => {
const actual = [];
const expected = [];
const calendar = arg.getISOFields().calendar;
Object.defineProperty(arg, "calendar", {
get() {
actual.push("get calendar");
return calendar;
},
});
const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.compareArray(actual, expected, "calendar getter not called");
});

View File

@ -1,11 +0,0 @@
// 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.now.plaindatetime
description: Throws when the calendar argument is undefined
features: [Temporal]
---*/
assert.throws(TypeError, () => Temporal.Now.plainDateTime(), "implicit");
assert.throws(TypeError, () => Temporal.Now.plainDateTime(undefined), "implicit");

View File

@ -1,37 +0,0 @@
// 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.now.plaindatetime
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for Calendar
features: [BigInt, Symbol, Temporal]
---*/
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of primitiveTests) {
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => Temporal.Now.plainDateTime(arg),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object that doesn't implement the protocol"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.Calendar, "Temporal.Calendar, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Now.plainDateTime(arg), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -1,12 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Temporal.Now.plainDateTime is extensible.
features: [Temporal]
---*/
assert(
Object.isExtensible(Temporal.Now.plainDateTime),
'Object.isExtensible(Temporal.Now.plainDateTime) must return true'
);

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: The `length` property of Temporal.Now.plainDateTime
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Now.plainDateTime, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,20 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plainDateTime
description: Temporal.Now.plainDateTime.name is "plainDateTime".
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(
Temporal.Now.plainDateTime.name,
'plainDateTime',
'The value of Temporal.Now.plainDateTime.name is expected to be "plainDateTime"'
);
verifyProperty(Temporal.Now.plainDateTime, 'name', {
enumerable: false,
writable: false,
configurable: true
});

View File

@ -1,14 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Temporal.Now.plainDateTime does not implement [[Construct]]
includes: [isConstructor.js]
features: [Reflect.construct, Temporal, arrow-function]
---*/
assert.sameValue(isConstructor(Temporal.Now.plainDateTime), false, 'isConstructor(Temporal.Now.plainDateTime) must return false');
assert.throws(TypeError, () => {
new Temporal.Now.plainDateTime();
}, 'new Temporal.Now.plainDateTime() throws a TypeError exception');

View File

@ -1,16 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: The "plainDateTime" property of Temporal.Now
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(typeof Temporal.Now.plainDateTime, "function", "typeof is function");
verifyProperty(Temporal.Now, 'plainDateTime', {
enumerable: false,
writable: true,
configurable: true
});

View File

@ -1,22 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Return value describes the start of a day
features: [BigInt, Temporal]
---*/
const calendar = Temporal.Calendar.from('iso8601');
const timeZone = {
id: 'Etc/Test',
getPossibleInstantsFor() { return []; },
getOffsetNanosecondsFor(instant) {
return -Number(instant.epochNanoseconds % 86400000000000n);
}
};
const result = Temporal.Now.plainDateTime(calendar, timeZone);
for (const property of ['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond']) {
assert.sameValue(result[property], 0, 'The value of result[property] is expected to be 0');
}

View File

@ -1,35 +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.now.plaindatetime
description: Functions when time zone argument is omitted
includes: [compareArray.js]
features: [Temporal]
---*/
const actual = [];
const expected = [];
Object.defineProperty(Temporal.TimeZone, "from", {
get() {
actual.push("get Temporal.TimeZone.from");
return undefined;
},
});
const resultExplicit = Temporal.Now.plainDateTime("iso8601", undefined);
assert(
resultExplicit instanceof Temporal.PlainDateTime,
'The result of evaluating (resultExplicit instanceof Temporal.PlainDateTime) is expected to be true'
);
assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected');
const resultImplicit = Temporal.Now.plainDateTime("iso8601");
assert(
resultImplicit instanceof Temporal.PlainDateTime,
'The result of evaluating (resultImplicit instanceof Temporal.PlainDateTime) is expected to be true'
);
assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected');

View File

@ -1,30 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Correctly invokes `getOffsetNanosecondsFor` method of TimeZone-like objects
features: [Temporal]
---*/
var calls = [];
var timeZone = {
id: 'Etc/Test',
getPossibleInstantsFor() { return []; },
getOffsetNanosecondsFor: function() {
calls.push({
args: arguments,
this: this
});
return 0;
},
};
Temporal.Now.plainDateTime('iso8601', timeZone);
assert.sameValue(calls.length, 1, 'The value of calls.length is expected to be 1');
assert.sameValue(calls[0].args.length, 1, 'The value of calls[0].args.length is expected to be 1');
assert(
calls[0].args[0] instanceof Temporal.Instant,
'The result of evaluating (calls[0].args[0] instanceof Temporal.Instant) is expected to be true'
);
assert.sameValue(calls[0].this, timeZone, 'The value of calls[0].this is expected to equal the value of timeZone');

View File

@ -1,17 +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.now.plaindatetime
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
features: [Temporal, arrow-function]
includes: [temporalHelpers.js]
---*/
[3600000000000.5, NaN].forEach(wrongOffset => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
assert.throws(
RangeError,
() => Temporal.Now.plainDateTime('iso8601', timeZone),
'Temporal.Now.plainDateTime("iso8601", timeZone) throws a RangeError exception'
);
});

View File

@ -1,15 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Rejects when `getOffsetNanosecondsFor` property is not a method
features: [Temporal]
---*/
var timeZone = {
getOffsetNanosecondsFor: 7
};
assert.throws(TypeError, function() {
Temporal.Now.plainDateTime('iso8601', timeZone);
}, 'Temporal.Now.plainDateTime("iso8601", timeZone) throws a TypeError exception');

View File

@ -1,39 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Rejects non-numeric nanosecond values reported by TimeZone-like object
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
const invalidValues = [
undefined,
null,
true,
'2020-01-01T12:45:36',
Symbol(),
2n,
{},
Temporal.PlainDateTime,
Temporal.PlainDateTime.prototype
];
for (const dateTime of invalidValues) {
let callCount = 0;
const timeZone = {
id: 'Etc/Test',
getPossibleInstantsFor() { return []; },
getOffsetNanosecondsFor() {
callCount += 1;
return dateTime;
}
};
assert.throws(
TypeError,
() => Temporal.Now.plainDateTime('iso8601', timeZone),
'Temporal.Now.plainDateTime("iso8601", timeZone) throws a TypeError exception'
);
assert.sameValue(callCount, 1, 'The value of callCount is expected to be 1');
}

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.now.plaindatetime
description: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable
features: [BigInt, Symbol, Temporal, arrow-function]
---*/
[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach(notCallable => {
const timeZone = new Temporal.TimeZone("UTC");
timeZone.getOffsetNanosecondsFor = notCallable;
assert.throws(
TypeError,
() => Temporal.Now.plainDateTime('iso8601', timeZone),
`Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError`
);
});

View File

@ -1,17 +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.now.plaindatetime
description: RangeError thrown if time zone reports an offset that is out of range
features: [Temporal, arrow-function]
includes: [temporalHelpers.js]
---*/
[-86400000000001, 86400000000001, -Infinity, Infinity].forEach(wrongOffset => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
assert.throws(
RangeError,
() => Temporal.Now.plainDateTime('iso8601', timeZone),
'Temporal.Now.plainDateTime("iso8601", timeZone) throws a RangeError exception'
);
});

View File

@ -1,19 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Forwards error when accessing `getOffsetNanosecondsFor` property throws
features: [Temporal]
---*/
var timeZone = {
id: 'Etc/Test',
getPossibleInstantsFor() { return []; },
get getOffsetNanosecondsFor() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Temporal.Now.plainDateTime('iso8601', timeZone);
}, 'Temporal.Now.plainDateTime("iso8601", timeZone) throws a Test262Error exception');

View File

@ -1,19 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Forwards error when `getOffsetNanosecondsFor` throws
features: [Temporal]
---*/
var timeZone = {
id: 'Etc/Test',
getPossibleInstantsFor() { return []; },
getOffsetNanosecondsFor() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
Temporal.Now.plainDateTime('iso8601', timeZone);
}, 'Temporal.Now.plainDateTime("iso8601", timeZone) throws a Test262Error exception');

View File

@ -1,21 +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.now.plaindatetime
description: TypeError thrown if time zone reports an offset that is not a Number
features: [BigInt, Symbol, Temporal, arrow-function]
includes: [temporalHelpers.js]
---*/
[undefined, null, true, '+01:00', Symbol(), 3600000000000n, {}, {
valueOf() {
return 3600000000000;
}
}].forEach(wrongOffset => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
assert.throws(
TypeError,
() => Temporal.Now.plainDateTime('iso8601', timeZone),
'Temporal.Now.plainDateTime("iso8601", timeZone) throws a TypeError exception'
);
});

View File

@ -1,39 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: Observable interactions with the provided timezone-like object
includes: [compareArray.js, temporalHelpers.js]
features: [BigInt, Proxy, Temporal]
---*/
const actual = [];
const expected = [
'has timeZone.getOffsetNanosecondsFor',
'has timeZone.getPossibleInstantsFor',
'has timeZone.id',
'get timeZone.getOffsetNanosecondsFor',
'call timeZone.getOffsetNanosecondsFor'
];
const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
getOffsetNanosecondsFor(instant) {
assert.sameValue(
instant instanceof Temporal.Instant,
true,
'The result of evaluating (instant instanceof Temporal.Instant) is expected to be true'
);
return -Number(instant.epochNanoseconds % 86400000000000n);
}
});
Object.defineProperty(Temporal.TimeZone, 'from', {
get() {
actual.push('get Temporal.TimeZone.from');
return undefined;
}
});
Temporal.Now.plainDateTime('iso8601', timeZone);
assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected');

View File

@ -1,61 +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.now.plaindatetime
description: Conversion of ISO date-time strings to Temporal.TimeZone instances
features: [Temporal]
---*/
let timeZone = "2021-08-19T17:30";
assert.throws(RangeError, () => Temporal.Now.plainDateTime("iso8601", timeZone), "bare date-time string is not a time zone");
[
"2021-08-19T17:30-07:00:01",
"2021-08-19T17:30-07:00:00",
"2021-08-19T17:30-07:00:00.1",
"2021-08-19T17:30-07:00:00.0",
"2021-08-19T17:30-07:00:00.01",
"2021-08-19T17:30-07:00:00.00",
"2021-08-19T17:30-07:00:00.001",
"2021-08-19T17:30-07:00:00.000",
"2021-08-19T17:30-07:00:00.0001",
"2021-08-19T17:30-07:00:00.0000",
"2021-08-19T17:30-07:00:00.00001",
"2021-08-19T17:30-07:00:00.00000",
"2021-08-19T17:30-07:00:00.000001",
"2021-08-19T17:30-07:00:00.000000",
"2021-08-19T17:30-07:00:00.0000001",
"2021-08-19T17:30-07:00:00.0000000",
"2021-08-19T17:30-07:00:00.00000001",
"2021-08-19T17:30-07:00:00.00000000",
"2021-08-19T17:30-07:00:00.000000001",
"2021-08-19T17:30-07:00:00.000000000",
].forEach((timeZone) => {
assert.throws(
RangeError,
() => Temporal.Now.plainDateTime("iso8601", timeZone),
`ISO string ${timeZone} with a sub-minute offset is not a valid time zone`
);
});
// The following are all valid strings so should not throw:
[
"2021-08-19T17:30Z",
"2021-08-19T1730Z",
"2021-08-19T17:30-07:00",
"2021-08-19T1730-07:00",
"2021-08-19T17:30-0700",
"2021-08-19T1730-0700",
"2021-08-19T17:30[UTC]",
"2021-08-19T1730[UTC]",
"2021-08-19T17:30Z[UTC]",
"2021-08-19T1730Z[UTC]",
"2021-08-19T17:30-07:00[UTC]",
"2021-08-19T1730-07:00[UTC]",
"2021-08-19T17:30-0700[UTC]",
"2021-08-19T1730-0700[UTC]",
].forEach((timeZone) => {
Temporal.Now.plainDateTime("iso8601", timeZone);
});

View File

@ -1,18 +0,0 @@
// 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.now.plaindatetime
description: Leap second is a valid ISO string for TimeZone
features: [Temporal]
---*/
let timeZone = "2016-12-31T23:59:60+00:00[UTC]";
// A string with a leap second is a valid ISO string, so the following
// operation should not throw
Temporal.Now.plainDateTime("iso8601", timeZone);
timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]";
assert.throws(RangeError, () => Temporal.Now.plainDateTime("iso8601", timeZone), "leap second in time zone name not valid");

View File

@ -1,20 +0,0 @@
// 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.now.plaindatetime
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+00:00[UTC]",
];
invalidStrings.forEach((timeZone) => {
assert.throws(
RangeError,
() => Temporal.Now.plainDateTime("iso8601", timeZone),
"reject minus zero as extended year"
);
});

View File

@ -1,35 +0,0 @@
// 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.now.plaindatetime
description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
// The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDateTime("iso8601", timeZone);
});
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -1,37 +0,0 @@
// 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.now.plaindatetime
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for TimeZone
features: [BigInt, Symbol, Temporal]
---*/
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[19761118, "number that would convert to a valid ISO string in other contexts"],
[1n, "bigint"],
];
for (const [timeZone, description] of primitiveTests) {
assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => Temporal.Now.plainDateTime("iso8601", timeZone),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "object not implementing time zone protocol"],
[new Temporal.Calendar("iso8601"), "calendar instance"],
];
for (const [timeZone, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Now.plainDateTime("iso8601", timeZone), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -1,34 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.plaindatetime
description: The value returned by TimeZone.getOffsetNanosecondsFor affects the result
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const actual = [];
const expected = [
"has timeZone.getOffsetNanosecondsFor",
"has timeZone.getPossibleInstantsFor",
"has timeZone.id",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
getOffsetNanosecondsFor(instant) {
assert.sameValue(instant instanceof Temporal.Instant, true, "Instant");
return -Number(instant.epochNanoseconds % 86400_000_000_000n);
},
});
const calendar = Temporal.Calendar.from("iso8601");
const result = Temporal.Now.plainDateTime(calendar, timeZone);
for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) {
assert.sameValue(result[property], 0, property);
}
assert.compareArray(actual, expected);

View File

@ -1,13 +0,0 @@
// 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.now.zoneddatetime
description: Calendar names are case-insensitive
features: [Temporal]
---*/
const arg = "iSo8601";
const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");

View File

@ -1,58 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: Behavior when provided calendar value is a function
includes: [compareArray.js, temporalHelpers.js]
features: [BigInt, Proxy, Temporal]
---*/
const actual = [];
const expected = [
"has timeZone.getOffsetNanosecondsFor",
"has timeZone.getPossibleInstantsFor",
"has timeZone.id",
];
const calendar = function() {};
calendar.dateAdd = () => {};
calendar.dateFromFields = () => {};
calendar.dateUntil = () => {};
calendar.day = () => {};
calendar.dayOfWeek = () => {};
calendar.dayOfYear = () => {};
calendar.daysInMonth = () => {};
calendar.daysInWeek = () => {};
calendar.daysInYear = () => {};
calendar.fields = () => {};
calendar.id = "test-calendar";
calendar.inLeapYear = () => {};
calendar.mergeFields = () => {};
calendar.month = () => {};
calendar.monthCode = () => {};
calendar.monthDayFromFields = () => {};
calendar.monthsInYear = () => {};
calendar.weekOfYear = () => {};
calendar.year = () => {};
calendar.yearMonthFromFields = () => {};
calendar.yearOfWeek = () => {};
const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
getOffsetNanosecondsFor(instant) {
return -Number(instant.epochNanoseconds % 86400000000000n);
}
});
Object.defineProperty(Temporal.Calendar, 'from', {
get() {
actual.push('get Temporal.Calendar.from');
return undefined;
}
});
const result = Temporal.Now.zonedDateTime(calendar, timeZone);
assert.compareArray(actual, expected, 'order of observable operations');
for (const property of ['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond']) {
assert.sameValue(result[property], 0, 'The value of result[property] is expected to be 0');
}

View File

@ -1,22 +0,0 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: An ISO 8601 string can be converted to a calendar ID in Calendar
features: [Temporal]
---*/
for (const arg of [
"2020-01-01",
"2020-01-01[u-ca=iso8601]",
"2020-01-01T00:00:00.000000000",
"2020-01-01T00:00:00.000000000[u-ca=iso8601]",
"01-01",
"01-01[u-ca=iso8601]",
"2020-01",
"2020-01[u-ca=iso8601]",
]) {
const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
}

View File

@ -1,23 +0,0 @@
// 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.now.zoneddatetime
description: A number is not allowed to be a calendar
features: [Temporal]
---*/
const numbers = [
1,
-19761118,
19761118,
1234567890,
];
for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.Now.zonedDateTime(arg),
"A number is not a valid ISO string for Calendar"
);
}

View File

@ -1,49 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: Observable interactions with the provided calendar-like object
includes: [compareArray.js, temporalHelpers.js]
features: [Proxy, Temporal]
---*/
const actual = [];
const expected = [
"has calendar.dateAdd",
"has calendar.dateFromFields",
"has calendar.dateUntil",
"has calendar.day",
"has calendar.dayOfWeek",
"has calendar.dayOfYear",
"has calendar.daysInMonth",
"has calendar.daysInWeek",
"has calendar.daysInYear",
"has calendar.fields",
"has calendar.id",
"has calendar.inLeapYear",
"has calendar.mergeFields",
"has calendar.month",
"has calendar.monthCode",
"has calendar.monthDayFromFields",
"has calendar.monthsInYear",
"has calendar.weekOfYear",
"has calendar.year",
"has calendar.yearMonthFromFields",
"has calendar.yearOfWeek",
];
const calendar = TemporalHelpers.calendarObserver(actual, "calendar", {
toString: "iso8601",
});
Object.defineProperty(Temporal.Calendar, 'from', {
get() {
actual.push('get Temporal.Calendar.from');
return undefined;
},
});
Temporal.Now.zonedDateTime(calendar);
assert.compareArray(actual, expected, 'order of observable operations');

View File

@ -1,16 +0,0 @@
// 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.now.zoneddatetime
description: Leap second is a valid ISO string for Calendar
features: [Temporal]
---*/
const arg = "2016-12-31T23:59:60";
const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(
result.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

View File

@ -1,13 +0,0 @@
// 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.now.zoneddatetime
description: A calendar ID is valid input for Calendar
features: [Temporal]
---*/
const arg = "iso8601";
const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);

View File

@ -1,38 +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.now.zoneddatetime
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal-totemporalcalendar step 1.b:
b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js]
features: [Temporal]
---*/
const plainDate = new Temporal.PlainDate(2000, 5, 2);
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5);
const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
[plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((arg) => {
const actual = [];
const expected = [];
const calendar = arg.getISOFields().calendar;
Object.defineProperty(arg, "calendar", {
get() {
actual.push("get calendar");
return calendar;
},
});
const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");
assert.compareArray(actual, expected, "calendar getter not called");
});

View File

@ -1,11 +0,0 @@
// 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.now.zoneddatetime
description: Throws when the calendar argument is undefined
features: [Temporal]
---*/
assert.throws(TypeError, () => Temporal.Now.zonedDateTime(), "implicit");
assert.throws(TypeError, () => Temporal.Now.zonedDateTime(undefined), "implicit");

View File

@ -1,37 +0,0 @@
// 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.now.zoneddatetime
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for Calendar
features: [BigInt, Symbol, Temporal]
---*/
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];
for (const [arg, description] of primitiveTests) {
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => Temporal.Now.zonedDateTime(arg),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "plain object that doesn't implement the protocol"],
[new Temporal.TimeZone("UTC"), "time zone instance"],
[Temporal.Calendar, "Temporal.Calendar, object"],
];
for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Now.zonedDateTime(arg), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -1,12 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: Temporal.Now.zonedDateTime is extensible.
features: [Temporal]
---*/
assert(
Object.isExtensible(Temporal.Now.zonedDateTime),
'Object.isExtensible(Temporal.Now.zonedDateTime) must return true'
);

View File

@ -1,25 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: The `length` property of Temporal.Now.zonedDateTime
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/
verifyProperty(Temporal.Now.zonedDateTime, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});

View File

@ -1,20 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: Temporal.Now.zonedDateTime.name is "zonedDateTime".
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(
Temporal.Now.zonedDateTime.name,
'zonedDateTime',
'The value of Temporal.Now.zonedDateTime.name is expected to be "zonedDateTime"'
);
verifyProperty(Temporal.Now.zonedDateTime, 'name', {
enumerable: false,
writable: false,
configurable: true
});

View File

@ -1,14 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: Temporal.Now.zonedDateTime does not implement [[Construct]]
includes: [isConstructor.js]
features: [Reflect.construct, Temporal, arrow-function]
---*/
assert.sameValue(isConstructor(Temporal.Now.zonedDateTime), false, 'isConstructor(Temporal.Now.zonedDateTime) must return false');
assert.throws(TypeError, () => {
new Temporal.Now.zonedDateTime();
}, 'new Temporal.Now.zonedDateTime() throws a TypeError exception');

View File

@ -1,16 +0,0 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: The "zonedDateTime" property of Temporal.Now
includes: [propertyHelper.js]
features: [Temporal]
---*/
assert.sameValue(typeof Temporal.Now.zonedDateTime, "function", "typeof is function");
verifyProperty(Temporal.Now, 'zonedDateTime', {
enumerable: false,
writable: true,
configurable: true
});

View File

@ -1,31 +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.now.zoneddatetime
description: Functions when time zone argument is omitted
includes: [compareArray.js]
features: [Temporal]
---*/
const actual = [];
const expected = [];
Object.defineProperty(Temporal.TimeZone, "from", {
get() {
actual.push("get Temporal.TimeZone.from");
return undefined;
},
});
const systemTimeZone = Temporal.Now.timeZoneId();
const resultExplicit = Temporal.Now.zonedDateTime('iso8601', undefined);
assert.sameValue(resultExplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");
assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");
const resultImplicit = Temporal.Now.zonedDateTime('iso8601');
assert.sameValue(resultImplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");
assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");

View File

@ -1,12 +0,0 @@
// 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.now.zoneddatetime
description: Time zone names are case insensitive
features: [Temporal]
---*/
const timeZone = 'UtC';
const result = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result.timeZoneId, 'UTC', `Time zone created from string "${timeZone}"`);

View File

@ -1,36 +0,0 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.now.zoneddatetime
description: Observable interactions with the provided timezone-like object
includes: [compareArray.js, temporalHelpers.js]
features: [BigInt, Proxy, Temporal]
---*/
const actual = [];
const expected = [
"has timeZone.getOffsetNanosecondsFor",
"has timeZone.getPossibleInstantsFor",
"has timeZone.id",
];
const timeZone = TemporalHelpers.timeZoneObserver(actual, "timeZone", {
getOffsetNanosecondsFor(instant) {
assert.sameValue(
instant instanceof Temporal.Instant,
true,
'The result of evaluating (instant instanceof Temporal.Instant) is expected to be true'
);
return -Number(instant.epochNanoseconds % 86400000000000n);
}
});
Object.defineProperty(Temporal.TimeZone, 'from', {
get() {
actual.push('get Temporal.TimeZone.from');
return undefined;
}
});
Temporal.Now.zonedDateTime('iso8601', timeZone);
assert.compareArray(actual, expected, 'order of observable operations');

View File

@ -1,60 +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.now.zoneddatetime
description: Conversion of ISO date-time strings to Temporal.TimeZone instances
features: [Temporal]
---*/
let timeZone = "2021-08-19T17:30";
assert.throws(RangeError, () => Temporal.Now.zonedDateTime("iso8601", timeZone), "bare date-time string is not a time zone");
[
"2021-08-19T17:30-07:00:01",
"2021-08-19T17:30-07:00:00",
"2021-08-19T17:30-07:00:00.1",
"2021-08-19T17:30-07:00:00.0",
"2021-08-19T17:30-07:00:00.01",
"2021-08-19T17:30-07:00:00.00",
"2021-08-19T17:30-07:00:00.001",
"2021-08-19T17:30-07:00:00.000",
"2021-08-19T17:30-07:00:00.0001",
"2021-08-19T17:30-07:00:00.0000",
"2021-08-19T17:30-07:00:00.00001",
"2021-08-19T17:30-07:00:00.00000",
"2021-08-19T17:30-07:00:00.000001",
"2021-08-19T17:30-07:00:00.000000",
"2021-08-19T17:30-07:00:00.0000001",
"2021-08-19T17:30-07:00:00.0000000",
"2021-08-19T17:30-07:00:00.00000001",
"2021-08-19T17:30-07:00:00.00000000",
"2021-08-19T17:30-07:00:00.000000001",
"2021-08-19T17:30-07:00:00.000000000",
].forEach((timeZone) => {
assert.throws(
RangeError,
() => Temporal.Now.zonedDateTime("iso8601", timeZone),
`ISO string ${timeZone} with a sub-minute offset is not a valid time zone`
);
});
timeZone = "2021-08-19T17:30Z";
const result1 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result1.timeZoneId, "UTC", "date-time + Z is UTC time zone");
timeZone = "2021-08-19T17:30-07:00";
const result2 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result2.timeZoneId, "-07:00", "date-time + offset is the offset time zone");
timeZone = "2021-08-19T17:30[UTC]";
const result3 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result3.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone");
timeZone = "2021-08-19T17:30Z[UTC]";
const result4 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result4.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
timeZone = "2021-08-19T17:30-07:00[UTC]";
const result5 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result5.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone");

View File

@ -1,16 +0,0 @@
// 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.now.zoneddatetime
description: Leap second is a valid ISO string for TimeZone
features: [Temporal]
---*/
let timeZone = "2016-12-31T23:59:60+00:00[UTC]";
const result = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone");
timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]";
assert.throws(RangeError, () => Temporal.Now.zonedDateTime("iso8601", timeZone), "leap second in time zone name not valid");

View File

@ -1,13 +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.now.zoneddatetime
description: Time zone parsing from ISO strings uses the bracketed offset, not the ISO string offset
features: [Temporal]
---*/
const timeZone = "2021-08-19T17:30:45.123456789-12:12[+01:46]";
const result = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result.timeZoneId, "+01:46", "Time zone string determined from bracket name");

View File

@ -1,20 +0,0 @@
// 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.now.zoneddatetime
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/
const invalidStrings = [
"-000000-10-31T17:45Z",
"-000000-10-31T17:45+00:00[UTC]",
];
invalidStrings.forEach((timeZone) => {
assert.throws(
RangeError,
() => Temporal.Now.zonedDateTime("iso8601", timeZone),
"reject minus zero as extended year"
);
});

View File

@ -1,34 +0,0 @@
// 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.now.zoneddatetime
description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result.getISOFields().timeZone, timeZone, `Time zone created from string "${timeZone}"`);
});
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -1,37 +0,0 @@
// 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.now.zoneddatetime
description: >
Appropriate error thrown when argument cannot be converted to a valid string
or object for TimeZone
features: [BigInt, Symbol, Temporal]
---*/
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[19761118, "number that would convert to a valid ISO string in other contexts"],
[1n, "bigint"],
];
for (const [timeZone, description] of primitiveTests) {
assert.throws(
typeof timeZone === 'string' ? RangeError : TypeError,
() => Temporal.Now.zonedDateTime("iso8601", timeZone),
`${description} does not convert to a valid ISO string`
);
}
const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "object not implementing time zone protocol"],
[new Temporal.Calendar("iso8601"), "calendar instance"],
];
for (const [timeZone, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Now.zonedDateTime("iso8601", timeZone), `${description} is not a valid object and does not convert to a string`);
}

View File

@ -1,22 +0,0 @@
// 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.instant.prototype.tozoneddatetime
description: Conversion of ISO date-time strings to Temporal.TimeZone instances (with IANA time zones)
features: [Temporal]
---*/
const instance = new Temporal.Instant(0n);
let timeZone = "2021-08-19T17:30[America/Vancouver]";
const result1 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result1.timeZoneId, "America/Vancouver", "date-time + IANA annotation is the IANA time zone");
timeZone = "2021-08-19T17:30Z[America/Vancouver]";
const result2 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result2.timeZoneId, "America/Vancouver", "date-time + Z + IANA annotation is the IANA time zone");
timeZone = "2021-08-19T17:30-07:00[America/Vancouver]";
const result3 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result3.timeZoneId, "America/Vancouver", "date-time + offset + IANA annotation is the IANA time zone");

View File

@ -1,12 +0,0 @@
// 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.now.plaindate
description: String calendar argument
features: [Temporal]
---*/
const date = Temporal.Now.plainDate("gregory");
assert(date instanceof Temporal.PlainDate);
assert.sameValue(date.calendarId, "gregory");

Some files were not shown because too many files have changed in this diff Show More