Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong>: modified <code>getMonth()</code> to <code>getMonth() + 1</code> accordingly to the comments.</p> <pre><code>**date in var natDays &amp; is in selected difference range** </code></pre> <p><em>date is in selected difference range</em> is always true as <code>new Date(i)</code> is inside said range (just like in the loop for <code>weekend_count</code>: you didn't bother with checking whether you're in the range).</p> <p>Now, checking if the date inside <code>temp</code> is a holiday, you may want to use a function (though you still can do it straight in your code):</p> <pre><code>/* dateObject is a JS Date object (e.g. dateObject = new Date();) */ /* country is the country we test holidays for */ function isHoliday(dateObject, country) { /* let's assume natDays is global, otherwise pass it as a third argument to this function */ for(var i = 0; i &lt; natDays.length; i++) { /* natDays[i][0] is a day, natDays[i][1] is a month, natDays[i][2] is a country indicator */ if(parseInt(dateObject.getDate()) == parseInt(natDays[i][0]) &amp;&amp; parseInt(dateObject.getMonth()) + 1 == parseInt(natDays[i][1]) &amp;&amp; country.toLowerCase() == natDays[i][2].toLowerCase()) { /* found a day and a month matching our current Date's day and month: interrupt and tell caller dateObject is a holiday */ return true; } } /* end of loop, we parsed all possible holidays without finding any match for our Date: tell caller the given Date is not a holiday */ return false; } </code></pre> <p>Now to put it in your code:</p> <pre><code>if (isHoliday(temp, 'uk')) { holidaycount++; } </code></pre> <p>This should do the trick, though it may require some refactoring (did not test this code), and there is probably more elegant ways to do it (like modding the Date object's prototype to use this function as a method of the object).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload