2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-07-22 03:32:06 +00:00
|
|
|
module Rex
|
2018-04-30 23:40:07 +00:00
|
|
|
###
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
2018-04-30 23:40:07 +00:00
|
|
|
# Extended time related functions.
|
2013-08-30 21:28:33 +00:00
|
|
|
#
|
2018-04-30 23:40:07 +00: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-09 02:21:26 +00:00
|
|
|
return "0 secs" if seconds.to_i <= 0
|
2018-06-09 02:09:03 +00: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 23:40:07 +00:00
|
|
|
end
|
2018-06-09 02:09:03 +00:00
|
|
|
}.compact.join(' ')
|
2018-04-30 23:40:07 +00:00
|
|
|
end
|
2013-08-30 21:28:33 +00:00
|
|
|
end
|
2008-11-08 22:35:37 +00:00
|
|
|
end
|