Skip to content

Commit

Permalink
Remove era from main spec
Browse files Browse the repository at this point in the history
This removes era from Temporal proper, and defines it only the first time
a calendar that uses it is constructed. This is in line with era and other
custom calendar properties being the domain of ECMA-402.

Closes: #1046
  • Loading branch information
ptomato committed Oct 26, 2020
1 parent 72a2c6a commit cb036ae
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 84 deletions.
5 changes: 0 additions & 5 deletions docs/date.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ date.day; // => 24

The `calendar` read-only property gives the calendar that the `year`, `month`, and `day` properties are interpreted in.

### date.**era** : unknown

The `era` read-only property is `undefined` when using the ISO 8601 calendar.
It's used for calendar systems that specify an era in addition to the year.

### date.**dayOfWeek** : number

The `dayOfWeek` read-only property gives the weekday number that the date falls on.
Expand Down
5 changes: 0 additions & 5 deletions docs/datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ dt.nanosecond; // => 500

The `calendar` read-only property gives the calendar that the `year`, `month`, and `day` properties are interpreted in.

### datetime.**era** : unknown

The `era` read-only property is `undefined` when using the ISO 8601 calendar.
It's used for calendar systems that specify an era in addition to the year.

### datetime.**dayOfWeek** : number

The `dayOfWeek` read-only property gives the weekday number that the date falls on.
Expand Down
5 changes: 0 additions & 5 deletions docs/yearmonth.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ ym.month; // => 6

The `calendar` read-only property gives the calendar that the `year` and `month` properties are interpreted in.

### yearmonth.**era** : unknown

The `era` read-only property is `undefined` when using the ISO 8601 calendar.
It's used for calendar systems that specify an era in addition to the year.

### yearMonth.**daysInMonth** : number

The `daysInMonth` read-only property gives the number of days in the month.
Expand Down
23 changes: 15 additions & 8 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ export class Calendar {
void date;
throw new Error('not implemented');
}
era(date) {
void date;
throw new Error('not implemented');
}
dayOfWeek(date) {
void date;
throw new Error('not implemented');
Expand Down Expand Up @@ -243,10 +239,6 @@ class ISO8601Calendar extends Calendar {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
return GetSlot(date, ISO_DAY);
}
era(date) {
void date;
return undefined;
}
dayOfWeek(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
return ES.DayOfWeek(GetSlot(date, ISO_YEAR), GetSlot(date, ISO_MONTH), GetSlot(date, ISO_DAY));
Expand Down Expand Up @@ -287,6 +279,15 @@ MakeIntrinsicClass(ISO8601Calendar, 'Temporal.ISO8601Calendar');
// proposal for ECMA-262. These calendars will be standardized as part of
// ECMA-402.

function addCustomPropertyGetter(type, name) {
Object.defineProperty(GetIntrinsic(`%Temporal.${type}.prototype%`), name, {
get() {
return this.calendar[name](this);
},
configurable: true
});
}

// Implementation details for Gregorian calendar
const gre = {
isoYear(year, era) {
Expand All @@ -300,6 +301,9 @@ const gre = {
class Gregorian extends ISO8601Calendar {
constructor() {
super('gregory');
addCustomPropertyGetter('Date', 'era');
addCustomPropertyGetter('DateTime', 'era');
addCustomPropertyGetter('YearMonth', 'era');
}

era(date) {
Expand Down Expand Up @@ -395,6 +399,9 @@ const jpn = {
class Japanese extends ISO8601Calendar {
constructor() {
super('japanese');
addCustomPropertyGetter('Date', 'era');
addCustomPropertyGetter('DateTime', 'era');
addCustomPropertyGetter('YearMonth', 'era');
}

era(date) {
Expand Down
4 changes: 0 additions & 4 deletions polyfill/lib/date.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export class Date {
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR);
}
get era() {
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR).era(this);
}
get year() {
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR).year(this);
Expand Down
4 changes: 0 additions & 4 deletions polyfill/lib/datetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ export class DateTime {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
return GetSlot(this, NANOSECOND);
}
get era() {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR).era(this);
}
get dayOfWeek() {
if (!ES.IsTemporalDateTime(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR).dayOfWeek(this);
Expand Down
4 changes: 0 additions & 4 deletions polyfill/lib/yearmonth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ export class YearMonth {
if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR);
}
get era() {
if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR).era(this);
}
get daysInMonth() {
if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver');
return GetSlot(this, CALENDAR).daysInMonth(this);
Expand Down
23 changes: 0 additions & 23 deletions polyfill/test/Calendar/prototype/era/length.js

This file was deleted.

3 changes: 0 additions & 3 deletions polyfill/test/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ describe('Calendar', () => {
it('Calendar.prototype.day is a Function', () => {
equal(typeof Calendar.prototype.day, 'function');
});
it('Calendar.prototype.era is a Function', () => {
equal(typeof Calendar.prototype.era, 'function');
});
it('Calendar.prototype.dayOfWeek is a Function', () => {
equal(typeof Calendar.prototype.dayOfWeek, 'function');
});
Expand Down
11 changes: 0 additions & 11 deletions spec/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,6 @@ <h1>Temporal.Calendar.prototype.day ( _date_ )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.calendar.prototype.era">
<h1>Temporal.Calendar.prototype.era ( _date_ )</h1>
<p>
The `era` method takes one argument _date_.
The following steps are taken:
</p>
<emu-alg>
1. Throw an *Error* exception.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.calendar.prototype.dayofweek">
<h1>Temporal.Calendar.prototype.dayOfWeek ( _date_ )</h1>
<p>
Expand Down
12 changes: 0 additions & 12 deletions spec/isocalendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,6 @@ <h1>Temporal.ISO8601Calendar.prototype.day ( _dateOrDateTime_ )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.iso8601calendar.prototype.era">
<h1>Temporal.ISO8601Calendar.prototype.era ( _dateOrDateTime_ )</h1>
<p>
The `era` method takes one argument _dateOrDateTime_.
The following steps are taken:
</p>
<emu-alg>
1. Perform ? RequireOneOfInternalSlots(_dateOrDateTime_, « [[InitializedTemporalDate]], [[InitializedTemporalDateTime]] »).
1. Return *undefined*.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.iso8601calendar.prototype.dayofweek">
<h1>Temporal.ISO8601Calendar.prototype.dayOfWeek ( _dateOrDateTime_ )</h1>
<p>
Expand Down

0 comments on commit cb036ae

Please sign in to comment.