Class: ReeDate::NextOccurring

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_date/package/ree_date/functions/next_occurring.rb

Instance Method Summary collapse

Instance Method Details

#call(date = nil, week_day) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ree_lib/packages/ree_date/package/ree_date/functions/next_occurring.rb', line 24

def call(date = nil , week_day)
  date = date || today

  days = nil

  if week_day == :sunday
    days = 6
  else
    days = DAYS_INTO_WEEK.fetch(week_day) - 1
  end

  advance(date, days: 7)
    .then { monday(_1) }
    .then { days_since(_1, days) }
end