Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const calendarsList = [-1, 0, 1].map((n) => {
const firstDayOfMonth = toUTCDate(ify, im + n, 1);
const lastDayOfMonthTime = +toUTCDate(ify, im + n + 1, 0);
const key = getKey(firstDayOfMonth);
/**
* NOTE: Return `null` when one of the followings fulfills:-
*
* minTime maxTime
* |--------|--------o--------|--------|
* last day | valid dates | first day
*
* - last day of the month < `minTime` - entire month should be disabled
* - first day of the month > `maxTime` - entire month should be disabled
*/
if (lastDayOfMonthTime < minTime || +firstDayOfMonth > maxTime) {
return {
key,
*/
if (keyCode === KEY_CODES_MAP.PAGE_DOWN || keyCode === KEY_CODES_MAP.PAGE_UP) {
const totalDaysOfMonth = toUTCDate(fy, m + 1, 0).getUTCDate();
if (d > totalDaysOfMonth) {
d = totalDaysOfMonth;
}
}
/** Get next selectable focused date */
const newFocusedDate = getNextSelectableDate({
keyCode,
maxTime,
minTime,
disabledDaysSet,
disabledDatesSet,
focusedDate: toUTCDate(fy, m, d),
});
return newFocusedDate;
}
const handleUpdateMonth = () => {
const calendarsContainer = this.calendarsContainer;
if (null == calendarsContainer) return this.updateComplete;
const dateDate = this._lastSelectedDate || this._selectedDate;
const minDate = this._min!;
const maxDate = this._max!;
const isPreviousMonth = updateType === 'previous';
const newSelectedDate = toUTCDate(
dateDate.getUTCFullYear(),
dateDate.getUTCMonth() + (isPreviousMonth ? -1 : 1),
1);
const newSelectedDateFy = newSelectedDate.getUTCFullYear();
const newSelectedDateM = newSelectedDate.getUTCMonth();
const minDateFy = minDate.getUTCFullYear();
const minDateM = minDate.getUTCMonth();
const maxDateFy = maxDate.getUTCFullYear();
const maxDateM = maxDate.getUTCMonth();
/**
* NOTE: Instead of debouncing/ throttling the animation when switching between
* calendar months, this prevents subsequent animation that can cause an issue
* where a blank calendar comes into view to be queued by ensuring the new updated
default: {
d = 1;
break;
}
}
/**
* NOTE(motss): When updating month and year, check if the value of day exceeds
* the total days of the updated date. If true, then focus the last day of the new month.
* This also applies to the following cases:
*
* - `2020-01-31` -> next month -> `2020-02-31` (invalid) -> fallback to `2020-02-29`
* - `2020-02-29` -> next year -> `2021-02-29` (invalid) -> fallback to `2021-02-28`
*/
if (keyCode === KEY_CODES_MAP.PAGE_DOWN || keyCode === KEY_CODES_MAP.PAGE_UP) {
const totalDaysOfMonth = toUTCDate(fy, m + 1, 0).getUTCDate();
if (d > totalDaysOfMonth) {
d = totalDaysOfMonth;
}
}
/** Get next selectable focused date */
const newFocusedDate = getNextSelectableDate({
keyCode,
maxTime,
minTime,
disabledDaysSet,
disabledDatesSet,
focusedDate: toUTCDate(fy, m, d),
});
return newFocusedDate;
const calendarsList = [-1, 0, 1].map((n) => {
const firstDayOfMonth = toUTCDate(ify, im + n, 1);
const lastDayOfMonthTime = +toUTCDate(ify, im + n + 1, 0);
const key = getKey(firstDayOfMonth);
/**
* NOTE: Return `null` when one of the followings fulfills:-
*
* minTime maxTime
* |--------|--------o--------|--------|
* last day | valid dates | first day
*
* - last day of the month < `minTime` - entire month should be disabled
* - first day of the month > `maxTime` - entire month should be disabled
*/
if (lastDayOfMonthTime < minTime || +firstDayOfMonth > maxTime) {
return {
key,
if (!isDisabledDay) return focusedDate;
let selectableFocusedDateTime = 0;
let selectableFocusedDate = isLessThanMinTime === isMoreThanMaxTime ?
focusedDate : new Date(isLessThanMinTime ? minTime - 864e5 : 864e5 + maxTime);
const fy = selectableFocusedDate.getUTCFullYear();
const m = selectableFocusedDate.getUTCMonth();
let d = selectableFocusedDate.getUTCDate();
while (isDisabledDay) {
if (isLessThanMinTime || (!isMoreThanMaxTime && NEXT_DAY_KEY_CODES_SET.has(keyCode))) d += 1;
if (isMoreThanMaxTime || (!isLessThanMinTime && PREV_DAY_KEY_CODES_SET.has(keyCode))) d -= 1;
selectableFocusedDate = toUTCDate(fy, m, d);
selectableFocusedDateTime = +selectableFocusedDate;
if (!isLessThanMinTime) {
isLessThanMinTime = selectableFocusedDateTime < minTime;
if (isLessThanMinTime) {
selectableFocusedDate = new Date(minTime);
selectableFocusedDateTime = +selectableFocusedDate;
d = selectableFocusedDate.getUTCDate();
}
}
if (!isMoreThanMaxTime) {
isMoreThanMaxTime = selectableFocusedDateTime > maxTime;
if (isMoreThanMaxTime) {
${this._yearList.map(n =>
html`<button class="${classMap({
'year-list-view__list-item': true,
'year--selected': focusedDateFy === n,
})}">
<div>${yearFormat(toUTCDate(n, 0, 1))}</div>
</button>`)
}
* last day | valid dates | first day
*
* - last day of the month < `minTime` - entire month should be disabled
* - first day of the month > `maxTime` - entire month should be disabled
*/
if (lastDayOfMonthTime < minTime || +firstDayOfMonth > maxTime) {
return {
key,
calendar: null,
disabledDatesSet: null,
disabledDaysSet: null,
};
}
const calendarDays = calendar({
dayFormat,
fullDateFormat,
locale,
disabledDates,
disabledDays,
firstDayOfWeek,
max,
min,
showWeekNumber,
weekLabel,
weekNumberType,
selectedDate: firstDayOfMonth,
});
return { ...calendarDays, key };
});
narrowWeekdayFormat,
selectedDate,
disabledDates,
disabledDays,
firstDayOfWeek,
max,
min,
showWeekNumber,
weekLabel,
weekNumberType,
} = options;
const minTime = min == null ? Number.MIN_SAFE_INTEGER : +min;
const maxTime = max == null ? Number.MAX_SAFE_INTEGER : +max;
const weekdays = getWeekdays({
longWeekdayFormat,
narrowWeekdayFormat,
firstDayOfWeek,
showWeekNumber,
weekLabel,
});
const getKey = (date: Date) => [
locale,
date.toJSON(),
disabledDates?.join('_'),
disabledDays?.join('_'),
firstDayOfWeek,
max?.toJSON(),
min?.toJSON(),
showWeekNumber,
weekLabel,