Monthly Timeline

@Loewi this won’t work, as a move forward in the calendar from Dec to Jan is a move from month 12 to 0, so was - now will be > 1 and this will incorrectly set the month forward an additional month. I used the following (in Typescript):

this.bookingScheduler.attachEvent('onBeforeViewChange', (old_mode: string, old_date: Date, mode: string, date: Date) => {
    const previousMonthSelected: number = old_date.getMonth();
    const currentMonthSelected: number = date.getMonth();
    const isMoveForwardFromDecToJan: boolean = previousMonthSelected === 11 && currentMonthSelected === 0;

    // Going back in month view steps the date back by the number of days in the month that the user is moving back from
    // If the month that the user is moving back from has more days than the month before it, this can skip a month - ensure month is changed correctly
    if ((currentMonthSelected < previousMonthSelected) && !isMoveForwardFromDecToJan) {
            date.setDate(1); // If a month is skipped, the selected date will not be the 1st of the month - reset it to ensure correct setting of the month
            date.setMonth(previousMonthSelected - 1);
    }

    const lastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
    const numDaysInMonth = lastDayOfMonth.getDate();
    this.bookingScheduler.matrix.timeline.x_size = numDaysInMonth;
    this.bookingScheduler.matrix.timeline.x_length = numDaysInMonth;
    this.bookingScheduler.date['timeline_start'] = this.bookingScheduler.date.month_start;
}
1 Like