Change Temporal.Calendar compare semantics to use .id

Compare semantics for custom calendars that _don't_ extend
Temporal.Calendar (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
This commit is contained in:
Philip Chimento 2023-01-17 11:23:57 -08:00 committed by Philip Chimento
parent 41ffc678b0
commit aee3a937dc
92 changed files with 278 additions and 271 deletions

View File

@ -1520,7 +1520,8 @@ var TemporalHelpers = {
// Remove the HasProperty check resulting from the above constructor call
assert.sameValue(calls.pop(), `has ${objectName}.calendar`);
return result;
}
},
id: "iso8601",
};
// Automatically generate the other methods that don't need any custom code
["toString", "dateUntil", "era", "eraYear", "year", "month", "monthCode", "day", "daysInMonth", "fields", "mergeFields"].forEach((methodName) => {

View File

@ -11,6 +11,6 @@ const instance = new Temporal.PlainDate(2000, 5, 2);
assert.sameValue(instance.equals({ year: 2000, month: 5, day: 2 }), true, "same date");
assert.sameValue(instance.equals({ year: 2000, month: 5, day: 4 }), false, "different date");
const calendar = { toString() { return "a" } };
const calendar = { id: "a" };
assert.sameValue(instance.withCalendar(calendar).equals({ year: 2000, month: 5, day: 2 }),
false, "different calendar");

View File

@ -11,5 +11,5 @@ const instance = new Temporal.PlainDate(2000, 5, 2);
assert.sameValue(instance.equals("2000-05-02"), true, "same date");
assert.sameValue(instance.equals("2000-05-04"), false, "different date");
const calendar = { toString() { return "a" } };
const calendar = { id: "a" };
assert.sameValue(instance.withCalendar(calendar).equals("2000-05-02"), false, "different calendar");

View File

@ -4,27 +4,31 @@
/*---
esid: sec-temporal.plaindate.protoype.equals
description: test if the calendar is compared
includes: [temporalHelpers.js]
features: [Temporal]
---*/
class CalendarTraceToString extends Temporal.Calendar {
class CalendarTraceId extends Temporal.Calendar {
constructor(id) {
super("iso8601");
this.id_ = id;
this.calls = 0;
}
toString() {
get id() {
++this.calls;
return this.id_;
}
toString() {
TemporalHelpers.assertUnreachable('toString should not be called');
}
};
const calendar1 = new CalendarTraceToString("a");
const calendar1 = new CalendarTraceId("a");
const date1 = new Temporal.PlainDate(1914, 2, 23, calendar1);
const calendar2 = new CalendarTraceToString("b");
const calendar2 = new CalendarTraceId("b");
const date2 = new Temporal.PlainDate(1914, 2, 23, calendar2);
assert.sameValue(date1.equals(date2), false, "different calendars");
assert.sameValue(calendar1.calls, 1, "calendar1 toString() calls");
assert.sameValue(calendar2.calls, 1, "calendar2 toString() calls");
assert.sameValue(calendar1.calls, 1, "calendar1 id getter calls");
assert.sameValue(calendar2.calls, 1, "calendar2 id getter calls");

View File

@ -4,6 +4,7 @@
/*---
esid: sec-temporal.plaindate.protoype.equals
description: test if the calendar is compared
includes: [temporalHelpers.js]
features: [Temporal]
---*/
@ -13,10 +14,13 @@ class CalendarTraceToString extends Temporal.Calendar {
this.id_ = id;
this.calls = 0;
}
toString() {
get id() {
++this.calls;
return this.id_;
}
toString() {
TemporalHelpers.assertUnreachable('toString should not be called');
}
};
const calendar1 = new CalendarTraceToString("a");
@ -26,5 +30,5 @@ const calendar2 = new CalendarTraceToString("a");
const date2 = new Temporal.PlainDate(1914, 2, 23, calendar2);
assert.sameValue(date1.equals(date2), true, "same calendar id");
assert.sameValue(calendar1.calls, 1, "calendar1 toString() calls");
assert.sameValue(calendar2.calls, 1, "calendar2 toString() calls");
assert.sameValue(calendar1.calls, 1, "calendar1 id getter calls");
assert.sameValue(calendar2.calls, 1, "calendar2 id getter calls");

View File

@ -3,12 +3,12 @@
/*---
esid: sec-temporal.plaindate.prototype.since
description: RangeError thrown if calendars' toString results do not match
description: RangeError thrown if calendars' id properties do not match
features: [Temporal]
---*/
const calendar1 = { toString() { return "A"; } };
const calendar2 = { toString() { return "B"; } };
const calendar1 = { id: "A" };
const calendar2 = { id: "B" };
const plainDate1 = new Temporal.PlainDate(2000, 1, 1, calendar1);
const plainDate2 = new Temporal.PlainDate(2000, 1, 1, calendar2);

View File

@ -29,12 +29,8 @@ const expected = [
"get other.calendar.dateFromFields",
"call other.calendar.dateFromFields",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -4,14 +4,18 @@
/*---
esid: sec-temporal.plaindate.protoype.tostring
description: Number of observable 'toString' calls on the calendar for each value of calendarName
includes: [temporalHelpers.js]
features: [Temporal]
---*/
let calls;
const customCalendar = {
toString() {
get id() {
++calls;
return "custom";
},
toString() {
TemporalHelpers.assertUnreachable('toString should not be called');
}
};
const date = new Temporal.PlainDate(2000, 5, 2, customCalendar);
@ -24,6 +28,6 @@ const date = new Temporal.PlainDate(2000, 5, 2, customCalendar);
].forEach(([calendarName, expectedResult, expectedCalls]) => {
calls = 0;
const result = date.toString({ calendarName });
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
assert.sameValue(result, expectedResult, `id for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to id getter for calendarName = ${calendarName}`);
});

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "2000-05-02[u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-02[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05-02[u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-02[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-02[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05-02[u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-02[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "2000-05-02", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-02[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05-02", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-02[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-02[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05-02", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-02[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -11,10 +11,10 @@ features: [Temporal]
const tests = [
[[], "2000-05-02[!u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-02[!u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05-02[!u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-02[!u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02[!u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-02[!u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05-02[!u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-02[!u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-02[!u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "2000-05-02", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-02", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05-02", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-02", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-02", "custom"],
[[{ id: "iso8601" }], "2000-05-02", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-02", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-02", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,10 +16,10 @@ features: [Temporal]
const tests = [
[[], "2000-05-02", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-02[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05-02", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-02[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-02[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05-02", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-02[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-02[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,7 +16,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const date = new Temporal.PlainDate(2000, 5, 2, calendar);

View File

@ -8,7 +8,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const date1 = new Temporal.PlainDate(2000, 5, 2);
const date2 = new Temporal.PlainDate(2000, 5, 2, calendar);

View File

@ -12,9 +12,7 @@ const expected = [
"get options.calendarName",
"get options.calendarName.toString",
"call options.calendarName.toString",
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get this.calendar.id",
];
const actual = [];

View File

@ -3,12 +3,12 @@
/*---
esid: sec-temporal.plaindate.prototype.until
description: RangeError thrown if calendars' toString results do not match
description: RangeError thrown if calendars' id properties do not match
features: [Temporal]
---*/
const calendar1 = { toString() { return "A"; } };
const calendar2 = { toString() { return "B"; } };
const calendar1 = { id: "A" };
const calendar2 = { id: "B" };
const plainDate1 = new Temporal.PlainDate(2000, 1, 1, calendar1);
const plainDate2 = new Temporal.PlainDate(2000, 1, 1, calendar2);

View File

@ -29,12 +29,8 @@ const expected = [
"get other.calendar.dateFromFields",
"call other.calendar.dateFromFields",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -9,26 +9,38 @@ features: [Temporal]
---*/
const actual = [];
const calendar1 = TemporalHelpers.toPrimitiveObserver(actual, "A", "calendar1");
const calendar2 = TemporalHelpers.toPrimitiveObserver(actual, "A", "calendar2");
const calendar3 = TemporalHelpers.toPrimitiveObserver(actual, "B", "calendar3");
function makeCalendar(id, objectName) {
const calendar = {};
TemporalHelpers.observeProperty(actual, calendar, "id", id, objectName);
return calendar;
}
const calendar1 = makeCalendar("A", "calendar1");
const calendar2 = makeCalendar("A", "calendar2");
const calendar3 = makeCalendar("B", "calendar3");
const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar1);
const dt1b = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar1);
const dt2 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar2);
const dt3 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar3);
actual.splice(0); // disregard the HasProperty checks done in the constructor
assert.sameValue(dt1.equals(dt1b), true, "same calendar object");
assert.compareArray(actual, []);
assert.sameValue(dt1.equals(dt2), true, "same calendar string");
assert.compareArray(actual, ["get calendar1.toString", "call calendar1.toString", "get calendar2.toString", "call calendar2.toString"]);
assert.compareArray(actual, ["get calendar1.id", "get calendar2.id"]);
actual.splice(0); // empty it for the next check
assert.sameValue(dt1.equals(dt3), false, "different calendar string");
assert.compareArray(actual, ["get calendar1.toString", "call calendar1.toString", "get calendar3.toString", "call calendar3.toString"]);
assert.compareArray(actual, ["get calendar1.id", "get calendar3.id"]);
const calendar4 = { toString() { throw new Test262Error("should not call calendar4.toString") } };
const calendar5 = { toString() { throw new Test262Error("should not call calendar5.toString") } };
const calendar4 = {
get id() { TemporalHelpers.assertUnreachable('should not get calendar4.id'); },
};
const calendar5 = {
get id() { TemporalHelpers.assertUnreachable('should not get calendar5.id'); },
};
const dt4 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar4);
const dt5 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, calendar4);
const dt6 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, calendar5);

View File

@ -8,7 +8,7 @@ features: [Temporal]
---*/
const dt1 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0);
const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, {});
const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, { id: "custom" });
assert.throws(
RangeError,

View File

@ -47,12 +47,8 @@ const expected = [
"get other.calendar.dateFromFields",
"call other.calendar.dateFromFields",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -4,14 +4,18 @@
/*---
esid: sec-temporal.plaindatetime.protoype.tostring
description: Number of observable 'toString' calls on the calendar for each value of calendarName
includes: [temporalHelpers.js]
features: [Temporal]
---*/
let calls;
const customCalendar = {
toString() {
get id() {
++calls;
return "custom";
},
toString() {
TemporalHelpers.assertUnreachable('toString should not be called');
}
};
const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, customCalendar);
@ -24,6 +28,6 @@ const date = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, c
].forEach(([calendarName, expectedResult, expectedCalls]) => {
calls = 0;
const result = date.toString({ calendarName });
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
assert.sameValue(result, expectedResult, `id for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to id getter for calendarName = ${calendarName}`);
});

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "1976-11-18T15:23:00[u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00[u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1976-11-18T15:23:00[u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "1976-11-18T15:23:00", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1976-11-18T15:23:00", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -11,10 +11,10 @@ features: [Temporal]
const tests = [
[[], "1976-11-18T15:23:00[!u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[!u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00[!u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[!u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[!u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1976-11-18T15:23:00[!u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1976-11-18T15:23:00[!u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1976-11-18T15:23:00[!u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1976-11-18T15:23:00[!u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "1976-11-18T15:23:00", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00", "custom"],
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00", "custom with dotless i toString"],
[[{ id: "custom" }], "1976-11-18T15:23:00", "custom"],
[[{ id: "iso8601" }], "1976-11-18T15:23:00", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1976-11-18T15:23:00", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1976-11-18T15:23:00", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,10 +16,10 @@ features: [Temporal]
const tests = [
[[], "1976-11-18T15:23:00", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1976-11-18T15:23:00", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1976-11-18T15:23:00[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1976-11-18T15:23:00", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1976-11-18T15:23:00[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1976-11-18T15:23:00[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,7 +16,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);

View File

@ -8,7 +8,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const datetime1 = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 650, 0);
const datetime2 = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 650, 0, calendar);

View File

@ -21,9 +21,7 @@ const expected = [
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get this.calendar.id",
];
const actual = [];
@ -55,9 +53,7 @@ const expectedForFractionalSecondDigits = [
"get options.roundingMode.toString",
"call options.roundingMode.toString",
"get options.smallestUnit",
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get this.calendar.id",
];
instance.toString(

View File

@ -8,7 +8,7 @@ features: [Temporal]
---*/
const dt1 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0);
const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, {});
const dt2 = new Temporal.PlainDateTime(2000, 1, 1, 0, 0, 0, 0, 0, 0, { id: "custom" });
assert.throws(
RangeError,

View File

@ -47,12 +47,8 @@ const expected = [
"get other.calendar.dateFromFields",
"call other.calendar.dateFromFields",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -9,13 +9,14 @@ includes: [temporalHelpers.js]
---*/
const cal1 = {
toString() { return "this is a string"; },
id: "this is a string",
toString() { return "this is another string"; }
};
const cal2 = {
id: 'thisisnotiso',
id: "this is a string",
era() { return undefined; },
eraYear() { return undefined; },
toString() { return "this is a string"; },
toString() { return "thisisnotiso"; },
year() { return 2008; },
month() { return 9; },
monthCode() { return "M09"; },

View File

@ -9,19 +9,20 @@ features: [Temporal]
---*/
const expected = [
"get calendar a.toString",
"call calendar a.toString",
"get calendar b.toString",
"call calendar b.toString",
"get calendar a.id",
"get calendar b.id",
];
const actual = [];
const calendar = (id) => {
return TemporalHelpers.toPrimitiveObserver(actual, id, `calendar ${id}`);
const c = {};
TemporalHelpers.observeProperty(actual, c, "id", id, `calendar ${id}`);
return c;
};
const mdA = new Temporal.PlainMonthDay(2, 7, calendar("a"));
const mdB = new Temporal.PlainMonthDay(2, 7, calendar("b"));
const mdC = new Temporal.PlainMonthDay(2, 7, calendar("c"), 1974);
actual.splice(0); // disregard the HasProperty checks done in the constructor
assert.sameValue(mdA.equals(mdC), false, "different year");
assert.compareArray(actual, [], "Should not check calendar");

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "05-02"],
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]"],
[[{ toString() { return "iso8601"; } }], "05-02"],
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]"],
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i
[[{ id: "custom" }], "1972-05-02[u-ca=custom]"],
[[{ id: "iso8601" }], "05-02"],
[[{ id: "ISO8601" }], "1972-05-02[u-ca=ISO8601]"],
[[{ id: "\u0131so8601" }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i
];
const options = {
get calendarName() {

View File

@ -11,7 +11,7 @@ features: [Temporal]
// the calendar is not ISO 8601
class NotISO extends Temporal.Calendar {
constructor() { super("iso8601"); }
toString() { return "not-iso"; }
get id() { return "not-iso"; }
}
const calendar = new NotISO();

View File

@ -4,14 +4,18 @@
/*---
esid: sec-temporal.plainmonthday.protoype.tostring
description: Number of observable 'toString' calls on the calendar for each value of calendarName
includes: [temporalHelpers.js]
features: [Temporal]
---*/
let calls;
const customCalendar = {
toString() {
get id() {
++calls;
return "custom";
},
toString() {
TemporalHelpers.assertUnreachable('toString should not be called');
}
};
const monthday = new Temporal.PlainMonthDay(5, 2, customCalendar);
@ -24,6 +28,6 @@ const monthday = new Temporal.PlainMonthDay(5, 2, customCalendar);
].forEach(([calendarName, expectedResult, expectedCalls]) => {
calls = 0;
const result = monthday.toString({ calendarName });
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
assert.sameValue(result, expectedResult, `id for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to id getter for calendarName = ${calendarName}`);
});

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "1972-05-02[u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1972-05-02[u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1972-05-02[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1972-05-02[u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1972-05-02[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "05-02", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "05-02", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1972-05-02[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "05-02", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1972-05-02[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -11,10 +11,10 @@ features: [Temporal]
const tests = [
[[], "1972-05-02[!u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1972-05-02[!u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1972-05-02[!u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1972-05-02[!u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[!u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1972-05-02[!u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1972-05-02[!u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1972-05-02[!u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1972-05-02[!u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "05-02", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1972-05-02", "custom"],
[[{ toString() { return "iso8601"; } }], "05-02", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1972-05-02", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02", "custom with dotless i toString"],
[[{ id: "custom" }], "1972-05-02", "custom"],
[[{ id: "iso8601" }], "05-02", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1972-05-02", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1972-05-02", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,10 +16,10 @@ features: [Temporal]
const tests = [
[[], "05-02", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "05-02", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1972-05-02[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "05-02", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1972-05-02[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1972-05-02[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,7 +16,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const monthday = new Temporal.PlainMonthDay(5, 2, calendar);

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "05-02"],
[[{ toString() { return "custom"; } }], "1972-05-02[u-ca=custom]"],
[[{ toString() { return "iso8601"; } }], "05-02"],
[[{ toString() { return "ISO8601"; } }], "1972-05-02[u-ca=ISO8601]"],
[[{ toString() { return "\u0131so8601"; } }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i
[[{ id: "custom" }], "1972-05-02[u-ca=custom]"],
[[{ id: "iso8601" }], "05-02"],
[[{ id: "ISO8601" }], "1972-05-02[u-ca=ISO8601]"],
[[{ id: "\u0131so8601" }], "1972-05-02[u-ca=\u0131so8601]"], // dotless i
];
for (const [args, expected] of tests) {

View File

@ -12,9 +12,7 @@ const expected = [
"get options.calendarName",
"get options.calendarName.toString",
"call options.calendarName.toString",
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get this.calendar.id",
];
const actual = [];

View File

@ -11,7 +11,7 @@ features: [Temporal]
// the calendar is not ISO 8601
class NotISO extends Temporal.Calendar {
constructor() { super("iso8601"); }
toString() { return "not-iso"; }
get id() { return "not-iso"; }
}
const calendar = new NotISO();

View File

@ -4,7 +4,7 @@
/*---
esid: sec-temporal.plainyearmonth.prototype.equals
description: equals() takes the calendar into account
includes: [compareArray.js]
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
@ -14,10 +14,13 @@ class CustomCalendar extends Temporal.Calendar {
super("iso8601");
this._id = id;
}
toString() {
get id() {
actual.push(this._id);
return this._id;
}
toString() {
TemporalHelpers.assertUnreachable("should not call toString");
}
}
const sharedCalendar = new CustomCalendar("a");

View File

@ -11,8 +11,8 @@ class customCal extends Temporal.Calendar {
constructor () {
super('iso8601');
}
toString() {
get id() {
return "I am a secret cal.";
}
}

View File

@ -26,12 +26,8 @@ const expected = [
"get other.calendar.yearMonthFromFields",
"call other.calendar.yearMonthFromFields",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -4,14 +4,18 @@
/*---
esid: sec-temporal.plainyearmonth.protoype.tostring
description: Number of observable 'toString' calls on the calendar for each value of calendarName
includes: [temporalHelpers.js]
features: [Temporal]
---*/
let calls;
const customCalendar = {
toString() {
get id() {
++calls;
return "custom";
},
toString() {
TemporalHelpers.assertUnreachable('toString should not be called');
}
};
const yearmonth = new Temporal.PlainYearMonth(2000, 5, customCalendar);
@ -24,6 +28,6 @@ const yearmonth = new Temporal.PlainYearMonth(2000, 5, customCalendar);
].forEach(([calendarName, expectedResult, expectedCalls]) => {
calls = 0;
const result = yearmonth.toString({ calendarName });
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
assert.sameValue(result, expectedResult, `id for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to id getter for calendarName = ${calendarName}`);
});

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "2000-05-01[u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-01[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05-01[u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-01[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-01[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05-01[u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-01[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "2000-05", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-01[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-01[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-01[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-01[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -11,10 +11,10 @@ features: [Temporal]
const tests = [
[[], "2000-05-01[!u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-01[!u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05-01[!u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-01[!u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01[!u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-01[!u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05-01[!u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-01[!u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-01[!u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "2000-05", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-01", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-01", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-01", "custom"],
[[{ id: "iso8601" }], "2000-05", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-01", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-01", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,10 +16,10 @@ features: [Temporal]
const tests = [
[[], "2000-05", "built-in ISO"],
[[{ toString() { return "custom"; } }], "2000-05-01[u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "2000-05", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "2000-05-01[u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "2000-05-01[u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "2000-05", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "2000-05-01[u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "2000-05-01[u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,7 +16,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const yearmonth = new Temporal.PlainYearMonth(2000, 5, calendar);

View File

@ -8,7 +8,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const yearmonth1 = new Temporal.PlainYearMonth(2000, 5);
const yearmonth2 = new Temporal.PlainYearMonth(2000, 5, calendar);

View File

@ -12,9 +12,7 @@ const expected = [
"get options.calendarName",
"get options.calendarName.toString",
"call options.calendarName.toString",
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get this.calendar.id",
];
const actual = [];

View File

@ -11,8 +11,8 @@ class customCal extends Temporal.Calendar {
constructor () {
super('iso8601');
}
toString() {
get id() {
return "I am a secret cal.";
}
}

View File

@ -26,12 +26,8 @@ const expected = [
"get other.calendar.yearMonthFromFields",
"call other.calendar.yearMonthFromFields",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -65,12 +65,8 @@ const expected = [
"get other.timeZone.toString",
"call other.timeZone.toString",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
];
const actual = [];

View File

@ -56,12 +56,8 @@ const expected = [
"get other.timeZone.getOffsetNanosecondsFor",
"call other.timeZone.getOffsetNanosecondsFor",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -4,14 +4,18 @@
/*---
esid: sec-temporal.zoneddatetime.protoype.tostring
description: Number of observable 'toString' calls on the calendar for each value of calendarName
includes: [temporalHelpers.js]
features: [Temporal]
---*/
let calls;
const customCalendar = {
toString() {
get id() {
++calls;
return "custom";
},
toString() {
TemporalHelpers.assertUnreachable('toString should not be called');
}
};
const date = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", customCalendar);
@ -24,6 +28,6 @@ const date = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", custo
].forEach(([calendarName, expectedResult, expectedCalls]) => {
calls = 0;
const result = date.toString({ calendarName });
assert.sameValue(result, expectedResult, `toString output for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to toString for calendarName = ${calendarName}`);
assert.sameValue(result, expectedResult, `id for calendarName = ${calendarName}`);
assert.sameValue(calls, expectedCalls, `calls to id getter for calendarName = ${calendarName}`);
});

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -11,10 +11,10 @@ features: [Temporal]
const tests = [
[[], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=iso8601]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][!u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -9,10 +9,10 @@ features: [Temporal]
const tests = [
[[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom"],
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with dotless i toString"],
[[{ id: "custom" }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom"],
[[{ id: "iso8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,10 +16,10 @@ features: [Temporal]
const tests = [
[[], "1970-01-01T01:01:01.987654321+00:00[UTC]", "built-in ISO"],
[[{ toString() { return "custom"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
[[{ toString() { return "iso8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 toString"],
[[{ toString() { return "ISO8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps toString"],
[[{ toString() { return "\u0131so8601"; } }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i toString"],
[[{ id: "custom" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=custom]", "custom"],
[[{ id: "iso8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC]", "custom with iso8601 id"],
[[{ id: "ISO8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=ISO8601]", "custom with caps id"],
[[{ id: "\u0131so8601" }], "1970-01-01T01:01:01.987654321+00:00[UTC][u-ca=\u0131so8601]", "custom with dotless i id"],
];
for (const [args, expected, description] of tests) {

View File

@ -16,7 +16,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", calendar);

View File

@ -8,7 +8,7 @@ features: [Temporal]
---*/
const calendar = {
toString() { return "custom"; }
id: "custom",
};
const datetime1 = new Temporal.ZonedDateTime(957270896_987_650_000n, "UTC");
const datetime2 = new Temporal.ZonedDateTime(957270896_987_650_000n, "UTC", calendar);

View File

@ -34,9 +34,7 @@ const expected = [
"get this.timeZone[Symbol.toPrimitive]",
"get this.timeZone.toString",
"call this.timeZone.toString",
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get this.calendar.id",
];
const actual = [];
@ -84,9 +82,7 @@ const expectedForFractionalSecondDigits = [
"get this.timeZone[Symbol.toPrimitive]",
"get this.timeZone.toString",
"call this.timeZone.toString",
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get this.calendar.id",
];
instance.toString(

View File

@ -56,12 +56,8 @@ const expected = [
"get other.timeZone.getOffsetNanosecondsFor",
"call other.timeZone.getOffsetNanosecondsFor",
// CalendarEquals
"get this.calendar[Symbol.toPrimitive]",
"get this.calendar.toString",
"call this.calendar.toString",
"get other.calendar[Symbol.toPrimitive]",
"get other.calendar.toString",
"call other.calendar.toString",
"get this.calendar.id",
"get other.calendar.id",
// CopyDataProperties
"ownKeys options",
"getOwnPropertyDescriptor options.roundingIncrement",

View File

@ -9,13 +9,14 @@ includes: [temporalHelpers.js]
---*/
const cal1 = {
toString() { return "this is a string"; },
id: "this is a string",
toString() { return "this is a another string"; },
};
const cal2 = {
id: 'thisisnotiso',
id: "this is a string",
era() { return "the era"; },
eraYear() { return 1909; },
toString() { return "this is a string"; },
toString() { return "thisisnotiso"; },
year() { return 2008; },
month() { return 9; },
monthCode() { return "M09"; },

View File

@ -10,7 +10,10 @@ includes: [temporalHelpers.js]
let calls = 0;
const cal = {
id: 'thisisnotiso',
get id() {
++calls;
return "thisisnotiso";
},
era() { return "the era"; },
eraYear() { return 1909; },
toString() {
@ -39,4 +42,4 @@ assert.sameValue(
cal,
"calendar is unchanged with same calendars (2)"
);
assert.sameValue(calls, 0, "should not have called cal.toString()");
assert.sameValue(calls, 0, "should not have called cal.toString() or accessed cal.id");

View File

@ -15,7 +15,7 @@ assert.throws(TypeError, () => inst.toZonedDateTime());
// throws with a string parameter
assert.throws(TypeError, () => inst.toZonedDateTime("UTC"));
var fakeGregorian = { toString() { return "gregory"; }};
var fakeGregorian = { id: "gregory" };
// time zone parameter UTC
var timeZone = Temporal.TimeZone.from("UTC");

View File

@ -11,6 +11,9 @@ class SeasonCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
get id() {
return "season";
}
toString() {
return "season";
}

View File

@ -11,6 +11,9 @@ class CenturyCalendar extends Temporal.Calendar {
constructor() {
super("iso8601");
}
get id() {
return 'century';
}
toString() {
return "century";
}

View File

@ -37,6 +37,7 @@ function isoToDecimal(date) {
};
}
var obj = {
id: 'decimal',
toString() {
return "decimal";
},

View File

@ -50,7 +50,7 @@ assert.throws(RangeError, () => Temporal.TimeZone.from("2020-05-26T16:02:46.2511
assert.sameValue(obj.getOffsetStringFor(inst), "-00:00:01.111111111")
// converts to DateTime
var fakeGregorian = { toString() { return "gregory"; }};
var fakeGregorian = { id: "gregory" };
assert.sameValue(`${ obj.getPlainDateTimeFor(inst) }`, "1969-12-31T23:59:58.888888889");
assert.sameValue(`${ obj.getPlainDateTimeFor(inst, fakeGregorian) }`, "1969-12-31T23:59:58.888888889[u-ca=gregory]");

View File

@ -32,7 +32,7 @@ var zdt = new Temporal.ZonedDateTime(0n, obj);
assert.sameValue(zdt.toString(), "1970-01-01T00:00:00+00:00[Etc/Custom/UTC_Protocol]");
// works in Temporal.Now
var fakeGregorian = { toString() { return "gregory"; }};
var fakeGregorian = { id: "gregory" };
assert(Temporal.Now.plainDateTimeISO(obj) instanceof Temporal.PlainDateTime);
assert(Temporal.Now.plainDateTime(fakeGregorian, obj) instanceof Temporal.PlainDateTime);
assert(Temporal.Now.plainDateISO(obj) instanceof Temporal.PlainDate);

View File

@ -88,7 +88,7 @@ assert.throws(RangeError, () => Temporal.TimeZone.from("2020-05-26T16:02:46.2511
assert.sameValue(obj.getOffsetStringFor(inst), "+00:00")
// converts to DateTime
var fakeGregorian = { toString() { return "gregory"; }};
var fakeGregorian = { id: "gregory" };
assert.sameValue(`${ obj.getPlainDateTimeFor(inst) }`, "1970-01-01T00:00:00");
assert.sameValue(`${ obj.getPlainDateTimeFor(inst, fakeGregorian) }`, "1970-01-01T00:00:00[u-ca=gregory]");

View File

@ -66,7 +66,7 @@ var fakeGregorian = {
daysInYear(date) { return date.withCalendar("iso8601").daysInYear; },
monthsInYear(date) { return date.withCalendar("iso8601").monthsInYear; },
inLeapYear(date) { return date.withCalendar("iso8601").inLeapYear; },
toString() { return "gregory"; },
id: "gregory",
};
var fakeVienna = {
getOffsetNanosecondsFor() { return 3600_000_000_000; },

View File

@ -13,7 +13,7 @@ var tz = {
};
var cal = {
dateFromFields(...args) { return Temporal.Calendar.from("iso8601").dateFromFields(...args); },
toString() { return "gregory"; },
id: "gregory",
fields(fieldNames) { return fieldNames; },
};
var zdt = new Temporal.ZonedDateTime(0n, tz, cal);

View File

@ -87,7 +87,7 @@ assert.notSameValue(monthsDifference.months, 0);
// no two different calendars
var zdt1 = new Temporal.ZonedDateTime(0n, "UTC");
var fakeJapanese = { toString() { return "japanese"; }};
var fakeJapanese = { id: "japanese" };
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", fakeJapanese);
assert.throws(RangeError, () => zdt1.since(zdt2));

View File

@ -14,7 +14,7 @@ var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTim
assert.sameValue(`${ zdt.toPlainDate() }`, "2019-10-29");
// preserves the calendar
const fakeGregorian = { toString() { return "gregory" }};
const fakeGregorian = { id: 'gregory' };
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({
timeZone: tz,
calendar: fakeGregorian

View File

@ -15,6 +15,7 @@ assert.sameValue(`${ zdt.toPlainMonthDay() }`, "10-29");
// preserves the calendar
var fakeGregorian = {
id: 'gregory',
monthDayFromFields(fields) {
var md = Temporal.Calendar.from("iso8601").monthDayFromFields(fields);
var {isoYear, isoMonth, isoDay} = md.getISOFields();
@ -22,7 +23,6 @@ var fakeGregorian = {
},
monthCode(date) { return date.withCalendar("iso8601").monthCode; },
day(date) { return date.withCalendar("iso8601").day; },
toString() { return "gregory"; },
fields(fieldNames) { return fieldNames; },
};
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({

View File

@ -15,6 +15,7 @@ assert.sameValue(`${ zdt.toPlainYearMonth() }`, "2019-10");
// preserves the calendar
var fakeGregorian = {
id: 'gregory',
yearMonthFromFields(fields) {
var ym = Temporal.Calendar.from("iso8601").yearMonthFromFields(fields);
var {isoYear, isoMonth, isoDay} = ym.getISOFields();
@ -22,7 +23,6 @@ var fakeGregorian = {
},
year(date) { return date.withCalendar("iso8601").year; },
monthCode(date) { return date.withCalendar("iso8601").monthCode; },
toString() { return "gregory"; },
fields(fieldNames) { return fieldNames; },
};
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({

View File

@ -9,7 +9,7 @@ features: [Temporal]
---*/
var zdt1 = Temporal.ZonedDateTime.from("1976-11-18T15:23+00:00[UTC]");
var fakeGregorian = { toString() { return "gregory" }};
var fakeGregorian = { id: "gregory" };
// shows offset if offset = auto
assert.sameValue(zdt1.toString({ offset: "auto" }), "1976-11-18T15:23:00+00:00[UTC]");

View File

@ -87,7 +87,7 @@ assert.notSameValue(monthsDifference.months, 0);
// no two different calendars
var zdt1 = new Temporal.ZonedDateTime(0n, "UTC");
var fakeJapanese = { toString() { return "japanese"; }};
var fakeJapanese = { id: "japanese" };
var zdt2 = new Temporal.ZonedDateTime(0n, "UTC", fakeJapanese);
assert.throws(RangeError, () => zdt1.until(zdt2));

View File

@ -10,7 +10,7 @@ features: [Temporal]
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789-08:00[-08:00]");
// zonedDateTime.withCalendar(japanese) works
var cal = { toString() { return "japanese"; }};
var cal = { id: 'japanese', toString() { return 'japanese'; } };
assert.sameValue(`${ zdt.withCalendar(cal) }`, "2019-11-18T15:23:30.123456789-08:00[-08:00][u-ca=japanese]");
// keeps instant and time zone the same

View File

@ -27,7 +27,7 @@ assert.sameValue(`${ zdt.withPlainDate(date) }`, "2020-01-23T03:24:30-08:00[Cust
assert.sameValue(`${ zdt.withPlainDate("2018-09-15") }`, "2018-09-15T03:24:30-08:00[Custom/Spring_Fall]");
// result contains a non-ISO calendar if present in the input
var fakeJapanese = { toString() { return "japanese"; }};
var fakeJapanese = { id: "japanese" };
assert.sameValue(`${ zdt.withCalendar(fakeJapanese).withPlainDate("2008-09-06") }`, "2008-09-06T03:24:30-08:00[Custom/Spring_Fall][u-ca=japanese]");
// calendar is unchanged if input has ISO calendar
@ -35,7 +35,7 @@ var date = new Temporal.PlainDate(2008, 9, 6, fakeJapanese);
assert.sameValue(`${ zdt.withPlainDate(date) }`, "2008-09-06T03:24:30-08:00[Custom/Spring_Fall][u-ca=japanese]");
// throws if both `this` and `other` have a non-ISO calendar
var fakeGregorian = { toString() { return "gregory"; }};
var fakeGregorian = { id: "gregory" };
assert.throws(RangeError, () => zdt.withCalendar(fakeGregorian).withPlainDate(date));
// object must contain at least one correctly-spelled property

View File

@ -8,7 +8,7 @@ features: [Temporal]
---*/
// keeps instant and calendar the same
var fakeGregorian = { toString() { return "gregory"; }};
var fakeGregorian = { id: 'gregory' };
var zdt = Temporal.ZonedDateTime.from("2019-11-18T15:23:30.123456789+01:00[+01:00]").withCalendar(fakeGregorian);
var zdt2 = zdt.withTimeZone("-08:00");
assert.sameValue(zdt.epochNanoseconds, zdt2.epochNanoseconds);