Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
select(event: Event, day: Day, fireEvents: boolean) {
Helpers.swallowEvent(event);
if (this.range) {
if (this.weekRangeSelect) {
this.selected = dateFns.startOfWeek(day.date, { weekStartsOn: this.weekStart });
this.selected2 = dateFns.endOfWeek(day.date, { weekStartsOn: this.weekStart });
this.selectedLabel = this.labels.formatDateWithFormat(this.selected, {
month: 'short',
day: '2-digit',
year: 'numeric',
});
this.selected2Label = this.labels.formatDateWithFormat(this.selected2, {
month: 'short',
day: '2-digit',
year: 'numeric',
});
// Make sure to fire this, since we default to the current week selected!
if (!fireEvents && this.weekRangeSelect) {
this.fireRangeSelect();
}
} else if (this.rangeSelectMode === 'startDate') {
buildMonth(start: Date, month: Date) {
// Reset the weeks
this.weeks = [];
// House keeping variables to know when we are done building the month
let done = false,
date = dateFns.startOfWeek(start, { weekStartsOn: this.weekStart }),
monthIndex = date.getMonth(),
count = 0;
while (!done) {
// Build the days for the weeks
this.weeks.push({ days: this.buildWeek(new Date(date.getTime()), month) });
// Increment variables for the next iteration
date = dateFns.addDays(date, 7);
done = count++ > 2 && monthIndex !== date.getMonth();
monthIndex = date.getMonth();
}
}
render({ date, selected }) {
const currentMonth = getMonth(date);
const firstOfMonth = startOfMonth(date);
const firstOfWeek = startOfWeek(firstOfMonth);
this.thead.innerHTML = `
${times(7).map(daysToAdd => `${format(addDays(firstOfWeek, daysToAdd), 'dd')}`).join('')}
`;
this.tbody.innerHTML = `
${times(7).map(daysToAdd => this.renderDay({ currentMonth, selected, date: addDays(firstOfWeek, daysToAdd) })).join('')}
${times(7).map(daysToAdd => this.renderDay({ currentMonth, selected, date: addWeeks(addDays(firstOfWeek, daysToAdd), 1) })).join('')}
${times(7).map(daysToAdd => this.renderDay({ currentMonth, selected, date: addWeeks(addDays(firstOfWeek, daysToAdd), 2) })).join('')}
export const getLowerBound = filter => {
const currentDate = new Date();
switch (filter) {
case "day":
return format(currentDate, "YYYY-MM-DD");
case "week":
return format(startOfWeek(currentDate), "YYYY-MM-DD");
case "month":
return format(startOfMonth(currentDate), "YYYY-MM-DD");
case "year":
return format(startOfYear(currentDate), "YYYY-MM-DD");
default:
return format(currentDate, "YYYY-MM-DD");
}
};
update(): void {
const firstDayOfMonth = startOfMonth(this.fakeValue);
const firstWeek = getISOWeek(firstDayOfMonth);
const firstSunday = startOfWeek(firstDayOfMonth);
this._weeks = range(firstWeek, firstWeek + 6);
this._dates = this.weeks.map((week) => {
return range(0, 7).map((day) => {
return addDays(addWeeks(firstSunday, week - firstWeek), day);
});
});
this._nearlyYears = range(this.year - 5, this.year + 6);
}
function weekdaysMin(): string[] {
const now = new Date();
return eachDay(startOfWeek(now), endOfWeek(now))
.map((day) => format(day, 'dd'));
}
const getDaysInWeek = (firstDayOfWeekIndex: number) => {
const week = [];
const firstDayOfWeek = addDays(startOfWeek(new Date()), firstDayOfWeekIndex);
for (let index = 0; index < 7; index++) {
week.push(addDays(firstDayOfWeek, index));
}
return week;
};
DaysPage.prototype.monthChanged = function (newMonth) {
this.month = newMonth || new Date();
var start = startOfMonth(this.month);
this.pageStart = startOfWeek(startOfMonth(this.month));
if (getDay(start) < 3) {
this.pageStart = addWeeks(this.pageStart, -1);
}
};
DaysPage.prototype.weekTitle = function (week) {
function getOutsideStartDays(day, props) {
var locale = props.locale;
var days = [];
var firstDayOfWeek = startOfWeek(day.date, { locale: locale });
var startDiff = differenceInDays(day.date, firstDayOfWeek);
for (var i = 0; i < startDiff; i++) {
var day_1 = addDays(firstDayOfWeek, i);
var hidden = props.fromMonth && day_1 < props.fromMonth;
var modifiers = { outside: 'start', hidden: hidden };
var dateWithModifiers = new DateWithModifiers(day_1, modifiers, props);
days.push(dateWithModifiers);
}
return days;
}