Class: Timing::NaturalTimeLanguage::LastNextDayName

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/timing/natural_time_language_interpreters.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(zone_offset) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/timing/natural_time_language_interpreters.rb', line 57

def evaluate(zone_offset)
  today = TimeInZone.now(zone_offset).beginning_of_day

  return today if !including_today.empty? && today.wday == day_name.value

  if direction.last?
    if today.wday > day_name.value
      today - Interval.days(today.wday - day_name.value)
    else
      today - Interval.weeks(1) + Interval.days(day_name.value - today.wday)
    end
  else
    if today.wday < day_name.value
      today + Interval.days(day_name.value - today.wday)
    else
      today + Interval.weeks(1) - Interval.days(today.wday - day_name.value)
    end
  end
end