Created
July 14, 2017 03:30
-
-
Save otolab/3a7474793d96911792e2503a85589882 to your computer and use it in GitHub Desktop.
1600000000000を向かえる準備
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
| 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