title: Calculate an expected delivery date (accounting for holidays) in business days using JavaScript?
body: <p>After revisiting this script, and some modifications, the following is available to allow a user to add a feature that calculates the expected delivery date.</p>
  
  <pre><code>// array of ISO YYYY-MM-DD format dates
  publicHolidays = {
      uk:["2020-01-01","2020-04-10","2020-04-13","2020-05-08","2020-05-25",
          "2020-08-03","2020-08-31","2020-12-25","2020-12-28"],
      usa:["2020-01-01","2020-01-20","2020-02-14","2020-02-17","2020-04-10",
          "2020-04-12","2020-05-10","2020-05-25","2020-06-21","2020-07-03",
          "2020-07-04","2020-09-07","2020-10-12","2020-10-31","2020,11,11",
          "2020-11-26","2020-12-25"]
  }
  // check if there is a match in the array
  Date.prototype.isPublicHoliday = function( data ){// we check for a public holiday
      if(!data) return 1;
  return data.indexOf(this.toISOString().slice(0,10))&gt;-1? 0:1;
  }
  
  // calculation of business days
  Date.prototype.businessDays = function( d, holidays ){
      var holidays = holidays || false, t = new Date( this ); // copy date.
      while( d ){ // we loop while d is not zero...   
          t.setDate( t.getDate() + 1 ); // set a date and test it
          switch( t.getDay() ){ // switch is used to allow easier addition of other days of the week
              case 0: case 6: break;// sunday &amp; saturday
              default: // check if we are a public holiday or not
                  d -= t.isPublicHoliday( holidays ); 
          }
      }
      return t.toISOString().slice(0,10); // just the YYY-MM-DD 
  }
  
  // dummy var, could be a form field input
  OrderDate = "2020-02-12";
  // test with a UK holiday date
  var deliveryDate = new Date(OrderDate).businessDays(7, publicHolidays.usa);
  // expected output 2020-02-25
  console.log("Order date: %s, Delivery date: %s",OrderDate,deliveryDate );
  </code></pre>
  
  <p>Order date: 2020-02-12, Delivery date: 2020-02-25</p>
  
  <hr>
  
  <p>The prototype is written to allow inputs from forms (HTML5 forms) of date type inputs as they are already in an ISO YYYY-MM-DD format and the output is formatted as such should that be needing to update a particular field.</p>
  
  <p>The typical use would be...</p>
  
  <pre><code>var delDate = new Date( ISOdate ).businessDays( addBusinessDays, holidayData );
  </code></pre>
  
  <p>where the delDate is an ISO format date, eg, 2020-01-01</p>