Module: Chore::TimeHelp
- Defined in:
- lib/chore/time_help.rb
Class Method Summary collapse
-
.elapsed_human_time(seconds) ⇒ Object
Show stuff like “7 weeks, 3 days, 4 hours” instead of 13252363477 seconds since epoch.
Class Method Details
.elapsed_human_time(seconds) ⇒ Object
Show stuff like “7 weeks, 3 days, 4 hours” instead of 13252363477 seconds since epoch
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/chore/time_help.rb', line 5 def self.elapsed_human_time seconds remaining_ticks = seconds human_text = "" [[60,:seconds],[60,:minutes],[24,:hours],[7, :days]].each do |ticks, unit| above = remaining_ticks / ticks below = remaining_ticks % ticks if below != 0 unit = unit[0..-2] if below == 1 human_text = "#{below} #{unit} " + human_text end remaining_ticks = above if above == 0 break end end human_text.strip end |