Skip to content

Instantly share code, notes, and snippets.

@manveru
Created February 11, 2012 22:35
Show Gist options
  • Save manveru/1804796 to your computer and use it in GitHub Desktop.
Save manveru/1804796 to your computer and use it in GitHub Desktop.
Format a duration as HH:MM:SS
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