我正在计算假期中间的持续时间。当我选择假日日期作为结束日期时,我已经尝试过了,持续时间为0。但是如果我选择第二天,持续时间将照常计算而不会减少假日。我必须在代码中添加或更改什么
function getBusinessDatesCount(startDate, endDate) {
var count = 0;
var curDate = new Date(startDate);
var holiday = [];
holiday[0] = new Date('2019-08-08');
holiday[1] = new Date('2019-08-14');
while (curDate <= endDate) {
var dayOfWeek = curDate.getDay();
var isWeekend = (dayOfWeek == 6) || (dayOfWeek == 0);
if (!isWeekend && !isHoliday(endDate, holiday))
count++;
curDate.setDate(curDate.getDate() + 1);
}
function isHoliday(dt, arr) {
var bln = false;
for (var i = 0; i < arr.length; i++) {
if (compare(dt, arr[i])) { //If days are holidays
bln = true;
break;
}
}
return bln;
}
function compare(dt1, dt2) {
var equal = false;
if (dt1.getDate() == dt2.getDate() && dt1.getMonth() == dt2.getMonth() && dt1.getFullYear() == dt2.getFullYear()) {
equal = true;
}
return equal;
}
return count;
}
我希望假期期间的日期不会一直计算假期日期