Created
November 9, 2017 11:44
-
-
Save rasy-js/19575c8539a71e1f91b49c26d3fa6769 to your computer and use it in GitHub Desktop.
get next day, except holiday
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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