kaore/CibulCalendar

Next month skips one when current day-number is not in that next month (solved)

Closed this issue · 2 comments

Hi there ... here some input to to add a fix also ;-)

Today is 30 Jan 2015 and when opening the calender (e.g. using basic.html example) that one is shown. When going to the next month, the calender shows March. So the month Februari is skipped.
Reason is that the next month does not have day 30. Same will happen when it is March 31th and going to April.

Solution seems to be simple by adding this to the initialization in the constructor (e.g. line 88):

    // Select the first day of the month 
    this.options.init = new Date(this.options.init.getFullYear(), this.options.init.getMonth(), 1);

It will set the date to day 1, which should be available in every month.

P.s. I probably should have used a fork and pull request, but I'm kinda new to Git and not sure how to do that.

Needs the same fix in setSelected too (around line 145-ish):

        if ( this.selection && updateMonth ) {
            //fix - force to 1st of month
            this.setDisplayedMonth( new Date(this.selection.begin.getFullYear(), this.selection.begin.getMonth(), 1) );

        } else {

          this._renderSelection( this.selection );

        }

(replaces this.setDisplayedMonth( new Date( this.selection.begin.getTime() ) );)

kaore commented

Thanks!