Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,10 @@ const helperChinese = ObjectAssign({}, nonIsoHelperBase, {
},
adjustCalendarDate(calendarDate, cache, overflow = 'constrain', fromLegacyDate = false) {
let { year, month, monthExtra, day, monthCode } = calendarDate;
if (year === undefined) throw new TypeErrorCtor('Missing property: year');
assert(
year !== undefined,
`adjustCalendarDate called on date ${JSONStringify(calendarDate)} with undefined year property`
);
if (fromLegacyDate) {
// Legacy Date output returns a string that's an integer with an optional
// "bis" suffix used only by the Chinese/Dangi calendar to indicate a leap
Expand All @@ -2061,9 +2064,7 @@ const helperChinese = ObjectAssign({}, nonIsoHelperBase, {
const monthCode = CreateMonthCode(month, monthExtra !== undefined);
const months = this.getMonthList(year, cache);
month = months[monthCode];
if (month === undefined) {
throw new RangeErrorCtor(`Unmatched month ${month}${monthExtra || ''} in ${this.id} year ${year}`);
}
assert(month !== undefined, `Unmatched month ${month}${monthExtra || ''} in ${this.id} year ${year}`);
return { year, month, day, monthCode };
} else {
// When called without input coming from legacy Date output,
Expand Down Expand Up @@ -2094,14 +2095,12 @@ const helperChinese = ObjectAssign({}, nonIsoHelperBase, {
day = ES.ConstrainToRange(day, 1, this.maximumMonthLength());
}
monthCode = months[month].monthCode;
if (monthCode === undefined) {
throw new RangeErrorCtor(`Invalid month ${month} in ${this.id} year ${year}`);
}
assert(monthCode !== undefined, `Invalid month ${month} in ${this.id} year ${year}`);
} else {
// Both month and monthCode are present. Make sure they don't conflict.
const months = this.getMonthList(year, cache);
const monthIndex = months[monthCode];
if (!monthIndex) throw new RangeErrorCtor(`Unmatched monthCode ${monthCode} in ${this.id} year ${year}`);
assert(monthIndex, `Unmatched monthCode ${monthCode} in ${this.id} year ${year}`);
if (month !== monthIndex) {
throw new RangeErrorCtor(
`monthCode ${monthCode} doesn't correspond to month ${month} in ${this.id} year ${year}`
Expand Down