metasploit-framework/lib/rex/time.rb

29 lines
667 B
Ruby
Raw Normal View History

# -*- coding: binary -*-
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
[[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
}.compact.join(' ')
2018-04-30 23:40:07 +00:00
end
2013-08-30 21:28:33 +00:00
end
end