Created
May 21, 2019 12:05
-
-
Save basith374/7876e116ce533e22f5df2f90d533d145 to your computer and use it in GitHub Desktop.
moment better duration
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 function duration(ms) { | |
| if(!ms) return 'N/A'; | |
| if(ms < (60 * 1000)) { | |
| let dur = Math.floor(ms / 1000); | |
| if(dur < 2) return 'a second'; | |
| return dur + ' seconds'; | |
| } | |
| if(ms < (60 * 60 * 1000)) { | |
| let minutes = Math.floor(ms / 1000 / 60); | |
| let seconds = Math.floor(ms % (1000 * 60) / 1000); | |
| let dur = minutes + ' min '; | |
| if(seconds) dur += seconds + ' sec'; | |
| return dur; | |
| } | |
| return moment.duration(ms).humanize(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment