kaore/CibulCalendar

February 2016 bug

Closed this issue · 4 comments

While modifying an example (examples/addedLanguage.html), set "firstDayOfWeek" to 1 (starting with Monday).
Navigating to February 2016 will display March 13th as not grayed out, untill something is clicked on on the map. Also when clicking on March 12th or 13th, February 12th or 13th respectively will be selected instead.

February 2021 has the same issue, with an additional date, since the month is exactly 4 rows - February 1st is on Monday and there are 28 days.

Fixes I found to work are:

In _getDateFromElement change comparison for dateValue to:

if ( (ulIndex>=4) && (dateValue<15) /*(dateValue<12)*/ ) incMonth = 1;

and in _generateCalendarHTML change comparison for mSi to:

if ((i>27) && (mSi<15) /*&& (mSi<13)*/ ) {

A further useful fix is to change the displayed month when one of the out-of-month days is chosen so it selects the chosen month and displays it next time the calendar is shown.

Add:
this.setDisplayedMonth( new Date(this.selection.begin.getFullYear(), this.selection.begin.getMonth(), 1) );

to the end of _completePreselection (around line 335).

kaore commented

Hi @nmcgann, I'm making the fixes; the last thing is the month toggle when a date from another month is clicked; I tested it out, it felt a bit strange to see the months toggle without clicking on the month navigation controls.. I won't include this at this time, it could maybe be added as a suggestion?

I looked at lots of other datepickers and the default behaviour is either to ignore selecting outside the current month, or to take the selected month as current when the calendar is subsequently viewed (both the jQuery UI and Bootstrap pickers do that).

I think it is a matter of preference, but it seemed odd to me that I'd be looking at February then select a day in March, but when re-viewed the calendar is still showing February.

It would be good to make it optional I think, then it would remain backwards-compatible, but could also behave like other common datepickers if wished.