jQuery显示明天日期无周末或每年的假期 [英] jQuery display Tomorrows date No weekend or Holidays by year
问题描述
请有人帮我更新此信息,以便也可以从数组中检测年份.我要尝试的目标是使标签不包括假日或周末.因此,当列出假日或周末时,它将显示下一个可用的日期.例如,如果今天(星期四)10/15/15,标签将显示"DUE 10/16/15 @ 5:00".但是,如果明天(星期五)10/16/15,标签将显示"DUE 10/19/15 @ 5:00".同样的做法也适用于假期,这将在下一个工作日而不是周末.
Will someone please help me update this to be able to detect the year from the array as well. The goal I am trying to do is have the label not include the holiday days or weekends. So when a holiday is listed or its the weekend it will display the next available day. For example if today (thursday) 10/15/15, the label will show "DUE 10/16/15 @ 5:00". But if tomorrow (friday) 10/16/15, the label will show "DUE 10/19/15 @ 5:00". And the same would apply for holidays it would be the next available day and not on the weekend.
这就是我所拥有的: http://jsfiddle.net/byyeh83t/1/其中在将年份考虑在内之前,它似乎一直有效,因为该阵列仅按月份和日期运行.因此,我现在还需要添加一些内容来检查年份.
This is what I have: http://jsfiddle.net/byyeh83t/1/ which appears to work until you take the year into consideration because the array is only going by the month and day. So I now need to add something to check the year as well.
请有人帮我调整一下以检查正确的年份. http://jsfiddle.net/byyeh83t/3/
Will someone please help me adjust this to check for the correct year as well. http://jsfiddle.net/byyeh83t/3/
如果1/18/15是星期日,则输出应为1/20/15,因为1/19/15是MLK假期,但返回1/19/15
If 1/18/15 is the date which is a sunday the output should be 1/20/15 since 1/19/15 is MLK holiday but instead it returns 1/19/15
$(document).ready(function() {
var natDays = [
[2014, 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, 13, 'Columbus Day'],
[2014, 11, 11, 'Veterans Day'],
[2014, 11, 27, 'Thanksgiving Day'],
[2014, 11, 28, 'Thanksgiving Day'],
[2014, 12, 25, 'Christmas'],
[2014, 12, 26, 'Christmas'],
[2015, 1, 1, 'New Year'],
[2015, 1, 19, 'Martin Luther King'],
[2015, 2, 16, 'Washingtons Birthday'],
[2015, 5, 25, 'Memorial Day'],
[2015, 7, 3, 'Independence Day'],
[2015, 9, 7, 'Labour Day'],
[2015, 10, 12, 'Columbus Day'],
[2015, 11, 11, 'Veterans Day'],
[2015, 11, 26, 'Thanksgiving Day'],
[2015, 11, 27, 'Thanksgiving Day'],
[2015, 12, 24, 'Christmas'],
[2015, 12, 25, 'Christmas']
];
// dateMin is the minimum delivery date
var dateMin = new Date("1/18/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)[0]) {
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));
});
任何帮助将不胜感激.
推荐答案
您应该:
- 将
natDays[i][0]
(以前是月份)更改为natDays[i][1]
- 将
natDays[i][1]
(以前是一天)更改为natDays[i][2]
- 将
natDays[i][2]
(以前是描述)更改为natDays[i][3]
- 将此条件添加到
nationalDays
函数中的if:date.getFullYear() == natDays[i][0]
- Change
natDays[i][0]
(which used to be the month) tonatDays[i][1]
- Change
natDays[i][1]
(which used to be the day) tonatDays[i][2]
- Change
natDays[i][2]
(which used to be the description) tonatDays[i][3]
- Add this condition to the if in
nationalDays
function:date.getFullYear() == natDays[i][0]
赞:
if (date.getFullYear() == natDays[i][0] && date.getMonth() == natDays[i][1] - 1 && date.getDate() == natDays[i][2]) {
return [false, natDays[i][3] + '_day'];
}
这篇关于jQuery显示明天日期无周末或每年的假期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!