Skip to content

Instantly share code, notes, and snippets.

@rasy-js
Created November 9, 2017 11:44
Show Gist options
  • Save rasy-js/19575c8539a71e1f91b49c26d3fa6769 to your computer and use it in GitHub Desktop.
Save rasy-js/19575c8539a71e1f91b49c26d3fa6769 to your computer and use it in GitHub Desktop.
get next day, except holiday
var getNextWeekday = (function() {
var holidays = ['1/1', '7/1', '4/2', '23/2', '8/3', '1/4', '9/4'];
function checkHoliday(date) {
date.setDate(date.getDate() + 1);
var day = date.getDay();
if(day === 0 || day === 6 || holidays.indexOf(date.getDate() + '/' + (date.getMonth() + 1)) !== -1) {
date = checkHoliday(date);
}
return date;
}
return function(date) {
return checkHoliday(new Date(date || Date.now()));
};
})();
var date = new Date();
console.log(getNextWeekday(date));
console.log(getNextWeekday());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment