Skip to content Skip to sidebar Skip to footer

How To Skip Holidays From The Set Of Result?

Is it possible to skip Holidays also?? Assume i have set of holiday list in database..holidays will not comes to the result date.I want to skip the holiday date and skip to next da

Solution 1:

You mean this?

functionnth(d)  { if (d > 3 && d < 21) return'th';  switch (d % 10) { case1:  return"st"; case2:  return"nd"; case3:  return"rd"; default: return"th"; } }
functiondateToYMD(date) { var strArray=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; var d = date.getDate(); var m = strArray[date.getMonth()]; var y = date.getFullYear(); return'' + (d <= 9 ? '0' + d : d) + '-' + m + '-' + y; }
Date.prototype.addDays = function(days) { var date = newDate(this.valueOf()); date.setDate(date.getDate() + days); return date; }
functionpad(str) { return (" "+str).slice(-2) }
var cnt = 0, dataSet = [];

functionprintNextPeriod(startDate, endDate, periodInDays) {
  var numWorkDays = 0;
  var currentDate = newDate(startDate);
  while (numWorkDays < periodInDays && currentDate <= endDate) {
    currentDate = currentDate.addDays(1);
    // Skips fridayif (currentDate.getDay() !== 5) {
      numWorkDays++;
    }
    if (numWorkDays == periodInDays) {
      numWorkDays = 0;
      cnt++;
      let date = dateToYMD(currentDate);
      let pos = holidays.indexOf(date);
      if (pos != -1) {
        console.log("replace",date,"with",instead[pos])
        date = instead[pos];
      }  
      let treatment = pad(cnt) + nth(cnt) + (cnt == 1 ? " Basic" : " Control") + " Treatment"
      dataSet.push([date, treatment])
    }
  }
}

var holidays = ["2019-02-07"// Thursday
  , "2019-10-08", "2019-12-17",
  "2019-02-05"// Friday
];
var instead = [];
holidays.forEach((hol,i) => {
  let d = newDate(hol);
  let date = d.getDate() + 1
  d.setDate(date); // next day (could be Weekend);while (d.getDay() === 5) {
    date = d.getDate()
    date++;
    d.setDate(date); // is any day not friday ok?
  }
  instead.push(dateToYMD(d))
  holidays[i] = dateToYMD(newDate(hol))
})
console.log(JSON.stringify(instead))
var start = newDate("2018-12-15");
var end = newDate("2019-12-31");
var period = 15;
printNextPeriod(start, end, period);

$(document).ready(function() {
  $('#example').DataTable({
    data: dataSet,
    columns: [{ title: "Date" },
              {title: "Frequency"}],
    order: [[1, "asc"]]
  });
});
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><linkrel="stylesheet"href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" /><scriptsrc="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script><tableid="example"></div>

Post a Comment for "How To Skip Holidays From The Set Of Result?"