Datepicker - udelad weekenddage
HejJeg bøvler med at få holdt weekenddage ude af beregningen her, når jeg bruger AddWeekDays.
Håber meget på at en med de rette skills (som jeg tydeligvis ikke har) kan hjælpe.
På forhånd tak!
/Morten
$(document).ready(function() {
var dateMin = new Date();
var weekDays = AddWeekDays(6);
dateMin.setDate(dateMin.getDate() + weekDays);
var natDays = [
[1, 1, 'dk'],
[1, 2, 'dk'],
[1, 3, 'dk'],
[3, 24, 'dk'],
[3, 25, 'dk'],
[3, 28, 'dk'],
[4, 22, 'dk'],
[5, 5, 'dk'],
[5, 16, 'dk'],
[12, 26, 'dk']
];
function noWeekendsOrHolidays(date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return nationalDays(date);
} else {
return 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 AddWeekDays(weekDaysToAdd) {
var daysToAdd = 0
var mydate = new Date()
var day = mydate.getDay()
weekDaysToAdd = weekDaysToAdd - (5 - day)
if ((5 - day) < weekDaysToAdd || weekDaysToAdd == 1) {
daysToAdd = (5 - day) + 2 + daysToAdd
} else { // (5-day) >= weekDaysToAdd
daysToAdd = (5 - day) + daysToAdd
}
while (weekDaysToAdd != 0) {
var week = weekDaysToAdd - 5
if (week > 0) {
daysToAdd = 7 + daysToAdd
weekDaysToAdd = weekDaysToAdd - 5
} else { // week < 0
daysToAdd = (5 + week) + daysToAdd
weekDaysToAdd = weekDaysToAdd - (5 + week)
}
}
return daysToAdd;
}
$('#picker').datepicker({
inline: true,
beforeShowDay: noWeekendsOrHolidays,
dateFormat: "dd/mm-yy",
firstDay: 1,
changeFirstDay: false,
minDate: dateMin,
buttonImageOnly: true,
showOn: 'both',
changeMonth: true,
changeYear: true,
buttonText: "Vælg dato",
buttonImage: "/css/gfx/calendar.gif",
});
$('#picker').keypress(function(event) {
event.preventDefault();
});
$('.hasDatepicker').datepicker({
maxDate: "-1D"
}).attr('readonly', 'readonly');
$('.hasDatepicker ').readonlyDatepicker(true);
});