我有一个名为dbo.Holidays SQL数据库表,我使用的ColdFusion查询。我的数据库转换为JS数组是这样的:jQuery的显示明天的日期,除非明天是周末或节假日
var natDays = [
[1, 1, 'New Year'], //2014
[1, 20, 'Martin Luther King'], //2014
[2, 17, 'Washingtons Birthday'], //2014
[5, 26, 'Memorial Day'], //2014
[7, 4, 'Independence Day'], //2014
[9, 1, 'Labour Day'], //2014
[10, 14, 'Columbus Day'], //2013
[11, 11, 'Veterans Day'], //2013
[11, 28, 'Thanksgiving Day'], //2013
[12, 25, 'Christmas'] //2013
];
我试图做的目的是在标签不包括假期天或周末。所以当一个假期被列出或者它的周末时,它会显示下一个可用的日子。例如,如果今天(星期四)10/15/15,标签将显示“DUE 10/16/15 @ 5:00”。但如果明天(星期五)10/16/15,标签将显示“DUE 10/19/15 @ 5:00”。同样的情况也适用于假期,它将成为下一个有空的一天,而不是在周末。
现在我测试了明天和它仍然显示星期六的日期。 http://jsfiddle.net/byyeh83t/
$(document).ready(function() {
var natDays = [
[1, 1, 'New Year'], //2014
[1, 20, 'Martin Luther King'], //2014
[2, 17, 'Washingtons Birthday'], //2014
[5, 26, 'Memorial Day'], //2014
[7, 4, 'Independence Day'], //2014
[9, 1, 'Labour Day'], //2014
[10, 14, 'Columbus Day'], //2013
[11, 11, 'Veterans Day'], //2013
[11, 28, 'Thanksgiving Day'], //2013
[12, 25, 'Christmas'] //2013
];
// dateMin is the minimum delivery date
var dateMin = new Date("10/16/2015");
dateMin.setDate(dateMin.getDate() + (dateMin.getHours() >= 14 ? 1 : 0));
function AddBusinessDays(curdate, weekDaysToAdd) {
var date = new Date(curdate.getTime());
while (weekDaysToAdd > 0) {
date.setDate(date.getDate() + 1);
//check if current day is business day
if (noWeekendsOrHolidays(date)) {
weekDaysToAdd--;
}
}
return date;
}
function noWeekendsOrHolidays(date) {
var noWeekend = $.datepicker.noWeekends(date);
return (noWeekend[0] ? nationalDays(date) : noWeekend);
}
function nationalDays(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
return [false, natDays[i][2] + '_day'];
}
}
return [true, ''];
}
function setDeliveryDate(date) {
$('#delivery-date').text($.datepicker.formatDate('mm/dd/yy', date));
}
setDeliveryDate(AddBusinessDays(dateMin, 1));
});
任何帮助,将不胜感激!
我遇到了一个新问题,柜面你想看看http://stackoverflow.com/questions/33155531/jquery-display-tomorrows-date-no-weekend-or-holidays-by-year – Vicki