Module: DecisionAgent::Dsl::Operators::DateTimeOperators
- Defined in:
- lib/decision_agent/dsl/operators/date_time_operators.rb
Overview
Handles date/time operators: before_date, after_date, within_days, day_of_week
Class Method Summary collapse
Class Method Details
.handle(op, actual_value, expected_value, _date_cache: nil, _date_cache_mutex: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/decision_agent/dsl/operators/date_time_operators.rb', line 8 def self.handle(op, actual_value, expected_value, _date_cache: nil, _date_cache_mutex: nil) case op when "before_date" # Checks if date is before specified date ConditionEvaluator.compare_dates(actual_value, expected_value, :<) when "after_date" # Checks if date is after specified date ConditionEvaluator.compare_dates(actual_value, expected_value, :>) when "within_days" # Checks if date is within N days from now (past or future) return false unless actual_value return false unless expected_value.is_a?(Numeric) date = ConditionEvaluator.parse_date(actual_value) return false unless date now = Time.now diff_days = ((date - now) / 86_400).abs # 86400 seconds in a day diff_days <= expected_value when "day_of_week" # Checks if date falls on specified day of week return false unless actual_value date = ConditionEvaluator.parse_date(actual_value) return false unless date expected_day = ConditionEvaluator.normalize_day_of_week(expected_value) return false unless expected_day date.wday == expected_day end # Returns nil if not handled by this module end |