Skip to content

Instantly share code, notes, and snippets.

@picsoung
Created August 19, 2021 22:11
Show Gist options
  • Save picsoung/df881f07cbd24e58aa01f4b29896c2f5 to your computer and use it in GitHub Desktop.
Save picsoung/df881f07cbd24e58aa01f4b29896c2f5 to your computer and use it in GitHub Desktop.
Generate a list of X upcoming days in the future.
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