diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals')
16 files changed, 562 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-object.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-object.js new file mode 100644 index 0000000000..196f32b1a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-object.js @@ -0,0 +1,106 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: Tests that objects can be compared for equality +features: [Temporal] +---*/ + +class CustomTimeZone extends Temporal.TimeZone { + constructor(id) { + super("UTC"); + this._id = id; + } + get id() { + return this._id; + } +} + +const objectsEqualUTC = [ + new Temporal.TimeZone("UTC"), + new CustomTimeZone("UTC"), + { id: "UTC", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, + new Temporal.ZonedDateTime(0n, "UTC") +]; + +const tzUTC = new Temporal.TimeZone("UTC"); + +for (const object of objectsEqualUTC) { + const result = tzUTC.equals(object); + assert.sameValue(result, true, `Receiver ${tzUTC.id} should equal argument ${object.id}`); +} + +const objectsEqual0000 = [ + new Temporal.TimeZone("+00:00"), + new Temporal.TimeZone("+0000"), + new Temporal.TimeZone("+00"), + new CustomTimeZone("+00:00"), + new CustomTimeZone("+0000"), + new CustomTimeZone("+00"), + { id: "+00:00", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, + { id: "+0000", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, + { id: "+00", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, + new Temporal.ZonedDateTime(0n, "+00:00"), + new Temporal.ZonedDateTime(0n, "+0000"), + new Temporal.ZonedDateTime(0n, "+00"), + "+00:00", + "+0000", + "+00" +]; + +const tz0000ToTest = [ + new Temporal.TimeZone("+00:00"), + new Temporal.TimeZone("+0000"), + new Temporal.TimeZone("+00"), + new CustomTimeZone("+00:00"), + new CustomTimeZone("+0000"), + new CustomTimeZone("+00") +]; + +for (const arg of objectsEqual0000) { + for (const receiver of tz0000ToTest) { + const result = receiver.equals(arg); + assert.sameValue(result, true, `Receiver ${receiver.id} should equal argument ${arg.id ?? arg}`); + } +} + +const objectsNotEqual = [ + new Temporal.TimeZone("+00:00"), + new CustomTimeZone("+00:00"), + new CustomTimeZone("Etc/Custom"), + { id: "+00:00", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, + { id: "Etc/Custom", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }, + new Temporal.ZonedDateTime(0n, "+00:00"), + "UTC" +]; + +const customObjectsToTest = [tzUTC, new CustomTimeZone("YouTeeSee"), new CustomTimeZone("+01:00")]; + +for (const arg of objectsNotEqual) { + for (const receiver of customObjectsToTest) { + if (arg === "UTC" && receiver === tzUTC) continue; + const result = receiver.equals(arg); + assert.sameValue(result, false, `Receiver ${receiver.id} should not equal argument ${arg.id ?? arg}`); + } +} + +// Custom object IDs are compared case-sensitively +const classInstanceCustomId = new CustomTimeZone("Moon/Cheese"); +const classInstanceSameCaseCustomId = new CustomTimeZone("Moon/Cheese"); +const classInstanceDifferentCaseCustomId = new CustomTimeZone("MoOn/CHEESe"); + +const plainObjectSameCaseCustomId = { id: "Moon/Cheese", getPossibleInstantsFor: null, getOffsetNanosecondsFor: null }; +const plainObjectDifferentCaseCustomId = { + id: "MoOn/CHEESe", + getPossibleInstantsFor: null, + getOffsetNanosecondsFor: null +}; + +assert.sameValue(classInstanceCustomId.equals(classInstanceSameCaseCustomId), true); +assert.sameValue(classInstanceCustomId.equals(classInstanceDifferentCaseCustomId), false); +assert.sameValue(classInstanceCustomId.equals(plainObjectSameCaseCustomId), true); +assert.sameValue(classInstanceCustomId.equals(plainObjectDifferentCaseCustomId), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-primitive.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-primitive.js new file mode 100644 index 0000000000..023206985d --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-primitive.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.from +description: Exceptions thrown if a value is passed that converts to an invalid string +features: [Temporal] +---*/ + +const primitives = [ + undefined, + null, + true, + "string", + "local", + "Z", + "-00:00[UTC]", + "+00:01.1", + "-01.1", + "1994-11-05T08:15:30+25:00", + "1994-11-05T13:15:30-25:00", + 7, + 4.2, + 12n +]; + +const tzUTC = new Temporal.TimeZone("UTC"); +for (const primitive of primitives) { + assert.throws(typeof primitive === "string" ? RangeError : TypeError, () => tzUTC.equals(primitive)); +} + +const symbol = Symbol(); +assert.throws(TypeError, () => tzUTC.equals(symbol)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-valid.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-valid.js new file mode 100644 index 0000000000..79af622fe4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/argument-valid.js @@ -0,0 +1,48 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.from +description: Built-in time zones are compared correctly out of valid strings +features: [Temporal] +---*/ + +const validsEqual = [ + ["+0330", "+03:30"], + ["-0650", "-06:50"], + ["-08", "-08:00"], + ["\u221201:00", "-01:00"], + ["\u22120650", "-06:50"], + ["\u221208", "-08:00"], + ["1994-11-05T08:15:30-05:00", "-05:00"], + ["1994-11-05T08:15:30\u221205:00", "-05:00"], + ["1994-11-05T13:15:30Z", "UTC"] +]; + +for (const [valid, canonical] of validsEqual) { + const tzValid = Temporal.TimeZone.from(valid); + const tzCanonical = Temporal.TimeZone.from(canonical); + assert.sameValue(tzValid.equals(canonical), true); + assert.sameValue(tzCanonical.equals(valid), true); +} + +const validsNotEqual = [ + ["+0330", "+03:31"], + ["-0650", "-06:51"], + ["-08", "-08:01"], + ["\u221201:00", "-01:01"], + ["\u22120650", "-06:51"], + ["\u221208", "-08:01"], + ["1994-11-05T08:15:30-05:00", "-05:01"], + ["1994-11-05T08:15:30\u221205:00", "-05:01"] +]; + +for (const [valid, canonical] of validsNotEqual) { + const tzValid = Temporal.TimeZone.from(valid); + const tzCanonical = Temporal.TimeZone.from(canonical); + assert.sameValue(tzValid.equals(canonical), false); + assert.sameValue(tzCanonical.equals(valid), false); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/branding.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/branding.js new file mode 100644 index 0000000000..5673b192e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/branding.js @@ -0,0 +1,27 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: Throw a TypeError if the receiver is invalid +features: [Symbol, Temporal] +---*/ + +const equals = Temporal.TimeZone.prototype.equals; + +assert.sameValue(typeof equals, "function"); + +const args = ["UTC"]; + +assert.throws(TypeError, () => equals.apply(undefined, args), "undefined"); +assert.throws(TypeError, () => equals.apply(null, args), "null"); +assert.throws(TypeError, () => equals.apply(true, args), "true"); +assert.throws(TypeError, () => equals.apply("", args), "empty string"); +assert.throws(TypeError, () => equals.apply(Symbol(), args), "symbol"); +assert.throws(TypeError, () => equals.apply(1, args), "1"); +assert.throws(TypeError, () => equals.apply({}, args), "plain object"); +assert.throws(TypeError, () => equals.apply(Temporal.TimeZone, args), "Temporal.TimeZone"); +assert.throws(TypeError, () => equals.apply(Temporal.TimeZone.prototype, args), "Temporal.TimeZone.prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/browser.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/browser.js diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/builtin.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/builtin.js new file mode 100644 index 0000000000..02c46c0d3b --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/builtin.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: > + Tests that Temporal.TimeZone.prototype.equals + 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.TimeZone.prototype.equals), + true, "Built-in objects must be extensible."); + +assert.sameValue(Object.prototype.toString.call(Temporal.TimeZone.prototype.equals), + "[object Function]", "Object.prototype.toString"); + +assert.sameValue(Object.getPrototypeOf(Temporal.TimeZone.prototype.equals), + Function.prototype, "prototype"); + +assert.sameValue(Temporal.TimeZone.prototype.equals.hasOwnProperty("prototype"), + false, "prototype property"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/id-wrong-type.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/id-wrong-type.js new file mode 100644 index 0000000000..b8fa629020 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/id-wrong-type.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: TypeError thrown if time zone reports an id that is not a String +features: [Temporal] +---*/ + +class CustomTimeZone extends Temporal.TimeZone { + constructor(id) { + super("UTC"); + this._id = id; + } + get id() { + return this._id; + } +} + +[ + undefined, + null, + true, + -1000, + Symbol(), + 3600_000_000_000n, + {}, + { + valueOf() { + return 3600_000_000_000; + } + } +].forEach((wrongId) => { + const timeZoneWrong = new CustomTimeZone(wrongId); + const timeZoneOK = new Temporal.TimeZone('UTC'); + assert.throws(TypeError, () => timeZoneWrong.equals(timeZoneOK)); + assert.throws(TypeError, () => timeZoneOK.equals(timeZoneWrong)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/length.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/length.js new file mode 100644 index 0000000000..61c65195ff --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/length.js @@ -0,0 +1,28 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: Temporal.TimeZone.prototype.equals.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.TimeZone.prototype.equals, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/name.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/name.js new file mode 100644 index 0000000000..df1828acc7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/name.js @@ -0,0 +1,26 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: Temporal.TimeZone.prototype.equals.name is "equals". +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.TimeZone.prototype.equals, "name", { + value: "equals", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/not-a-constructor.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/not-a-constructor.js new file mode 100644 index 0000000000..e01067b313 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/not-a-constructor.js @@ -0,0 +1,24 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: > + Temporal.TimeZone.prototype.equals 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.TimeZone.prototype.equals(); +}, "Calling as constructor"); + +assert.sameValue(isConstructor(Temporal.TimeZone.prototype.equals), false, + "isConstructor(Temporal.TimeZone.prototype.equals)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/prop-desc.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/prop-desc.js new file mode 100644 index 0000000000..deb16a6e1c --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/prop-desc.js @@ -0,0 +1,24 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.equals +description: The "equals" property of Temporal.TimeZone.prototype +includes: [propertyHelper.js] +features: [Temporal] +---*/ + +assert.sameValue( + typeof Temporal.TimeZone.prototype.equals, + "function", + "`typeof TimeZone.prototype.equals` is `function`" +); + +verifyProperty(Temporal.TimeZone.prototype, "equals", { + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/shell.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-case-insensitive.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-case-insensitive.js new file mode 100644 index 0000000000..28d4a0de6f --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-case-insensitive.js @@ -0,0 +1,16 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.equals +description: Time zone names are case insensitive +features: [Temporal] +---*/ + +const timeZone = 'UtC'; +const result = Temporal.TimeZone.from(timeZone); +assert.sameValue(result.equals(timeZone), true); +assert.sameValue(result.equals("+00:00"), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-string-datetime.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-string-datetime.js new file mode 100644 index 0000000000..56cafca99f --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-string-datetime.js @@ -0,0 +1,64 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.equals +description: Conversion of ISO date-time strings to the argument of Temporal.TimeZone.prototype.equals +features: [Temporal] +---*/ + +let tzUTC = Temporal.TimeZone.from("UTC"); +let arg = "2021-08-19T17:30"; +assert.throws(RangeError, () => tzUTC.equals(arg), "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, + () => tzUTC.equals(timeZone), + `ISO string ${timeZone} with a sub-minute offset is not a valid time zone` + ); +}); + +arg = "2021-08-19T17:30Z"; +tzUTC = Temporal.TimeZone.from(arg); +assert.sameValue(tzUTC.equals(arg), true, "date-time + Z is UTC time zone"); + +arg = "2021-08-19T17:30-07:00"; +tzUTC = Temporal.TimeZone.from(arg); +assert.sameValue(tzUTC.equals(arg), true, "date-time + offset is the offset time zone"); + +arg = "2021-08-19T17:30[UTC]"; +tzUTC = Temporal.TimeZone.from(arg); +assert.sameValue(tzUTC.equals(arg), true, "date-time + IANA annotation is the IANA time zone"); + +arg = "2021-08-19T17:30Z[UTC]"; +tzUTC = Temporal.TimeZone.from(arg); +assert.sameValue(tzUTC.equals(arg), true, "date-time + Z + IANA annotation is the IANA time zone"); + +arg = "2021-08-19T17:30-07:00[UTC]"; +tzUTC = Temporal.TimeZone.from(arg); +assert.sameValue(tzUTC.equals(arg), true, "date-time + offset + IANA annotation is the IANA time zone"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-string-multiple-offsets.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-string-multiple-offsets.js new file mode 100644 index 0000000000..2ac68213de --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-string-multiple-offsets.js @@ -0,0 +1,16 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.from +description: Time zone strings with UTC offset fractional part are not confused with time fractional part +features: [Temporal] +---*/ + +const timeZone = "2021-08-19T17:30:45.123456789-12:12[+01:46]"; + +const result = Temporal.TimeZone.from(timeZone); +assert.sameValue(result.equals("+01:46"), true, "Time zone string determined from bracket name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-wrong-type.js b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-wrong-type.js new file mode 100644 index 0000000000..a0031d3629 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/equals/timezone-wrong-type.js @@ -0,0 +1,46 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2023 Justin Grant. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.from +description: > + Appropriate error thrown when argument cannot be converted to a valid string + or object for TimeZone +features: [BigInt, Symbol, Temporal] +---*/ + +const rangeErrorTests = [ + [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"] +]; + +const tzUTC = new Temporal.TimeZone("UTC"); + +for (const [timeZone, description] of rangeErrorTests) { + assert.throws( + typeof timeZone === "string" ? RangeError : TypeError, + () => tzUTC.equals(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, + () => tzUTC.equals(timeZone), + `${description} is not a valid object and does not convert to a string` + ); +} + +reportCompare(0, 0); |