Home > Software engineering >  jQuery UI Datepicker; Disable second and fourth saturday
jQuery UI Datepicker; Disable second and fourth saturday

Time:09-18

Sorry, I searched a lot in stackoverflow but couldn't find it.
I want to disable Second Saturday, Fourth Saturday of every month. I already have functions in beforeShowDay.
My current beforeShowDay.

beforeShowDay: function(date) {
  var show = true;
  for( var k in holidays){if(date.getDay()==holidays[k]) show=false;}
  return [show];
}

I want to return false for Second & Fourth Saturday too.

CodePudding user response:

I found the following: https://www.codeproject.com/Questions/1067759/How-To-disable-nd-th-saturday-sunday-and-Holiday-d

The useful bit for you is here:

var week = 0 | date.getDate() / 7 //get the week
//check if it's second week or fourth week
if (week == 1 || week == 3) {
  if (day == 6)  { //check for satruday
    return [false];
  }
}

So your script would look like:

beforeShowDay: function(date) {
  var result = [true, "open"];
  var day = date.getDay();
  var week = 0 | date.getDate() / 7;
  $.each(holidays, function(i, holiday){
    if(day == holiday){
      result = [false, "holiday"];
    }
  });
  if ((week == 1 || week == 3) && day == 6) {
    result = [false, "closed"]
  }
  return result;
}
  • Related