我有一個名爲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