Method: Rex::ExtTime.str_to_sec

Defined in:
lib/rex/time.rb

.str_to_sec(str) ⇒ Object

Converts a string in the form n years g days x hours y mins z secs.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rex/time.rb', line 39

def self.str_to_sec(str)
  fields = str.split(/ /)
  secs   = 0

  fields.each_with_index { |f, idx|
    val = 0
    case f
      when /^year/
        val = 31536000
      when /^day/
        val = 86400
      when /^hour/
        val = 3600
      when /^min/
        val = 60
      when /^sec/
        val = 1
    end

    secs += val * fields[idx-1].to_i
  }

  secs
end