From 57491d838f90d83b8faee1098362efdab4f57845 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Fri, 10 Sep 2021 17:54:20 -0400 Subject: [PATCH] Import tests for Temporal.Now.zonedDateTimeISO These tests originated in the Temporal proposal repository https://github.com/tc39/proposal-temporal --- .../Temporal/Now/zonedDateTimeISO/length.js | 24 +++++++++++ .../zonedDateTimeISO/time-zone-undefined.js | 30 +++++++++++++ .../timezone-string-datetime.js | 42 +++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 test/built-ins/Temporal/Now/zonedDateTimeISO/length.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTimeISO/time-zone-undefined.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-string-datetime.js diff --git a/test/built-ins/Temporal/Now/zonedDateTimeISO/length.js b/test/built-ins/Temporal/Now/zonedDateTimeISO/length.js new file mode 100644 index 0000000000..5bacbdc6d4 --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTimeISO/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.zoneddatetimeiso +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.zonedDateTimeISO, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/Temporal/Now/zonedDateTimeISO/time-zone-undefined.js b/test/built-ins/Temporal/Now/zonedDateTimeISO/time-zone-undefined.js new file mode 100644 index 0000000000..3acc06dc31 --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTimeISO/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.zoneddatetimeiso +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.zonedDateTimeISO(undefined); +assert.sameValue(resultExplicit.timeZone.id, systemTimeZone.id); + +assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called"); + +const resultImplicit = Temporal.Now.zonedDateTimeISO(); +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/zonedDateTimeISO/timezone-string-datetime.js b/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-string-datetime.js new file mode 100644 index 0000000000..de88cf693e --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTimeISO/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.zoneddatetimeiso +description: Conversion of ISO date-time strings to Temporal.TimeZone instances +features: [Temporal] +---*/ + +let timeZone = "2021-08-19T17:30"; +assert.throws(RangeError, () => Temporal.Now.zonedDateTimeISO(timeZone), "bare date-time string is not a time zone"); +assert.throws(RangeError, () => Temporal.Now.zonedDateTimeISO({ timeZone }), "bare date-time string is not a time zone"); + +timeZone = "2021-08-19T17:30Z"; +const result1 = Temporal.Now.zonedDateTimeISO(timeZone); +assert.sameValue(result1.timeZone.id, "UTC", "date-time + Z is UTC time zone"); +const result2 = Temporal.Now.zonedDateTimeISO({ 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.zonedDateTimeISO(timeZone); +assert.sameValue(result3.timeZone.id, "-07:00", "date-time + offset is the offset time zone"); +const result4 = Temporal.Now.zonedDateTimeISO({ 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.zonedDateTimeISO(timeZone); +assert.sameValue(result5.timeZone.id, "America/Vancouver", "date-time + IANA annotation is the IANA time zone"); +const result6 = Temporal.Now.zonedDateTimeISO({ 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.zonedDateTimeISO(timeZone); +assert.sameValue(result7.timeZone.id, "America/Vancouver", "date-time + Z + IANA annotation is the IANA time zone"); +const result8 = Temporal.Now.zonedDateTimeISO({ 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.zonedDateTimeISO(timeZone); +assert.sameValue(result9.timeZone.id, "America/Vancouver", "date-time + offset + IANA annotation is the IANA time zone"); +const result10 = Temporal.Now.zonedDateTimeISO({ timeZone }); +assert.sameValue(result10.timeZone.id, "America/Vancouver", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");