From c99ec1780de996fc11a62c50974625e8dcd4d8c9 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Fri, 10 Sep 2021 17:53:26 -0400 Subject: [PATCH] Import tests for Temporal.Now.zonedDateTime These tests originated in the Temporal proposal repository https://github.com/tc39/proposal-temporal --- .../zonedDateTime/calendar-temporal-object.js | 22 ++++++++++ .../Temporal/Now/zonedDateTime/length.js | 24 +++++++++++ .../Now/zonedDateTime/time-zone-undefined.js | 30 +++++++++++++ .../zonedDateTime/timezone-string-datetime.js | 42 +++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 test/built-ins/Temporal/Now/zonedDateTime/calendar-temporal-object.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTime/length.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTime/time-zone-undefined.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTime/timezone-string-datetime.js diff --git a/test/built-ins/Temporal/Now/zonedDateTime/calendar-temporal-object.js b/test/built-ins/Temporal/Now/zonedDateTime/calendar-temporal-object.js new file mode 100644 index 0000000000..b4da48ab9a --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTime/calendar-temporal-object.js @@ -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"); +}); diff --git a/test/built-ins/Temporal/Now/zonedDateTime/length.js b/test/built-ins/Temporal/Now/zonedDateTime/length.js new file mode 100644 index 0000000000..d199da6874 --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTime/length.js @@ -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, +}); diff --git a/test/built-ins/Temporal/Now/zonedDateTime/time-zone-undefined.js b/test/built-ins/Temporal/Now/zonedDateTime/time-zone-undefined.js new file mode 100644 index 0000000000..15d4265204 --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTime/time-zone-undefined.js @@ -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"); diff --git a/test/built-ins/Temporal/Now/zonedDateTime/timezone-string-datetime.js b/test/built-ins/Temporal/Now/zonedDateTime/timezone-string-datetime.js new file mode 100644 index 0000000000..38f6cb00dd --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTime/timezone-string-datetime.js @@ -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)");