Created
April 17, 2018 02:35
-
-
Save codesoda/dbf5f124c71b46ed1b0725276c3bc441 to your computer and use it in GitHub Desktop.
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 padLeft = (number, n,str) => { | |
return number.toString().length >= n ? number : Array(n-String(number).length + 1).join(str||'0') + number; | |
} | |
const playTime = (milliseconds) => { | |
let seconds = milliseconds / 1000.0, | |
hours = Math.floor(seconds / 3600), | |
minutes = Math.floor((seconds % 3600) / 60), | |
only_seconds = Math.round(seconds % 60), | |
parts = []; | |
if (hours >= 1) | |
parts.push(padLeft(hours, 2)); | |
parts.push(padLeft(minutes, 2)); | |
parts.push(padLeft(only_seconds, 2)); | |
return parts.join(':'); | |
} | |
export { padLeft, playTime }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment