Skip to content

Instantly share code, notes, and snippets.

@otolab
Created July 14, 2017 03:30
Show Gist options
  • Select an option

  • Save otolab/3a7474793d96911792e2503a85589882 to your computer and use it in GitHub Desktop.

Select an option

Save otolab/3a7474793d96911792e2503a85589882 to your computer and use it in GitHub Desktop.
1600000000000を向かえる準備
function start() {
let nextEpoc = (Math.floor(Date.now() / 100000000000) + 1) * 100000000000
console.log('next epoc:', nextEpoc)
waitNextEpoc(nextEpoc)
}
function waitNextEpoc(nextEpoc) {
let now = Date.now()
let sleepTime = (nextEpoc - now) / 10
if (sleepTime < 100000) {
console.log(now)
}
else if (sleepTime > 24 * 60 * 60 * 1000) {
console.log('good night!')
}
if (sleepTime <= 10) {
while(Date.now() < nextEpoc);
console.log('happy new epoc!', nextEpoc)
start()
}
else {
setTimeout(() => waitNextEpoc(nextEpoc), sleepTime)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment