Skip to content

Commit

Permalink
Remove support for nested Temporal calendar property bags
Browse files Browse the repository at this point in the history
Previously, "nested" calendar property bags were unwrapped up to one
level. That is, this object:
{
  calendar: {
     // ...Temporal.Calendar methods
  }
}
would not be considered to implement the Calendar protocol, but would have
its calendar property used instead, if it were passed to an API that
required a Calendar protocol object.

These nested property bags are no longer supported. Discussion:
tc39/proposal-temporal#2104 (comment)

Corresponding normative PR:
tc39/proposal-temporal#2485
  • Loading branch information
ptomato committed Apr 10, 2023
1 parent 52062ed commit a4068a0
Show file tree
Hide file tree
Showing 302 changed files with 593 additions and 3,861 deletions.
20 changes: 4 additions & 16 deletions harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,10 +1475,7 @@ var TemporalHelpers = {
const originalResult = iso8601.dateFromFields(...args);
// Replace the calendar in the result with the call-tracking calendar
const {isoYear, isoMonth, isoDay} = originalResult.getISOFields();
const result = new Temporal.PlainDate(isoYear, isoMonth, isoDay, this);
// Remove the HasProperty check resulting from the above constructor call
assert.sameValue(calls.pop(), `has ${objectName}.calendar`);
return result;
return new Temporal.PlainDate(isoYear, isoMonth, isoDay, this);
},
yearMonthFromFields(...args) {
calls.push(`call ${objectName}.yearMonthFromFields`);
Expand All @@ -1489,10 +1486,7 @@ var TemporalHelpers = {
const originalResult = iso8601.yearMonthFromFields(...args);
// Replace the calendar in the result with the call-tracking calendar
const {isoYear, isoMonth, isoDay} = originalResult.getISOFields();
const result = new Temporal.PlainYearMonth(isoYear, isoMonth, this, isoDay);
// Remove the HasProperty check resulting from the above constructor call
assert.sameValue(calls.pop(), `has ${objectName}.calendar`);
return result;
return new Temporal.PlainYearMonth(isoYear, isoMonth, this, isoDay);
},
monthDayFromFields(...args) {
calls.push(`call ${objectName}.monthDayFromFields`);
Expand All @@ -1503,10 +1497,7 @@ var TemporalHelpers = {
const originalResult = iso8601.monthDayFromFields(...args);
// Replace the calendar in the result with the call-tracking calendar
const {isoYear, isoMonth, isoDay} = originalResult.getISOFields();
const result = new Temporal.PlainMonthDay(isoMonth, isoDay, this, isoYear);
// Remove the HasProperty check resulting from the above constructor call
assert.sameValue(calls.pop(), `has ${objectName}.calendar`);
return result;
return new Temporal.PlainMonthDay(isoMonth, isoDay, this, isoYear);
},
dateAdd(...args) {
calls.push(`call ${objectName}.dateAdd`);
Expand All @@ -1516,10 +1507,7 @@ var TemporalHelpers = {
}
const originalResult = iso8601.dateAdd(...args);
const {isoYear, isoMonth, isoDay} = originalResult.getISOFields();
const result = new Temporal.PlainDate(isoYear, isoMonth, isoDay, this);
// Remove the HasProperty check resulting from the above constructor call
assert.sameValue(calls.pop(), `has ${objectName}.calendar`);
return result;
return new Temporal.PlainDate(isoYear, isoMonth, isoDay, this);
},
id: "iso8601",
};
Expand Down

This file was deleted.

11 changes: 0 additions & 11 deletions test/built-ins/Temporal/Calendar/from/calendar-object-invalid.js

This file was deleted.

This file was deleted.

12 changes: 1 addition & 11 deletions test/built-ins/Temporal/Calendar/from/calendar-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@

/*---
esid: sec-temporal.calendar.from
description: Converting objects to Temporal.Calendar
description: Converting a plain object to Temporal.Calendar gives the same object
features: [Temporal]
---*/

const cal = new Temporal.Calendar("iso8601");
const calFromObject = Temporal.Calendar.from({ calendar: cal });
assert(calFromObject instanceof Temporal.Calendar);
assert.sameValue(calFromObject.id, "iso8601");

const calFromString = Temporal.Calendar.from({ calendar: "iso8601" });
assert(calFromString instanceof Temporal.Calendar);
assert.sameValue(calFromString.id, "iso8601");

const custom = { id: "custom-calendar" };
assert.sameValue(Temporal.Calendar.from({ calendar: custom }), custom);
assert.sameValue(Temporal.Calendar.from(custom), custom);
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ description: Leap second is a valid ISO string for Calendar
features: [Temporal]
---*/

let arg = "2016-12-31T23:59:60";
const result1 = Temporal.Calendar.from(arg);
const arg = "2016-12-31T23:59:60";
const result = Temporal.Calendar.from(arg);
assert.sameValue(
result1.id,
result.id,
"iso8601",
"leap second is a valid ISO string for Calendar"
);

arg = { calendar: "2016-12-31T23:59:60" };
const result2 = Temporal.Calendar.from(arg);
assert.sameValue(
result2.id,
"iso8601",
"leap second is a valid ISO string for Calendar (nested property)"
);
2 changes: 0 additions & 2 deletions test/built-ins/Temporal/Calendar/from/calendar-wrong-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const rangeErrorTests = [

for (const [arg, description] of rangeErrorTests) {
assert.throws(RangeError, () => Temporal.Calendar.from(arg), `${description} does not convert to a valid ISO string`);
assert.throws(RangeError, () => Temporal.Calendar.from({ calendar: arg }), `${description} does not convert to a valid ISO string (in property bag)`);
}

const typeErrorTests = [
Expand All @@ -29,5 +28,4 @@ const typeErrorTests = [

for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => Temporal.Calendar.from(arg), `${description} is not a valid object and does not convert to a string`);
assert.throws(TypeError, () => Temporal.Calendar.from({ calendar: arg }), `${description} is not a valid object and does not convert to a string (in property bag)`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result1, 1976, 11, "M11", 18, "Calendar is case-insensitive");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result2, 1976, 11, "M11", 18, "Calendar is case-insensitive (nested property)");
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "Calendar is case-insensitive");

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "2016-12-31T23:59:60";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateAdd(arg, new Temporal.Duration());
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result1,
result,
1976, 11, "M11", 18,
"leap second is a valid ISO string for calendar"
);

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(
result2,
1976, 11, "M11", 18,
"leap second is a valid ISO string for calendar (nested property)"
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = 19970327;

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result1, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result2 = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result2, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar (nested property)");
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result = instance.dateAdd(arg, new Temporal.Duration());
TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar");

const numbers = [
1,
Expand All @@ -27,16 +23,10 @@ const numbers = [
];

for (const calendar of numbers) {
let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`Number ${calendar} does not convert to a valid ISO string for calendar`
);
arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
assert.throws(
RangeError,
() => instance.dateAdd(arg, new Temporal.Duration()),
`Number ${calendar} does not convert to a valid ISO string for calendar (nested property)`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ const rangeErrorTests = [
];

for (const [calendar, description] of rangeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string`);

arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string (nested property)`);
}

const typeErrorTests = [
Expand All @@ -36,12 +33,6 @@ const typeErrorTests = [
];

for (const [calendar, description] of typeErrorTests) {
let arg = { year: 2019, monthCode: "M11", day: 1, calendar };
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} is not a valid property bag and does not convert to a string`);

arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } };
assert.throws(TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} is not a valid property bag and does not convert to a string (nested property)`);
}

const arg = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar: undefined } };
assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `nested undefined calendar property is always a RangeError`);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ features: [Temporal]
const expected = [
// ToTemporalDate → GetTemporalCalendarWithISODefault
"get date.calendar",
"has date.calendar.calendar",
// ToTemporalDate → CalendarFields
"get date.calendar.fields",
"call date.calendar.fields",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "IsO8601";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (second argument)");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result3 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property, first argument)");
const result4 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result4, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "Calendar is case-insensitive (nested property, second argument)");

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ const instance = new Temporal.Calendar("iso8601");

const calendar = "2016-12-31T23:59:60";

let arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (first argument)");
const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (second argument)");

arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } };
const result3 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19));
TemporalHelpers.assertDuration(result3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (nested property, first argument)");
const result4 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg);
TemporalHelpers.assertDuration(result4, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "leap second is a valid ISO string for calendar (nested property, second argument)");
Loading

0 comments on commit a4068a0

Please sign in to comment.