Skip to content

Instantly share code, notes, and snippets.

@jarib
Created August 7, 2009 10:14
Show Gist options
  • Save jarib/163820 to your computer and use it in GitHub Desktop.
Save jarib/163820 to your computer and use it in GitHub Desktop.
def seconds_to_s(seconds)
seconds = seconds.round
s = seconds % 60
m = (seconds /= 60) % 60
h = (seconds /= 60) % 24
d = (seconds /= 24)
out = []
out << "#{d}d" if d > 0
out << "#{h}h" if h > 0
out << "#{m}m" if m > 0
out << "#{s}s" if s > 0
out.length > 0 ? out.join(' ') : '0s'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment