From adf2e1c437ba6f1d183e4572980697e027210677 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 18 Jan 2023 15:01:52 -0800 Subject: [PATCH] Change Temporal.TimeZone compare semantics to use .id Compare semantics for custom time zones that _don't_ extend Temporal.TimeZone (and therefore don't have the internal slot) use the value of the .id property, instead of calling toString(). Normative PR: https://github.com/tc39/proposal-temporal/pull/2482 --- harness/temporalHelpers.js | 8 +++++++- .../ZonedDateTime/prototype/equals/order-of-operations.js | 8 ++------ .../ZonedDateTime/prototype/since/order-of-operations.js | 8 ++------ .../prototype/toString/order-of-operations.js | 8 ++------ .../ZonedDateTime/prototype/toString/timezonename-auto.js | 2 +- .../prototype/toString/timezonename-critical.js | 2 +- .../ZonedDateTime/prototype/until/order-of-operations.js | 8 ++------ .../staging/Temporal/UserTimezone/old/trivial-protocol.js | 4 +--- .../ZonedDateTime/old/construction-and-properties.js | 4 ++-- test/staging/Temporal/ZonedDateTime/old/equals.js | 2 +- 10 files changed, 21 insertions(+), 33 deletions(-) diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index 55e00c81343..c9406d5db6b 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -1797,6 +1797,10 @@ var TemporalHelpers = { return null; } + get id() { + return "Custom/Spring_Fall"; + } + toString() { return "Custom/Spring_Fall"; } @@ -1817,7 +1821,9 @@ var TemporalHelpers = { */ timeZoneObserver(calls, objectName, methodOverrides = {}) { const utc = new Temporal.TimeZone("UTC"); - const trackingMethods = {}; + const trackingMethods = { + id: "UTC", + }; // Automatically generate the methods ["getOffsetNanosecondsFor", "getPossibleInstantsFor", "toString"].forEach((methodName) => { trackingMethods[methodName] = function (...args) { diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js index 0556c76ad51..49f7d9b3821 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/order-of-operations.js @@ -58,12 +58,8 @@ const expected = [ "get other.timeZone.getOffsetNanosecondsFor", "call other.timeZone.getOffsetNanosecondsFor", // TimeZoneEquals - "get this.timeZone[Symbol.toPrimitive]", - "get this.timeZone.toString", - "call this.timeZone.toString", - "get other.timeZone[Symbol.toPrimitive]", - "get other.timeZone.toString", - "call other.timeZone.toString", + "get this.timeZone.id", + "get other.timeZone.id", // CalendarEquals "get this.calendar.id", "get other.calendar.id", diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js index ed6d61c00e1..149719f3718 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js @@ -125,12 +125,8 @@ actual.splice(0); // clear // Making largestUnit a calendar unit adds the following observable operations: const expectedOpsForCalendarDifference = [ // TimeZoneEquals - "get this.timeZone[Symbol.toPrimitive]", - "get this.timeZone.toString", - "call this.timeZone.toString", - "get other.timeZone[Symbol.toPrimitive]", - "get other.timeZone.toString", - "call other.timeZone.toString", + "get this.timeZone.id", + "get other.timeZone.id", // DifferenceZonedDateTime "get this.timeZone.getOffsetNanosecondsFor", "call this.timeZone.getOffsetNanosecondsFor", diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js index 08535d27ac8..59e4dc1c066 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/order-of-operations.js @@ -31,9 +31,7 @@ const expected = [ "call this.timeZone.getOffsetNanosecondsFor", "get this.timeZone.getOffsetNanosecondsFor", "call this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone[Symbol.toPrimitive]", - "get this.timeZone.toString", - "call this.timeZone.toString", + "get this.timeZone.id", "get this.calendar.id", ]; const actual = []; @@ -79,9 +77,7 @@ const expectedForFractionalSecondDigits = [ "call this.timeZone.getOffsetNanosecondsFor", "get this.timeZone.getOffsetNanosecondsFor", "call this.timeZone.getOffsetNanosecondsFor", - "get this.timeZone[Symbol.toPrimitive]", - "get this.timeZone.toString", - "call this.timeZone.toString", + "get this.timeZone.id", "get this.calendar.id", ]; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js index 10e97af7086..bdde75152f6 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-auto.js @@ -12,7 +12,7 @@ const tests = [ ["+01:00", "1970-01-01T02:01:01.987654321+01:00[+01:00]", "built-in offset"], [{ getOffsetNanosecondsFor() { return 0; }, - toString() { return "Etc/Custom"; }, + id: "Etc/Custom", }, "1970-01-01T01:01:01.987654321+00:00[Etc/Custom]", "custom"], ]; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js index 05698e8272f..e7b79c94ffe 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezonename-critical.js @@ -14,7 +14,7 @@ const tests = [ ["+01:00", "1970-01-01T02:01:01.987654321+01:00[!+01:00]", "built-in offset"], [{ getOffsetNanosecondsFor() { return 0; }, - toString() { return "Etc/Custom"; }, + id: "Etc/Custom", }, "1970-01-01T01:01:01.987654321+00:00[!Etc/Custom]", "custom"], ]; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js index 1a5fa9e6e0c..476e392e3b3 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js @@ -125,12 +125,8 @@ actual.splice(0); // clear // Making largestUnit a calendar unit adds the following observable operations: const expectedOpsForCalendarDifference = [ // TimeZoneEquals - "get this.timeZone[Symbol.toPrimitive]", - "get this.timeZone.toString", - "call this.timeZone.toString", - "get other.timeZone[Symbol.toPrimitive]", - "get other.timeZone.toString", - "call other.timeZone.toString", + "get this.timeZone.id", + "get other.timeZone.id", // DifferenceZonedDateTime "get this.timeZone.getOffsetNanosecondsFor", "call this.timeZone.getOffsetNanosecondsFor", diff --git a/test/staging/Temporal/UserTimezone/old/trivial-protocol.js b/test/staging/Temporal/UserTimezone/old/trivial-protocol.js index 44de9bbfeeb..72ff02967bb 100644 --- a/test/staging/Temporal/UserTimezone/old/trivial-protocol.js +++ b/test/staging/Temporal/UserTimezone/old/trivial-protocol.js @@ -18,9 +18,7 @@ var obj = { var epochNs = MakeDate(dayNum, time); return [new Temporal.Instant(epochNs)]; }, - toString() { - return "Etc/Custom/UTC_Protocol"; - } + id: "Etc/Custom/UTC_Protocol", }; var inst = Temporal.Instant.fromEpochNanoseconds(0n); diff --git a/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js b/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js index 9fb60cfedc0..5a78498594a 100644 --- a/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js +++ b/test/staging/Temporal/ZonedDateTime/old/construction-and-properties.js @@ -19,7 +19,7 @@ assert.sameValue(zdt.toInstant().epochSeconds, Math.floor(Date.UTC(1976, 10, 18, assert.sameValue(zdt.toInstant().epochMilliseconds, Date.UTC(1976, 10, 18, 15, 23, 30, 123), "epochMilliseconds"); // Temporal.ZonedDateTime for (1976, 11, 18, 15, 23, 30, 123, 456, 789)" - var zdt = new Temporal.ZonedDateTime(epochNanos, new Temporal.TimeZone("UTC")); + var zdt = new Temporal.ZonedDateTime(epochNanos, "UTC"); // can be constructed assert(zdt instanceof Temporal.ZonedDateTime); assert.sameValue(typeof zdt, "object"); @@ -70,7 +70,7 @@ var fakeGregorian = { }; var fakeVienna = { getOffsetNanosecondsFor() { return 3600_000_000_000; }, - toString() { return "Europe/Vienna"; }, + id: "Europe/Vienna", } var zdt = new Temporal.ZonedDateTime(epochNanos, fakeVienna, fakeGregorian); assert(zdt instanceof Temporal.ZonedDateTime); diff --git a/test/staging/Temporal/ZonedDateTime/old/equals.js b/test/staging/Temporal/ZonedDateTime/old/equals.js index ac6e17f85de..8715af737c5 100644 --- a/test/staging/Temporal/ZonedDateTime/old/equals.js +++ b/test/staging/Temporal/ZonedDateTime/old/equals.js @@ -9,7 +9,7 @@ features: [Temporal] var tz = { getPossibleInstantsFor(pdt) { return Temporal.TimeZone.from("-05:00").getPossibleInstantsFor(pdt); }, - toString() { return "America/New_York"; }, + id: "America/New_York", }; var cal = { dateFromFields(...args) { return Temporal.Calendar.from("iso8601").dateFromFields(...args); },