I am trying to use bootstrap datepicker plugin (https://github.com/eternicode/bootstrap-datepicker/blob/release/docs/index.rst) with array of disabled days passed into it.
My code (partial):
var disabled_dates = ["23.03.2014","21.03.2014"];
$("#datepicker").datepicker({
language: "pl",
autoclose: true,
startDate: '+1d',
weekStart: 1,
default: 'dd.mm.yyyy',
beforeShowDay: function(date){
var formattedDate = $.fn.datepicker.DPGlobal.formatDate(date, 'dd.mm.yyyy', 'pl');
if ($.inArray(formattedDate.toString(), disabled_dates) != -1){
return {
enabled : false
};
}
return;
}
});
it works (almost) OK. It disables wrong date. Instead of disabling 23.03.2014 it disabled 24.04.2014. I am not sure where is the issue, on timezone maybe? Any suggestions?
Looking inside the plugin, I found out $.fn.datepicker.DPGlobal.formatDate
returns a UTC-formatted string instead of GMT. Try changing the setting of formattedDate variable to this:
var formattedDate = date.toLocaleDateString('pl',{day:'2-digit',year:'numeric',month:'2-digit'});