Skip to content

Instantly share code, notes, and snippets.

@jafoca
Created September 18, 2012 16:23
Show Gist options
  • Save jafoca/3744085 to your computer and use it in GitHub Desktop.
Save jafoca/3744085 to your computer and use it in GitHub Desktop.
Restrict the options on a jQueryUI date picker to allow only weekdays at a minimum of 2 business days in the future
$(document).ready(function() {
$('.date').datepicker({
dateFormat: 'yy-mm-dd',
minDate : setRestrictedDates(),
beforeShowDay: $.datepicker.noWeekends
});
});
function setRestrictedDates(){
var today = new Date();
//default to second business day
var offset = 2;
switch(today.getDay())
{
//sunday -> wednesday
case 0:
offset = 3;
break;
//thursday -> monday
case 4:
//friday -> tuesday
case 5:
//saturday -> wednesday
case 6:
offset = 4;
break;
}
return offset;
}
@jafoca
Copy link
Author

jafoca commented Sep 18, 2012

setRestrictedDates uses a switch statement for read-ability, not sure if this is the 'best' way of doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment