Reputation: 105
I tried to make my datepicker better, but i only managed to enable (first i disabled all) mondays and thursdays but now i have a problem with specific dates. I tried many posibilities but either select 21th in every month or doesn't work at all.
Now im trying to enable that date (2013,04,21) (and later maybe more of them)
$( '#vfb-datum-75' ).datepicker({
beforeShowDay: settings,
});
function settings(date) {
if (date.getDay() == 1)
{ return [true, "","Works"];
} else if (date.getDay() == 4)
{ return [true, "","Works"];
} else if (date.getDate() == (2013,04,21)) <-- this doesn't work
{ return [true, "","Works"];
} else { return [false,"",""];
}}
thanks for help.
Upvotes: 1
Views: 578
Reputation: 5858
You can compare the year, day, and month. Remember that month is zero based.
date.getDate() == 21 && date.getMonth() == 3 && date.getFullYear() == 2013
You can campare the date to another date using this method also.
date - new Date(2013, 3, 21) == 0
BUT, if you are going to grow this function to have 50+ special dates, you might want something a little snappier, and easier to configure.
var specialDays =
{2013 :
{
3 :
{
21 : [true, "", "WORKS"]
},
4 :
{
15 : [true, "", "WORKS"],
17 : [true, "", "WORKS"]
},
},
};
Then in your function:
... else if (!!specialDays[date.getYear()] && !!specialDays[date.getYear()][date.getMonth()] && !!specialDays[date.getYear()][date.getMonth()][date.getDate()]) {
return specialDays[date.getYear()][date.getMonth()][date.getDate()];
}
Upvotes: 2