Skip to content

Instantly share code, notes, and snippets.

@khaledosman
Created November 2, 2020 16:30
Show Gist options
  • Save khaledosman/e9c8e913cd665af5e60b105e7bf0b188 to your computer and use it in GitHub Desktop.
Save khaledosman/e9c8e913cd665af5e60b105e7bf0b188 to your computer and use it in GitHub Desktop.
Generate a time array (i.e for a graph)
function generateTimeArray (startTime, endTime, step) {
let pointer = startTime
const res = []
console.log(pointer, pointer <= endTime)
while (pointer <= endTime) {
res.push(pointer)
const dateObj = new Date(pointer)
pointer = dateObj.setHours(dateObj.getHours() + step)
}
return res
}
module.exports.generateTimeArray = generateTimeArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment