I wrote this code for calculating differences between business hours for a leave duration, I also took note of the lunch time and weekends. However, i want to extend it to accommodate holidays. For example, if the dates in the array [‘2020-07-15’, ‘2020-07-16′, 2020-07-17’] are holidays. Please, how can i exclude these holiday days based on the dates passed in the array. Thanks
onChangeDateOT(){ var minutesWorked = 0; var startDate = new Date(this.OTLeaveList.time_from); var endDate = new Date(this.OTLeaveList.time_to); var current = startDate var workHoursStart = 8.30; var workHoursEnd = 24; var includeWeekends = false; var includeLunch = true; var includeWeekDays = true; while(current <= endDate){ if(current.getHours() >= workHoursStart && current.getHours() < workHoursEnd && (includeWeekends ? current.getDay() !== 0 && current.getDay() !== 6 : true) &&(includeWeekDays ? current.getDay() !== 1 && current.getDay() !==2 && current.getDay() !==3 && current.getDay() !==4 && current.getDay() !==5: true ) &&(includeLunch ? current.getHours() !== 12 && current.getHours() !== 13.30 : true)){ minutesWorked++; } current.setTime(current.getTime() + 1000 * 60); } this.OTLeaveList.hours = Math.floor(minutesWorked / 60); }