Class: FEEL::DateTimeLiteral
- Inherits:
-
Node
- Object
- Treetop::Runtime::SyntaxNode
- Node
- FEEL::DateTimeLiteral
show all
- Defined in:
- lib/feel/nodes.rb
Overview
- date time literal = ( "date" | "time" | "date and time" | "duration" ) , "(" , string literal , ")" ;
Instance Method Summary
collapse
Methods inherited from Node
#access_property, #contains_input_placeholder?, #qualified_names_in_context, #raise_evaluation_error
Instance Method Details
#duration_range(start_date, end_date) ⇒ Object
795
796
797
|
# File 'lib/feel/nodes.rb', line 795
def duration_range(start_date, end_date)
(Date.parse(end_date) - Date.parse(start_date)).to_i
end
|
#eval(context = {}) ⇒ Object
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
|
# File 'lib/feel/nodes.rb', line 769
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
|