Class: FEEL::DateTimeLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/feel/nodes.rb

Overview

  1. date time literal = ( “date” | “time” | “date and time” | “duration” ) , “(” , string literal , “)” ;

Instance Method Summary collapse

Methods inherited from Node

#access_property, #qualified_names_in_context, #raise_evaluation_error

Instance Method Details

#duration_range(start_date, end_date) ⇒ Object



777
778
779
# File 'lib/feel/nodes.rb', line 777

def duration_range(start_date, end_date)
  (Date.parse(end_date) - Date.parse(start_date)).to_i
end

#eval(context = {}) ⇒ Object



751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/feel/nodes.rb', line 751

def eval(context = {})
  head_val = head.eval(context)
  return nil if head_val.nil?
  return head_val if head_val.is_a?(ActiveSupport::Duration) || head_val.is_a?(DateTime) || head_val.is_a?(Date) || head_val.is_a?(Time)

  result = case keyword.text_value
  when "date and time"
    DateTime.parse(head_val)
  when "date"
    Date.parse(head_val)
  when "time"
    Time.parse(head_val)
  when "duration"
    if defined?(tail) && tail.present?
      (Date.parse(tail.text_value) - Date.parse(head.text_value)).to_i.days
    else
      ActiveSupport::Duration.parse(head_val)
    end
  end

  if defined?(property) && property.present?
    result = access_property(result, property.name.eval(context))
  end
  result
end