Last active
October 30, 2023 13:34
-
-
Save gauravds/462fe9d089137372bcf74e1586f5e7b9 to your computer and use it in GitHub Desktop.
Next Time Slot
This file contains hidden or 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 moment = require('moment') | |
/** | |
* Get time for next round off 10 minutes in epoch form. | |
* @returns { number } epoch time | |
* | |
* if time is 17:23:32 => 17:30:00 | |
* if time is 17:53:32 => 18:00:00 | |
* if time is 23 Oct, 2023 23:53:32 => 24 Oct, 2023 00:00:00 | |
*/ | |
function getNextTimeClickFor10Minutes() { | |
const now = moment() | |
const currentMinutes = now.minutes() | |
const minutesRemaining = 10 - (currentMinutes % 10) | |
return now.clone().add(minutesRemaining, 'minutes').seconds(0).unix() | |
} | |
/** | |
* Get time for next round off 60 minutes in epoch form. | |
* @returns { number } epoch time | |
* | |
* if time is 17:23:32 => 18:00:00 | |
* if time is 23 Oct, 2023 23:13:32 => 24 Oct, 2023 00:00:00 | |
*/ | |
function getNextTimeClickFor60Minutes() { | |
const now = moment() | |
const currentMinutes = now.minutes() | |
const minutesRemaining = 60 - currentMinutes | |
return now.clone().add(minutesRemaining, 'minutes').minute(0).seconds(0).unix() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment