Method: Fluent::TimeParser#parse

Defined in:
lib/fluent/time.rb

#parse(value) ⇒ Object Also known as: call

TODO: new cache mechanism using format string



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/fluent/time.rb', line 267

def parse(value)
  unless value.is_a?(String)
    raise TimeParseError, "value must be string: #{value}"
  end

  if @cache1_key == value
    return @cache1_time
  elsif @cache2_key == value
    return @cache2_time
  else
    begin
      time = @parse.call(value)
    rescue => e
      raise TimeParseError, "invalid time format: value = #{value}, error_class = #{e.class.name}, error = #{e.message}"
    end
    @cache1_key = @cache2_key
    @cache1_time = @cache2_time
    @cache2_key = value
    @cache2_time = time
    return time
  end
end