Created
November 29, 2018 12:35
-
-
Save vlrmprjct/b476c24b980d6002e2d418188c1ec7fa to your computer and use it in GitHub Desktop.
countdown from seconds #time #js
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
| export const countdown = (function () { | |
| const pad = t => { | |
| return (t + '').length < 2 ? pad('0' + t + '') : t; | |
| } | |
| return s => { | |
| const d = Math.floor(s / (3600 * 24)); | |
| s -= d * 3600 * 24; | |
| const h = Math.floor(s / 3600); | |
| s -= h * 3600; | |
| const m = Math.floor(s / 60); | |
| s -= m * 60; | |
| const tmp = []; | |
| (d) && tmp.push(d + 'd'); | |
| (d || h) && tmp.push(h + 'h'); | |
| (d || h || m) && tmp.push(m + 'm'); | |
| tmp.push(s + 's'); | |
| return tmp.join(' '); | |
| } | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment