Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created March 23, 2009 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsmith/83668 to your computer and use it in GitHub Desktop.
Save lsmith/83668 to your computer and use it in GitHub Desktop.
// Adds n weekdays to Date d. Weekdays are Mon-Fri. Holidays are not accounted for.
// Adding 0 days to a weekend day will return Monday's Date.
function addWeekdays(d,n) {
d = new Date(d.getTime());
var day = d.getDay();
d.setDate(
d.getDate() + n +
(day === 6 ? 2 : +!day) +
(Math.floor((n - 1 + (day % 6 || 1)) / 5) * 2));
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment