title: Calculate working days between two dates in Javascript excepts holidays
body: <p>I have a javascript function which is calculating working days between 2 dates, it works, but the problem is that it not consider holidays. How can I modify this function, for example by adding holidays in exception array?</p>
  
  <p>Searched in internet about this question, but haven't find about holidays exception.</p>
  
  <p>For example holidays array:</p>
  
  <pre><code>var holidays = ['2016-05-03','2016-05-05'];
  </code></pre>
  
  <p>And I have a functions to calculate this:</p>
  
  <pre><code>function workingDaysBetweenDates(d0, d1) {
      var startDate = parseDate(d0);
      var endDate = parseDate(d1);  
      // Validate input
      if (endDate &lt; startDate)
          return 0;
  
      // Calculate days between dates
      var millisecondsPerDay = 86400 * 1000; // Day in milliseconds
      startDate.setHours(0,0,0,1);  // Start just after midnight
      endDate.setHours(23,59,59,999);  // End just before midnight
      var diff = endDate - startDate;  // Milliseconds between datetime objects    
      var days = Math.ceil(diff / millisecondsPerDay);
  
      // Subtract two weekend days for every week in between
      var weeks = Math.floor(days / 7);
      days = days - (weeks * 2);
  
      // Handle special cases
      var startDay = startDate.getDay();
      var endDay = endDate.getDay();
  
      // Remove weekend not previously removed.   
      if (startDay - endDay &gt; 1)         
          days = days - 2;      
  
      // Remove start day if span starts on Sunday but ends before Saturday
      if (startDay == 0 &amp;&amp; endDay != 6)
          days = days - 1  
  
      // Remove end day if span ends on Saturday but starts after Sunday
      if (endDay == 6 &amp;&amp; startDay != 0)
          days = days - 1  
  
      return days;
  }
  function parseDate(input) {
      // Transform date from text to date
    var parts = input.match(/(\d+)/g);
    // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]])
    return new Date(parts[0], parts[1]-1, parts[2]); // months are 0-based
  }
  </code></pre>
  
  <p>Have made an example in jsfiddle:</p>
  
  <p><a href="https://jsfiddle.net/alessandro2981/LgL9zr95/" rel="noreferrer"><strong>JSFiddle example</strong></a></p>
  
  <p>Maybe there are some other functions which can easy use in Jquery?</p>