Files
metasploit-gs/lib/rex/time.rb
T

29 lines
667 B
Ruby
Raw Normal View History

# -*- coding: binary -*-
2005-07-22 03:32:06 +00:00
module Rex
2018-04-30 18:40:07 -05:00
###
2013-08-30 16:28:33 -05:00
#
2018-04-30 18:40:07 -05:00
# Extended time related functions.
2013-08-30 16:28:33 -05:00
#
2018-04-30 18:40:07 -05:00
###
module ExtTime
#
# Convert seconds to a string that is broken down into years, days, hours,
# minutes, and second.
#
def self.sec_to_s(seconds)
2018-06-08 22:21:26 -04:00
return "0 secs" if seconds.to_i <= 0
2018-06-08 22:09:03 -04:00
[[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
2018-04-30 18:40:07 -05:00
end
2018-06-08 22:09:03 -04:00
}.compact.join(' ')
2018-04-30 18:40:07 -05:00
end
2013-08-30 16:28:33 -05:00
end
end