hi , i want to make the case for example if a lesson is every Thursday and we had a holiday on one of the month Thursday it should skip the date to the next Thursday but it doesn't , help please.
const holidays = [
new Date(2023, 0, 1),
new Date(2023, 2, 9),
new Date(2023, 3, 21),
new Date(2023, 3, 22),
];
function calculateEndDate(startDate, courseDuration, workingDays, workingHours) {
let currentDate = startDate;
let remainingDuration = courseDuration;
while (remainingDuration > 0) {
if(holidays.includes(currentDate)) {
currentDate.setDate(currentDate.getDate() + 1);
continue;
}
let hoursOnCurrentDay = 0;
if (workingDays.includes(currentDate.getDay())) {
hoursOnCurrentDay = workingHours[currentDate.getDay()];
}
remainingDuration -= hoursOnCurrentDay;
currentDate.setDate(currentDate.getDate() + 1);
}
return currentDate;
}
let startDate = new Date(2023, 0, 19);
let courseDuration = 36;
let workingDays = [4]; // Thursday
let workingHours = {
4: 4, // 4 hours every Thursday
};
let endDate = calculateEndDate(startDate, courseDuration, workingDays, workingHours);
console.log(endDate);