Created
August 1, 2018 08:44
-
-
Save khaledosman/9fd05923f8bd94b7ea3a5f1e7c52237c to your computer and use it in GitHub Desktop.
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
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