0

I would like to add 10 days to a date excluding holidays and weekends. Here is the code i am using but i am unable to figure out how to take out the holidays and weekends. Thanks for any help!!

var someDate = item.INITIAL_REQUEST; 
var numberOfDaysToAdd = 10;
someDate.setDate(someDate.getDate() + numberOfDaysToAdd);
item.FINAL_REQUEST = someDate;
melpomene
  • 84,125
  • 8
  • 85
  • 148
  • 4
    What qualifies as a holiday? – tymeJV Nov 07 '18 at 20:28
  • Why not add one day at a time, and check the result to see whether it's a day you want; if not try the next day, and keep track of how many "good" ones you've seen. You're on your own in determining what "holiday" means however. – Pointy Nov 07 '18 at 20:32
  • There is also [*DateJS - Do Not Include Weeknds*](https://stackoverflow.com/questions/41517796/datejs-do-not-include-weeknds/41518614#41518614) – RobG Nov 07 '18 at 22:32

1 Answers1

1

There isn't a built-in command to do this.

Basically you have to add one date at a time, and test each one for whether it's a holiday or weekend. Weekends are easy:

function amIAWeekend(someDate){
  return someDate.getDay() == 6 || someDate.getDay() == 0;
}

Testing for a holiday is much harder. The simplest thing to do might be to have a list of holidays in some sort of JSON format, and then for each date run through the list to see if it matches.

Hope this helps get you started!

Andrew Ridgway
  • 574
  • 2
  • 9