mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 04:54:44 +02:00
Import tests for Temporal.Now.zonedDateTime
These tests originated in the Temporal proposal repository https://github.com/tc39/proposal-temporal
This commit is contained in:
parent
0232d97415
commit
c99ec1780d
@ -0,0 +1,22 @@
|
|||||||
|
// 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.now.plaindatetime step 1:
|
||||||
|
1. Return ? SystemZonedDateTime(_temporalTimeZoneLike_, _calendar_).
|
||||||
|
sec-temporal-systemzoneddatetime step 3:
|
||||||
|
3. Let _calendar_ be ? ToTemporalCalendar(_calendarLike_).
|
||||||
|
sec-temporal-totemporalcalendar step 1.a:
|
||||||
|
a. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
|
||||||
|
i. Return _temporalCalendarLike_.[[Calendar]].
|
||||||
|
includes: [compareArray.js, temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
|
||||||
|
const result = Temporal.Now.zonedDateTime(temporalObject);
|
||||||
|
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
|
||||||
|
});
|
24
test/built-ins/Temporal/Now/zonedDateTime/length.js
Normal file
24
test/built-ins/Temporal/Now/zonedDateTime/length.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// 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
|
||||||
|
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,
|
||||||
|
});
|
@ -0,0 +1,30 @@
|
|||||||
|
// 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
|
||||||
|
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.timeZone();
|
||||||
|
|
||||||
|
const resultExplicit = Temporal.Now.zonedDateTime('iso8601', undefined);
|
||||||
|
assert.sameValue(resultExplicit.timeZone.id, systemTimeZone.id);
|
||||||
|
|
||||||
|
assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");
|
||||||
|
|
||||||
|
const resultImplicit = Temporal.Now.zonedDateTime('iso8601');
|
||||||
|
assert.sameValue(resultImplicit.timeZone.id, systemTimeZone.id);
|
||||||
|
|
||||||
|
assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");
|
@ -0,0 +1,42 @@
|
|||||||
|
// 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");
|
||||||
|
assert.throws(RangeError, () => Temporal.Now.zonedDateTime("iso8601", { timeZone }), "bare date-time string is not a time zone");
|
||||||
|
|
||||||
|
timeZone = "2021-08-19T17:30Z";
|
||||||
|
const result1 = Temporal.Now.zonedDateTime("iso8601", timeZone);
|
||||||
|
assert.sameValue(result1.timeZone.id, "UTC", "date-time + Z is UTC time zone");
|
||||||
|
const result2 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
|
||||||
|
assert.sameValue(result2.timeZone.id, "UTC", "date-time + Z is UTC time zone (string in property bag)");
|
||||||
|
|
||||||
|
timeZone = "2021-08-19T17:30-07:00";
|
||||||
|
const result3 = Temporal.Now.zonedDateTime("iso8601", timeZone);
|
||||||
|
assert.sameValue(result3.timeZone.id, "-07:00", "date-time + offset is the offset time zone");
|
||||||
|
const result4 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
|
||||||
|
assert.sameValue(result4.timeZone.id, "-07:00", "date-time + offset is the offset time zone (string in property bag)");
|
||||||
|
|
||||||
|
timeZone = "2021-08-19T17:30[America/Vancouver]";
|
||||||
|
const result5 = Temporal.Now.zonedDateTime("iso8601", timeZone);
|
||||||
|
assert.sameValue(result5.timeZone.id, "America/Vancouver", "date-time + IANA annotation is the IANA time zone");
|
||||||
|
const result6 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
|
||||||
|
assert.sameValue(result6.timeZone.id, "America/Vancouver", "date-time + IANA annotation is the IANA time zone (string in property bag)");
|
||||||
|
|
||||||
|
timeZone = "2021-08-19T17:30Z[America/Vancouver]";
|
||||||
|
const result7 = Temporal.Now.zonedDateTime("iso8601", timeZone);
|
||||||
|
assert.sameValue(result7.timeZone.id, "America/Vancouver", "date-time + Z + IANA annotation is the IANA time zone");
|
||||||
|
const result8 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
|
||||||
|
assert.sameValue(result8.timeZone.id, "America/Vancouver", "date-time + Z + IANA annotation is the IANA time zone (string in property bag)");
|
||||||
|
|
||||||
|
timeZone = "2021-08-19T17:30-07:00[America/Vancouver]";
|
||||||
|
const result9 = Temporal.Now.zonedDateTime("iso8601", timeZone);
|
||||||
|
assert.sameValue(result9.timeZone.id, "America/Vancouver", "date-time + offset + IANA annotation is the IANA time zone");
|
||||||
|
const result10 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
|
||||||
|
assert.sameValue(result10.timeZone.id, "America/Vancouver", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");
|
Loading…
x
Reference in New Issue
Block a user