ngx-bootstrap
Version:
Native Angular Bootstrap Components
72 lines • 3.45 kB
JavaScript
import { isSameDay, isSameMonth } from '../../chronos/utils/date-getters';
import { isAfter, isBefore } from '../../chronos/utils/date-compare';
import { isMonthDisabled } from '../utils/bs-calendar-utils';
import { shiftDate } from '../../chronos/utils/date-setters';
export function flagDaysCalendar(formattedMonth, options) {
formattedMonth.weeks.forEach(function (week, weekIndex) {
week.days.forEach(function (day, dayIndex) {
// datepicker
var isOtherMonth = !isSameMonth(day.date, formattedMonth.month);
var isHovered = !isOtherMonth && isSameDay(day.date, options.hoveredDate);
// date range picker
var isSelectionStart = !isOtherMonth &&
options.selectedRange &&
isSameDay(day.date, options.selectedRange[0]);
var isSelectionEnd = !isOtherMonth &&
options.selectedRange &&
isSameDay(day.date, options.selectedRange[1]);
var isSelected = (!isOtherMonth && isSameDay(day.date, options.selectedDate)) ||
isSelectionStart ||
isSelectionEnd;
var isInRange = !isOtherMonth &&
options.selectedRange &&
isDateInRange(day.date, options.selectedRange, options.hoveredDate);
var isDisabled = options.isDisabled ||
isBefore(day.date, options.minDate, 'day') ||
isAfter(day.date, options.maxDate, 'day');
// decide update or not
var newDay = Object.assign({}, day, {
isOtherMonth: isOtherMonth,
isHovered: isHovered,
isSelected: isSelected,
isSelectionStart: isSelectionStart,
isSelectionEnd: isSelectionEnd,
isInRange: isInRange,
isDisabled: isDisabled
});
if (day.isOtherMonth !== newDay.isOtherMonth ||
day.isHovered !== newDay.isHovered ||
day.isSelected !== newDay.isSelected ||
day.isSelectionStart !== newDay.isSelectionStart ||
day.isSelectionEnd !== newDay.isSelectionEnd ||
day.isDisabled !== newDay.isDisabled ||
day.isInRange !== newDay.isInRange) {
week.days[dayIndex] = newDay;
}
});
});
// todo: add check for linked calendars
formattedMonth.hideLeftArrow =
options.isDisabled ||
(options.monthIndex > 0 && options.monthIndex !== options.displayMonths);
formattedMonth.hideRightArrow =
options.isDisabled ||
(options.monthIndex < options.displayMonths &&
options.monthIndex + 1 !== options.displayMonths);
formattedMonth.disableLeftArrow = isMonthDisabled(shiftDate(formattedMonth.month, { month: -1 }), options.minDate, options.maxDate);
formattedMonth.disableRightArrow = isMonthDisabled(shiftDate(formattedMonth.month, { month: 1 }), options.minDate, options.maxDate);
return formattedMonth;
}
function isDateInRange(date, selectedRange, hoveredDate) {
if (!date || !selectedRange[0]) {
return false;
}
if (selectedRange[1]) {
return date > selectedRange[0] && date <= selectedRange[1];
}
if (hoveredDate) {
return date > selectedRange[0] && date <= hoveredDate;
}
return false;
}
//# sourceMappingURL=flag-days-calendar.js.map