Method: PulseMeter::Mixins::Utils#parse_time

Defined in:
lib/pulse_meter/mixins/utils.rb

#parse_time(str) ⇒ Time

Converts string of the form YYYYmmddHHMMSS (considered as UTC) to Time

Parameters:

  • str (String)

    string to be converted

Returns:

  • (Time)

Raises:

  • (ArgumentError)

    unless passed value responds to to_s



108
109
110
111
112
113
114
115
116
# File 'lib/pulse_meter/mixins/utils.rb', line 108

def parse_time(str)
  raise ArgumentError unless str.respond_to?(:to_s)
  m = str.to_s.match(/\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\z/)
  if m
    Time.gm(*m.captures.map(&:to_i))
  else
    raise ArgumentError, "`#{str}' is not a YYYYmmddHHMMSS time"
  end
end