At the moment I have a datepicker which:
Excludes today, if after 12:00 midday.
Excludes sundays.
<script type="text/javascript">
$(function() {
// get today's date
var myDate = new Date();
// add one day if after 12:00
if (myDate.getHours() > 12) {
myDate.setDate(myDate.getDate()+1);
} else {
myDate.setDate(myDate.getDate()+0);
};
$("#delivery-date-textbox").datepicker({
dateFormat: 'dd-mm-yy',
minDate: myDate,
beforeShowDay: function(date){ return [date.getDay() != 0,""]}
});
});
</script>
How can I make it also exclude an array of public holidays?
I quickly wrote a snippet that I think is a good outline. My main point is that there are two types of national holidays: ones that fall on the same day every year (like Christmas) and ones that fall on different days every year (like Easter). I won’t give you the logic here to calculate moving holidays, but my snippet works with an array that can have two types of holidays:
month/day(for static) andmonth/day/year(for changing). You can generate this array the way you want.The test will run against this array, converts the array’s values into Date objects and uses jQuery’s
inArray()to find matches.Basic code:
And a jsFiddle Demo. Tested successfully on Chrome and FF4.