Skip to content

Commit

Permalink
Merge c9f30e2 into 40c36f9
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato authored Apr 15, 2021
2 parents 40c36f9 + c9f30e2 commit 5defed6
Show file tree
Hide file tree
Showing 144 changed files with 3,290 additions and 435 deletions.
44 changes: 23 additions & 21 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,71 +88,73 @@ export class Calendar {
}
year(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].year(date);
}
month(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (ES.IsTemporalMonthDay(date)) throw new TypeError('use monthCode on PlainMonthDay instead');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].month(date);
}
monthCode(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalYearMonth(date) && !ES.IsTemporalMonthDay(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].monthCode(date);
}
day(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalMonthDay(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].day(date);
}
era(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].era(date);
}
eraYear(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].eraYear(date);
}
dayOfWeek(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].dayOfWeek(date);
}
dayOfYear(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].dayOfYear(date);
}
weekOfYear(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].weekOfYear(date);
}
daysInWeek(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].daysInWeek(date);
}
daysInMonth(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].daysInMonth(date);
}
daysInYear(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].daysInYear(date);
}
monthsInYear(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!HasSlot(date, ISO_YEAR)) date = ES.ToTemporalDate(date);
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].monthsInYear(date);
}
inLeapYear(date) {
if (!ES.IsTemporalCalendar(this)) throw new TypeError('invalid receiver');
if (!ES.IsTemporalYearMonth(date)) date = ES.ToTemporalDate(date);
return impl[GetSlot(this, CALENDAR_ID)].inLeapYear(date);
}
toString() {
Expand All @@ -163,7 +165,7 @@ export class Calendar {
return ES.ToString(this);
}
static from(item) {
return ES.CalendarFrom(item);
return ES.ToTemporalCalendar(item);
}
}

Expand All @@ -178,7 +180,7 @@ impl['iso8601'] = {
let { year, month, day } = fields;
({ year, month, day } = ES.RegulateISODate(year, month, day, overflow));
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
return new TemporalPlainDate(year, month, day, calendar);
return TemporalPlainDate[ES.PrivateCreateMethod](year, month, day, calendar);
},
yearMonthFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
Expand All @@ -187,7 +189,7 @@ impl['iso8601'] = {
let { year, month } = fields;
({ year, month } = ES.RegulateISOYearMonth(year, month, overflow));
const TemporalPlainYearMonth = GetIntrinsic('%Temporal.PlainYearMonth%');
return new TemporalPlainYearMonth(year, month, calendar, /* referenceISODay */ 1);
return TemporalPlainYearMonth[ES.PrivateCreateMethod](year, month, calendar, /* referenceISODay = */ 1);
},
monthDayFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
Expand All @@ -206,7 +208,7 @@ impl['iso8601'] = {
let { month, day, year } = fields;
({ month, day } = ES.RegulateISODate(useYear ? year : referenceISOYear, month, day, overflow));
const TemporalPlainMonthDay = GetIntrinsic('%Temporal.PlainMonthDay%');
return new TemporalPlainMonthDay(month, day, calendar, referenceISOYear);
return TemporalPlainMonthDay[ES.PrivateCreateMethod](month, day, calendar, referenceISOYear);
},
fields(fields) {
return fields;
Expand All @@ -227,7 +229,7 @@ impl['iso8601'] = {
let day = GetSlot(date, ISO_DAY);
({ year, month, day } = ES.AddISODate(year, month, day, years, months, weeks, days, overflow));
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
return new TemporalPlainDate(year, month, day, calendar);
return TemporalPlainDate[ES.PrivateCreateMethod](year, month, day, calendar);
},
dateUntil(one, two, largestUnit) {
return ES.DifferenceISODate(
Expand Down Expand Up @@ -1781,7 +1783,7 @@ const nonIsoGeneralImpl = {
]);
const { year, month, day } = this.helper.calendarToIsoDate(fields, overflow, cache);
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
const result = new TemporalPlainDate(year, month, day, calendar);
const result = TemporalPlainDate[ES.PrivateCreateMethod](year, month, day, calendar);
cache.setObject(result);
return result;
},
Expand All @@ -1798,7 +1800,7 @@ const nonIsoGeneralImpl = {
]);
const { year, month, day } = this.helper.calendarToIsoDate({ ...fields, day: 1 }, overflow, cache);
const TemporalPlainYearMonth = GetIntrinsic('%Temporal.PlainYearMonth%');
const result = new TemporalPlainYearMonth(year, month, calendar, /* referenceISODay = */ day);
const result = TemporalPlainYearMonth[ES.PrivateCreateMethod](year, month, calendar, /* referenceISODay = */ day);
cache.setObject(result);
return result;
},
Expand All @@ -1820,7 +1822,7 @@ const nonIsoGeneralImpl = {
const { year, month, day } = this.helper.monthDayFromFields(fields, overflow, cache);
// `year` is a reference year where this month/day exists in this calendar
const TemporalPlainMonthDay = GetIntrinsic('%Temporal.PlainMonthDay%');
const result = new TemporalPlainMonthDay(month, day, calendar, /* referenceISOYear */ year);
const result = TemporalPlainMonthDay[ES.PrivateCreateMethod](month, day, calendar, /* referenceISOYear = */ year);
cache.setObject(result);
return result;
},
Expand Down Expand Up @@ -1856,7 +1858,7 @@ const nonIsoGeneralImpl = {
const isoAdded = this.helper.calendarToIsoDate(added, 'constrain', cache);
const { year, month, day } = isoAdded;
const TemporalPlainDate = GetIntrinsic('%Temporal.PlainDate%');
const newTemporalObject = new TemporalPlainDate(year, month, day, calendar);
const newTemporalObject = TemporalPlainDate[ES.PrivateCreateMethod](year, month, day, calendar);
// The new object's cache starts with the cache of the old object
const newCache = new OneObjectCache(cache);
newCache.setObject(newTemporalObject);
Expand Down
Loading

0 comments on commit 5defed6

Please sign in to comment.