Skip to content

Instantly share code, notes, and snippets.

@mihar
Created December 19, 2013 11:38
Show Gist options
  • Save mihar/8037930 to your computer and use it in GitHub Desktop.
Save mihar/8037930 to your computer and use it in GitHub Desktop.
DUBJOY.human_time = (s) ->
time = DUBJOY.get_time_from_seconds s
output = ""
output += "#{time.h}h" if time.h and time.h isnt '00'
output += "#{time.m}m" if time.m and time.m isnt '00'
output += "#{time.s}s" if time.s and time.s isnt '00'
output += "#{time.ms}ms" if time.ms and time.ms isnt '00'
output
DUBJOY.get_time_from_seconds = (s) ->
hours = parseInt( s / 3600 ) % 24
minutes = parseInt( s / 60 ) % 60
seconds = Math.floor s % 60
miliseconds = Math.round (s % 1) * 1000
hours = if hours < 10
"0" + hours
else
hours
minutes = if minutes < 10
"0" + minutes
else
minutes
seconds = if seconds < 10
"0" + seconds
else
seconds
miliseconds = if miliseconds < 10
"00" + miliseconds
else if miliseconds < 100
"0" + miliseconds
else
miliseconds
{h: hours, m: minutes, s: seconds, ms: miliseconds}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment