Module: Tddium::TimeFormat

Extended by:
TextHelper
Defined in:
lib/tddium/cli/timeformat.rb

Class Method Summary collapse

Methods included from TextHelper

pluralize

Class Method Details

.seconds_to_human_time(seconds) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tddium/cli/timeformat.rb', line 7

def self.seconds_to_human_time(seconds)
  return '-' if seconds.nil?
  seconds = seconds.to_time if seconds.respond_to?(:to_time)
  seconds = seconds.abs.round
  return "0 secs" if seconds == 0
  [[60, :sec], [60, :min], [24, :hr], [10000, :day]].map{ |count, name|
    if seconds > 0
      seconds, n = seconds.divmod(count)
      pluralize(n.to_i, name.to_s)
    end
  }.compact.reverse[0..1].join(' ')
end