Class: Hutils::Ltap::TimeBoundParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hutils/ltap/time_bound_parser.rb

Overview

A parser designed to support the same style of relative time that Splunk does, but note that absolute dates and “snap to” times are not supported.

See here for more information on this format:

http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/SearchTimeModifiers

Instance Method Summary collapse

Instance Method Details

#parse(str, from: Time.now.getutc) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/hutils/ltap/time_bound_parser.rb', line 9

def parse(str, from: Time.now.getutc)
  if str =~ /^([+\-])([0-9]+)?([a-z]+)$/
    to_date($2 || 1, $3, from: from)
  else
    nil
  end
end