I have been using this script, found on Answers, verbatim for several years to facilitate restricting the date picker to every other Sunday:
$(document).ready(function(){
//The date should be every other Sunday since 5/3/2020
var startDate = new Date(2020,4,3);
function payPeriodsOnly(date) {
var day = date.getDay();
var oneDay = 24 * 60 * 60 * 1000; //milliseconds in one day
var diffDays = (Math.abs(startDate.getTime() - date.getTime()) / oneDay);
return ((day == 0) && (Math.round(diffDays) % 14 == 0)); //sunday and every other weeks
}
function getStartDate() {
var dayOfWeek = 0;
var resultDate = new Date();
resultDate.setHours(0,0,0,0);
//If today is 5/28/2020, the start date is 5/17/2020
//If today is 6/1/2020, the start date is 5/31/2020
resultDate.setDate(resultDate.getDate() - 14);
resultDate.setDate(resultDate.getDate() + (7 + dayOfWeek - resultDate.getDay()) % 7);
if (!payPeriodsOnly(resultDate)) {
resultDate.setDate(resultDate.getDate() + 7);
}
return resultDate;
}
function checkField(input, inst) {
if ($(input).closest('li').hasClass('PPEdate')) {
$(input).datepicker("option", {minDate: getStartDate(), beforeShowDay: function(n) {return [payPeriodsOnly(n), ''];}});
}
}
$.datepicker.setDefaults( {beforeShow: checkField} );
window.Parsley.addValidator('othersun', {
validateString: function(value, target) {
return payPeriodsOnly(new Date(value));
},
messages: {
en: 'Not valid date.'
}
});
$('.PPEdate input').attr('data-parsley-othersun', true);
});
I now need a way to have the startDate go way back to 2017 (1/1/2017). I updated the year range on the date field to go back 10 years and tried updating the startDate accordingly, but it didn't work. Is it possible to accomplish what I need? Lots of poking around on Answers didn't yield many clues.