Created
August 19, 2021 22:11
-
-
Save picsoung/df881f07cbd24e58aa01f4b29896c2f5 to your computer and use it in GitHub Desktop.
Generate a list of X upcoming days in the future.
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
let {current_day, EXCLUDE_WEEKENDS,INTERVAL} = inputData | |
let dates = [] | |
let j = 1; | |
do{ | |
let d = new Date(current_day); | |
d.setDate(d.getDate()+j) | |
if(EXCLUDE_WEEKENDS==="true"){//exclude weekends | |
if(d.getDay() === 6){ //saturday | |
d.setDate(d.getDate() + 2); | |
j = j + 2 | |
}else if(d.getDay() === 7){ //sunday | |
d.setDate(d.getDate() + 1); | |
j = j + 1 | |
} | |
} | |
j = j + 1 | |
dates.push({label: d.toDateString()}) | |
}while(dates.length < INTERVAL) | |
output = [{dates}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment