Skip to content

Instantly share code, notes, and snippets.

@khaledosman
Created August 1, 2018 08:44
Show Gist options
  • Save khaledosman/9fd05923f8bd94b7ea3a5f1e7c52237c to your computer and use it in GitHub Desktop.
Save khaledosman/9fd05923f8bd94b7ea3a5f1e7c52237c to your computer and use it in GitHub Desktop.
const getNextDate = (dateObj, recurringType) => {
let pointerTime = dateObj.getTime()
const generatedTimes = []
while (pointerTime <= Date.now()) {
let pointerDate = new Date(pointerTime)
if (recurringType === 'daily') {
pointerTime = pointerDate.setHours(pointerDate.getHours() + 24)
} else if (recurringType === 'monthly') {
pointerTime = pointerDate.setMonth(pointerDate.getMonth() + 1)
} else if (recurringType === 'weekly') {
pointerTime = pointerDate.setHours(pointerDate.getHours() + 24 * 7)
}
generatedTimes.push(new Date(pointerTime))
}
const lastTime = generatedTimes[generatedTimes.length - 1]
return lastTime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment