Method: Doing::ChronifyString#to_seconds

Defined in:
lib/doing/chronify/string.rb

#to_secondsInteger

Convert DD:HH:MM to seconds

Returns:

  • (Integer)

    rounded number of seconds

Raises:



101
102
103
104
105
106
107
108
109
110
# File 'lib/doing/chronify/string.rb', line 101

def to_seconds
  mtch = match(/(\d+):(\d+):(\d+)/)

  raise Errors::DoingRuntimeError, "Invalid time string: #{self}" unless mtch

  h = mtch[1]
  m = mtch[2]
  s = mtch[3]
  (h.to_i * 60 * 60) + (m.to_i * 60) + s.to_i
end