Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap datepicker, beforeShowDay and array of disabled dates

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?

like image 746
dease Avatar asked Mar 21 '14 17:03

dease


1 Answers

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'});
like image 160
Justin Paul Paño Avatar answered Oct 20 '22 19:10

Justin Paul Paño