Skip to content

Commit

Permalink
Replace Temporal objects' .calendar getters with .calendarId/.getCale…
Browse files Browse the repository at this point in the history
…ndar

This is the replacement of the old API with the new API. Semantics will be
corrected in the following commit.

Normative PR: tc39/proposal-temporal#2482
  • Loading branch information
ptomato committed Feb 17, 2023
1 parent 6b1b500 commit 4dda712
Show file tree
Hide file tree
Showing 202 changed files with 1,063 additions and 340 deletions.
24 changes: 16 additions & 8 deletions harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var TemporalHelpers = {
* Shorthand for asserting that each field of a Temporal.PlainDate is equal to
* an expected value. (Except the `calendar` property, since callers may want
* to assert either object equality with an object they put in there, or the
* result of date.calendar.toString().)
* value of date.calendarId.)
*/
assertPlainDate(date, year, month, monthCode, day, description = "", era = undefined, eraYear = undefined) {
assert(date instanceof Temporal.PlainDate, `${description} instanceof`);
Expand All @@ -93,7 +93,7 @@ var TemporalHelpers = {
* Shorthand for asserting that each field of a Temporal.PlainDateTime is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of datetime.calendar.toString().)
* or the value of datetime.calendarId.)
*/
assertPlainDateTime(datetime, year, month, monthCode, day, hour, minute, second, millisecond, microsecond, nanosecond, description = "", era = undefined, eraYear = undefined) {
assert(datetime instanceof Temporal.PlainDateTime, `${description} instanceof`);
Expand All @@ -116,13 +116,17 @@ var TemporalHelpers = {
*
* Shorthand for asserting that two Temporal.PlainDateTimes are of the correct
* type, equal according to their equals() methods, and additionally that
* their calendars are the same value.
* their calendar internal slots are the same value.
*/
assertPlainDateTimesEqual(actual, expected, description = "") {
assert(expected instanceof Temporal.PlainDateTime, `${description} expected value should be a Temporal.PlainDateTime`);
assert(actual instanceof Temporal.PlainDateTime, `${description} instanceof`);
assert(actual.equals(expected), `${description} equals method`);
assert.sameValue(actual.calendar, expected.calendar, `${description} calendar same value`);
assert.sameValue(
actual.getISOFields().calendar,
expected.getISOFields().calendar,
`${description} calendar same value`
);
},

/*
Expand All @@ -131,7 +135,7 @@ var TemporalHelpers = {
* Shorthand for asserting that each field of a Temporal.PlainMonthDay is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of monthDay.calendar.toString().)
* or the value of monthDay.calendarId().)
*/
assertPlainMonthDay(monthDay, monthCode, day, description = "", referenceISOYear = 1972) {
assert(monthDay instanceof Temporal.PlainMonthDay, `${description} instanceof`);
Expand Down Expand Up @@ -174,7 +178,7 @@ var TemporalHelpers = {
* Shorthand for asserting that each field of a Temporal.PlainYearMonth is
* equal to an expected value. (Except the `calendar` property, since callers
* may want to assert either object equality with an object they put in there,
* or the result of yearMonth.calendar.toString().)
* or the value of yearMonth.calendarId.)
*/
assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) {
assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`);
Expand All @@ -191,14 +195,18 @@ var TemporalHelpers = {
*
* Shorthand for asserting that two Temporal.ZonedDateTimes are of the correct
* type, equal according to their equals() methods, and additionally that
* their time zones and calendars are the same value.
* their time zones and calendar internal slots are the same value.
*/
assertZonedDateTimesEqual(actual, expected, description = "") {
assert(expected instanceof Temporal.ZonedDateTime, `${description} expected value should be a Temporal.ZonedDateTime`);
assert(actual instanceof Temporal.ZonedDateTime, `${description} instanceof`);
assert(actual.equals(expected), `${description} equals method`);
assert.sameValue(actual.timeZone, expected.timeZone, `${description} time zone same value`);
assert.sameValue(actual.calendar, expected.calendar, `${description} calendar same value`);
assert.sameValue(
actual.getISOFields().calendar,
expected.getISOFields().calendar,
`${description} calendar same value`
);
},

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT
});

const result = Temporal.Calendar.from(arg);
assert.sameValue(result, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.id, calendar, "Temporal object coerced to calendar");

assert.compareArray(actual, expected, "calendar getter not called");
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ const options = TemporalHelpers.propertyBagObserver(actual, {

const result = instance.dateFromFields(fields, options);
TemporalHelpers.assertPlainDate(result, 1, 1, "M01", 1, "date result");
assert.sameValue(result.calendar, instance, "calendar result");
assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar slot should store a string");
assert.compareArray(actual, expected, "order of operations");
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ const options = TemporalHelpers.propertyBagObserver(actual, {

const result = instance.monthDayFromFields(fields, options);
TemporalHelpers.assertPlainMonthDay(result, "M01", 1, "monthDay result");
assert.sameValue(result.calendar, instance, "calendar result");
assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar slot should store a string");
assert.compareArray(actual, expected, "order of operations");
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ const options = TemporalHelpers.propertyBagObserver(actual, {

const result = instance.yearMonthFromFields(fields, options);
TemporalHelpers.assertPlainYearMonth(result, 1, 1, "M01", "yearMonth result");
assert.sameValue(result.calendar, instance, "calendar result");
assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar slot should store a string");
assert.compareArray(actual, expected, "order of operations");
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var cal = new class extends Temporal.Calendar {
}("iso8601");

var relativeTo = new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, 0, 0, cal);
assert.sameValue(relativeTo.calendar, cal);
assert.sameValue(relativeTo.getCalendar(), cal);

var options = {
smallestUnit: "days",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ const instance = new Temporal.Instant(1_000_000_000_000_000_000n);

const arg = "iSo8601";
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.calendar.id, "iso8601", "Calendar is case-insensitive");
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const arg = 19761118;

const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar");
assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar");

const numbers = [
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
let arg = "2016-12-31T23:59:60";
const result1 = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(
result1.calendar.id,
result1.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

arg = { calendar: "2016-12-31T23:59:60" };
const result2 = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(
result2.calendar.id,
result2.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar (nested property)"
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const arg = "iso8601";

const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.calendar.id, "iso8601", `Calendar created from string "${arg}"`);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT

const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" });
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");

assert.compareArray(actual, expected, "calendar getter not called");
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iSo8601";

const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.calendar.id, "iso8601", "Calendar is case-insensitive");
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");
2 changes: 1 addition & 1 deletion test/built-ins/Temporal/Now/plainDate/calendar-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ features: [Temporal]
const arg = 19761118;

const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar");
assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar");

const numbers = [
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ features: [Temporal]
let arg = "2016-12-31T23:59:60";
const result1 = Temporal.Now.plainDate(arg);
assert.sameValue(
result1.calendar.id,
result1.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

arg = { calendar: "2016-12-31T23:59:60" };
const result2 = Temporal.Now.plainDate(arg);
assert.sameValue(
result2.calendar.id,
result2.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar (nested property)"
);
2 changes: 1 addition & 1 deletion test/built-ins/Temporal/Now/plainDate/calendar-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iso8601";

const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.calendar.id, "iso8601", `Calendar created from string "${arg}"`);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT
});

const result = Temporal.Now.plainDate(arg);
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");

assert.compareArray(actual, expected, "calendar getter not called");
});
2 changes: 1 addition & 1 deletion test/built-ins/Temporal/Now/plainDateISO/return-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ features: [Temporal]

const d = Temporal.Now.plainDateISO();
assert(d instanceof Temporal.PlainDate);
assert.sameValue(d.calendar.id, "iso8601");
assert.sameValue(d.getISOFields().calendar, "iso8601", "calendar slot should store a string");
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iSo8601";

const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.calendar.id, "iso8601", "Calendar is case-insensitive");
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ features: [Temporal]
const arg = 19761118;

const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar");
assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar");

const numbers = [
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ features: [Temporal]
let arg = "2016-12-31T23:59:60";
const result1 = Temporal.Now.plainDateTime(arg);
assert.sameValue(
result1.calendar.id,
result1.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

arg = { calendar: "2016-12-31T23:59:60" };
const result2 = Temporal.Now.plainDateTime(arg);
assert.sameValue(
result2.calendar.id,
result2.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar (nested property)"
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iso8601";

const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.calendar.id, "iso8601", `Calendar created from string "${arg}"`);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT
});

const result = Temporal.Now.plainDateTime(arg);
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");

assert.compareArray(actual, expected, "calendar getter not called");
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ features: [Temporal]
---*/

const result = Temporal.Now.plainDateTimeISO();
assert(result.calendar instanceof Temporal.Calendar);
assert.sameValue(result.calendar.id, "iso8601");
assert.sameValue(result.getISOFields().calendar, "iso8601", "calendar slot should store a string");
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iSo8601";

const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.calendar.id, "iso8601", "Calendar is case-insensitive");
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ features: [Temporal]
const arg = 19761118;

const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar");
assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar");

const numbers = [
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ features: [Temporal]
let arg = "2016-12-31T23:59:60";
const result1 = Temporal.Now.zonedDateTime(arg);
assert.sameValue(
result1.calendar.id,
result1.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

arg = { calendar: "2016-12-31T23:59:60" };
const result2 = Temporal.Now.zonedDateTime(arg);
assert.sameValue(
result2.calendar.id,
result2.calendarId,
"iso8601",
"leap second is a valid ISO string for Calendar (nested property)"
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iso8601";

const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.calendar.id, "iso8601", `Calendar created from string "${arg}"`);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ esid: sec-temporal.now.zoneddatetime
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal-totemporalcalendar step 1.b:
b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
b. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js]
features: [Temporal]
Expand All @@ -32,7 +32,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT
});

const result = Temporal.Now.zonedDateTime(arg);
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");

assert.compareArray(actual, expected, "calendar getter not called");
});
3 changes: 1 addition & 2 deletions test/built-ins/Temporal/Now/zonedDateTimeISO/return-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ features: [Temporal]
const zdt = Temporal.Now.zonedDateTimeISO();
const tz = Temporal.Now.timeZoneId();
assert(zdt instanceof Temporal.ZonedDateTime);
assert(zdt.calendar instanceof Temporal.Calendar);
assert.sameValue(zdt.calendar.id, "iso8601");
assert.sameValue(zdt.getISOFields().calendar, "iso8601", "calendar slot should store a string");
assert(zdt.timeZone instanceof Temporal.TimeZone);
assert.sameValue(zdt.timeZone.id, tz);
6 changes: 3 additions & 3 deletions test/built-ins/Temporal/PlainDate/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Object.defineProperty(Temporal.Calendar, "from", {
const calendar = new Temporal.Calendar("iso8601");
const plainDateWithObject = new Temporal.PlainDate(2020, 12, 24, calendar);
TemporalHelpers.assertPlainDate(plainDateWithObject, 2020, 12, "M12", 24, "with object");
assert.sameValue(plainDateWithObject.calendar, calendar);
assert.sameValue(plainDateWithObject.getCalendar(), calendar);

const plainDateWithString = new Temporal.PlainDate(2020, 12, 24, "iso8601");
TemporalHelpers.assertPlainDate(plainDateWithString, 2020, 12, "M12", 24, "with string");
assert.sameValue(plainDateWithString.calendar.toString(), "iso8601");
assert.notSameValue(plainDateWithString.calendar, calendar);
assert.sameValue(plainDateWithString.getISOFields().calendar, "iso8601", "calendar slot should store a string");
assert.notSameValue(plainDateWithString.getCalendar(), calendar);
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iSo8601";

const result = new Temporal.PlainDate(2000, 5, 2, arg);
assert.sameValue(result.calendar.id, "iso8601", "Calendar is case-insensitive");
assert.sameValue(result.calendarId, "iso8601", "Calendar is case-insensitive");
2 changes: 1 addition & 1 deletion test/built-ins/Temporal/PlainDate/calendar-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ features: [Temporal]
const arg = 19761118;

const result = new Temporal.PlainDate(2000, 5, 2, arg);
assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar");
assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar");

const numbers = [
1,
Expand Down
2 changes: 1 addition & 1 deletion test/built-ins/Temporal/PlainDate/calendar-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ features: [Temporal]
const arg = "iso8601";

const result = new Temporal.PlainDate(2000, 5, 2, arg);
assert.sameValue(result.calendar.id, "iso8601", `Calendar created from string "${arg}"`);
assert.sameValue(result.getISOFields().calendar, "iso8601", `Calendar created from string "${arg}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UT
});

const result = new Temporal.PlainDate(2000, 5, 2, arg);
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
assert.sameValue(result.getISOFields().calendar, calendar, "Temporal object coerced to calendar");

assert.compareArray(actual, expected, "calendar getter not called");
});
4 changes: 2 additions & 2 deletions test/built-ins/Temporal/PlainDate/calendar-undefined.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Object.defineProperty(Temporal.Calendar, "from", {
});

const dateExplicit = new Temporal.PlainDate(...args, undefined);
assert.sameValue(dateExplicit.calendar.toString(), "iso8601");
assert.sameValue(dateExplicit.getISOFields().calendar, "iso8601", "calendar slot should store string");

const dateImplicit = new Temporal.PlainDate(...args);
assert.sameValue(dateImplicit.calendar.toString(), "iso8601");
assert.sameValue(dateImplicit.getISOFields().calendar, "iso8601", "calendar slot should store string");
Loading

0 comments on commit 4dda712

Please sign in to comment.