Module: Rex::ExtTime

Defined in:
lib/rex/ext_time.rb

Overview

Extended time related functions.

Class Method Summary collapse

Class Method Details

.sec_to_s(seconds) ⇒ Object

Convert seconds to a string that is broken down into years, days, hours, minutes, and second.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rex/ext_time.rb', line 13

def self.sec_to_s(seconds)
  return "0 secs" if seconds.to_i <= 0
  [[31536000, 'year'], [86400, 'day'], [3600, 'hour'], [60, 'min'], [1, 'sec']].map! { |count, name|
    if (c = seconds / count) > 0
      c = c.truncate
      seconds -= c * count
      if c == 1
        "#{c} #{name}"
      elsif c > 1
        "#{c} #{name}s"
      end
    end
  }.compact.join(' ')
end