Created
February 11, 2012 22:35
-
-
Save manveru/1804796 to your computer and use it in GitHub Desktop.
Format a duration as HH:MM:SS
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
divmod = (num1, num2) -> | |
[num1 / num2, num1 % num2] | |
formatInterval = (start) -> | |
total = parseInt((Date.now() - start) / 1000, 10) | |
[hours, rest] = divmod(total, 60 * 60) | |
[minutes, seconds] = divmod(rest, 60) | |
sprintTime(hours, minutes, seconds) | |
sprintTime = -> | |
parts = for arg in arguments | |
num = parseInt(arg, 10) | |
if num < 10 | |
'0' + num | |
else | |
num | |
parts.join(":") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment