module Chronic

def parse(text, opts={})

Returns:
  • (Time, Chronic::Span, nil) -

Options Hash: (**opts)
  • :ambiguous_year_future_bias (Integer) --
  • :endian_precedence (Array) --
  • :ambiguous_time_range (Integer) --
  • :guess (Boolean) --
  • :now (Object) --
  • :context (Symbol) --
def parse(text, opts={})
  @text = text
  options = DEFAULT_OPTIONS.merge opts
  # ensure the specified options are valid
  (opts.keys - DEFAULT_OPTIONS.keys).each do |key|
    raise InvalidArgumentException, "#{key} is not a valid option key."
  end
  unless [:past, :future, :none].include?(options[:context])
    raise InvalidArgumentException, "Invalid context, :past/:future only"
  end
  options[:text] = text
  options[:now] ||= Chronic.time_class.now
  Chronic.now = options[:now]
  # tokenize words
  tokens = tokenize(text, options)
  if Chronic.debug
    puts "+#{'-' * 51}\n| #{tokens}\n+#{'-' * 51}"
  end
  span = tokens_to_span(tokens, options)
  if options[:guess]
    guess span
  else
    span
  end
end