Skip to content

Commit

Permalink
Change Temporal.TimeZone compare semantics to use .id
Browse files Browse the repository at this point in the history
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: tc39/proposal-temporal#2482
  • Loading branch information
ptomato committed Feb 18, 2023
1 parent 00fb851 commit adf2e1c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 33 deletions.
8 changes: 7 additions & 1 deletion harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,10 @@ var TemporalHelpers = {
return null;
}

get id() {
return "Custom/Spring_Fall";
}

toString() {
return "Custom/Spring_Fall";
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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",
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions test/staging/Temporal/UserTimezone/old/trivial-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/staging/Temporal/ZonedDateTime/old/equals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); },
Expand Down

0 comments on commit adf2e1c

Please sign in to comment.