Skip to content

Instantly share code, notes, and snippets.

@jamesattard
Created May 8, 2018 19:53
Show Gist options
  • Save jamesattard/f7919b9ca5ec758ba8293eba58084349 to your computer and use it in GitHub Desktop.
Save jamesattard/f7919b9ca5ec758ba8293eba58084349 to your computer and use it in GitHub Desktop.
Create a moment.js time range based on arbitrary duration, start time and end time
const timeRangeArr = [];
const lunchBreakFrom = moment()
.hours(12)
.minutes(0);
const lunchBreakTo = moment()
.hours(13)
.minutes(0);
const duration = 15;
for (
let lunchBreak = lunchBreakFrom;
lunchBreak.isBefore(lunchBreakTo);
lunchBreak.add(duration, "minutes")
) {
timeRangeArr.push(moment(lunchBreak));
}
// console.log(timeRangeArr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment