Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ngOnInit() {
this.opened = false;
this.date = dateFns.startOfDay(new Date());
this.options = this.options || { theme: 'default', range: 'tm' };
this.initNames();
this.selectRange(this.options.range);
}
public filterData(filter?: any): void {
let actualFilter = filter;
if (this.config.filterConfig.type === 'date' && filter) {
this.activeDateFilter = filter.label || this.labels.customDateRange;
if (filter.startDate && filter.endDate) {
actualFilter = {
min: dateFns.startOfDay(filter.startDate.date),
max: dateFns.startOfDay(dateFns.addDays(dateFns.startOfDay(filter.endDate.date), 1)),
};
} else {
actualFilter = {
min: filter.min ? dateFns.addDays(dateFns.startOfToday(), filter.min) : dateFns.startOfToday(),
max: filter.max ? dateFns.addDays(dateFns.startOfTomorrow(), filter.max) : dateFns.startOfTomorrow(),
};
}
}
if (actualFilter && actualFilter.hasOwnProperty('value')) {
actualFilter = filter.value;
}
if (this.changeTimeout) {
clearTimeout(this.changeTimeout);
}
var isBeforeMin = function (month, minDate, n) {
if (n === void 0) { n = 0; }
return isValid(minDate) ? isBefore(addMonths(startOfDay(month), n), startOfDay(minDate)) : false;
};
var isAfterMax = function (month, maxDate, n) {
export const isDisabled = (config: IDateConfig, date: Date): boolean => {
let min = config.minDate;
let max = config.maxDate;
if (config.page === CALENDAR_VIEWS.DAYS) {
min = startOfDay(min);
max = startOfDay(max);
}
if (config.page === CALENDAR_VIEWS.MONTHS) {
min = startOfMonth(startOfDay(min));
max = endOfMonth(startOfDay(max));
}
if (config.page === CALENDAR_VIEWS.YEARS) {
min = startOfYear(startOfDay(min));
max = startOfYear(startOfDay(max));
}
if (isBefore(date, min)) {
return true;
}
if (isAfter(date, max)) {
return true;
}
if (config.page === CALENDAR_VIEWS.DAYS && config.disabled) {
const { disabled } = config;
if (isArray(disabled)) {
return disabled.includes(startOfDay(date).toISOString());
const isDisabled = (config, date) => {
let min = config.minDate;
let max = config.maxDate;
if (config.page === CALENDAR_VIEWS.DAYS) {
min = startOfDay(min);
max = startOfDay(max);
}
if (config.page === CALENDAR_VIEWS.MONTHS) {
min = startOfMonth(startOfDay(min));
max = endOfMonth(startOfDay(max));
}
if (config.page === CALENDAR_VIEWS.YEARS) {
min = startOfYear(startOfDay(min));
max = startOfYear(startOfDay(max));
}
if (isBefore(date, min)) {
return true;
}
if (isAfter(date, max)) {
return true;
}
max = endOfMonth(startOfDay(max));
}
if (config.page === CALENDAR_VIEWS.YEARS) {
min = startOfYear(startOfDay(min));
max = startOfYear(startOfDay(max));
}
if (isBefore(date, min)) {
return true;
}
if (isAfter(date, max)) {
return true;
}
if (config.page === CALENDAR_VIEWS.DAYS && config.disabled) {
var disabled = config.disabled;
if (isArray(disabled)) {
return disabled.includes(startOfDay(date).toISOString());
}
else if (isFunction(disabled)) {
return disabled({ date: date });
}
}
return false;
};
function lastDays(distance) {
const now = startOfDay(new Date());
const dates = [];
const ranges = [];
const getTime = date => Math.floor(date.getTime() / 1000);
for (let i = -distance; i < 0; i++) {
const day0 = addDays(now, i);
const day1 = addSeconds(addDays(day0, 1), -1);
dates.push(format(day0, "MMM Do, YYYY"));
ranges.push(`${getTime(day0)}_${getTime(day1)}`);
}
return { dates, ranges: ranges.join("-") };
}
function getWeekDay({ date }: { date: Date }): WeekDay {
const today: Date = dateFns.startOfDay(new Date());
return {
date,
isPast: date < today,
isToday: dateFns.isSameDay(date, today),
isFuture: date > today,
isWeekend: WEEKEND_DAY_NUMBERS.indexOf(dateFns.getDay(date)) > -1,
};
}
export function getDayView({ events = [], viewDate, hourSegments, dayStart, dayEnd, eventWidth, segmentHeight }: GetDayViewArgs): DayView {
if (!events) {
events = [];
}
const startOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfDay(viewDate), dayStart.hour), dayStart.minute);
const endOfView: Date = dateFns.setMinutes(
dateFns.setHours(dateFns.startOfMinute(dateFns.endOfDay(viewDate)), dayEnd.hour),
dayEnd.minute,
);
const previousDayEvents: DayViewEvent[] = [];
const dayViewEvents: DayViewEvent[] = getEventsInTimeRange(
getEventsInPeriod({
events: events.filter((event: CalendarEvent) => !event.allDay),
periodStart: startOfView,
periodEnd: endOfView,
}),
dayStart,
dayEnd,
)
.sort((eventA: CalendarEvent, eventB: CalendarEvent) => {