The bug (or feature, but i hope it's not) was introduced in the 1.8.4 release of jQuery UI (hence the demo posted by D Hoerster works, since it's using the 1.8.2 version). The source of it is on line 8384 in this version hosted by Google. It's the part covering the generation of the actual HTML of the datepicker. It's inside a loop, iterating over each month to be drawn. It reads
var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
Now, drawmonth/year
is the current month being drawn (duh), so it's pretty obvious what's going in. The result is your stated problem - if you select the 17th in one month, selectedDate
will be set to the 17th of every month as you iterate over them and these will be highlighted. Judging by the variable name (selectedDate
) and it's semantic meaning it should instead state
var selectedDate = this._daylightSavingAdjust(new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay));
The funny thing is that this error was also present in the 1.8.2 version, but the code that does the highlighting didn't use it in the previous version. In 1.8.2, highlighting the current date was done like (on line 8446):
(printDate.getTime() == currentDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
and looking at the code, it's clear that it should instead be as it is in the 1.8.4 version (use selectedDate
instead of currentDate
):
(printDate.getTime() == selectedDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
So it's weird there's not any more bugs going on, since
selectedDate
apparently is wrong and is used several places. (And the fact that nothing was wrong in the previous version, despite the wrong variable being used to highlight the current date) I've been looking at this code for too long now, so I don't know whether I'm right or totally wrong anymore. This should nevertheless be a good fundament for people wanting to investigate it further and possibly do a bug report. I'll do it myself eventually when i get the time (and my sanity back)