Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def humanize secs
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name|
if secs > 0
secs, n = secs.divmod(count)
"#{n.to_i} #{name}"
end
}.compact.reverse.join(' ')
end
@aerickson

This comment has been minimized.

Copy link
Owner Author

@aerickson aerickson commented Aug 3, 2016

for milliseconds

def humanize millis
  [[1000, :milliseconds], [60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name|
    if millis > 0
      millis, n = millis.divmod(count)
      "#{n.to_i} #{name}"
    end
  }.compact.reverse.join(' ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment