diff --git a/src/components/ebay-calendar/component.js b/src/components/ebay-calendar/component.js index 8d2071d29..f01ac7792 100644 --- a/src/components/ebay-calendar/component.js +++ b/src/components/ebay-calendar/component.js @@ -143,6 +143,14 @@ export default class extends Marko.Component { // In this case, we leave the tabindex and position as is. This is a fall-through case. } } + while ( + this.state.disableAfter && + this.getMonthDate( + this.state.offset + (input.numMonths || 1) - 1 + ).toISOString() > this.state.disableAfter + ) { + this.state.offset--; + } } /** @@ -240,8 +248,7 @@ export default class extends Marko.Component { getMonthDate(offset) { const baseDate = fromISO(this.state.baseISO); const date = new Date( - baseDate.getUTCFullYear(), - baseDate.getUTCMonth() + offset + Date.UTC(baseDate.getUTCFullYear(), baseDate.getUTCMonth() + offset) ); return date; } @@ -254,11 +261,13 @@ export default class extends Marko.Component { const baseDate = fromISO(this.state.baseISO); return toISO( new Date( - baseDate.getUTCFullYear(), - baseDate.getUTCMonth() + - this.state.offset + - (input.numMonths || 1), - 0 + Date.UTC( + baseDate.getUTCFullYear(), + baseDate.getUTCMonth() + + this.state.offset + + (input.numMonths || 1), + 0 + ) ) ); } @@ -292,7 +301,9 @@ export default class extends Marko.Component { year: "numeric", } ); - return formatter.format(date); + return formatter.format( + new Date(date.getUTCFullYear(), date.getUTCMonth()) + ); } /** diff --git a/src/components/ebay-calendar/index.marko b/src/components/ebay-calendar/index.marko index dcc7ea91b..362bb128b 100644 --- a/src/components/ebay-calendar/index.marko +++ b/src/components/ebay-calendar/index.marko @@ -68,7 +68,7 @@ $ var a11ySeparator = input.a11ySeparator ?? " - "; $ endDate = daysInMonth; - $ var dayISO = toISO(new Date(year, month, day)); + $ var dayISO = toISO(new Date(Date.UTC(year, month, day))); $ var isToday = dayISO === state.todayISO; $ var isSelected = (Array.isArray(input.selected) ? input.selected.some((iso) => iso === dayISO)