Module: Service::DateTime

Defined in:
lib/service/time_zone.rb

Class Method Summary collapse

Class Method Details

.closest_day_of_week(start_datetime, day_of_week) ⇒ Object

return start_date if start_datetime day of week == day_of_week return the day after start_date with the same day_of_week



53
54
55
56
57
58
59
60
61
# File 'lib/service/time_zone.rb', line 53

def self.closest_day_of_week(start_datetime, day_of_week)
  target_index = Date::DAYNAMES.index(day_of_week.capitalize)
  start_index = start_datetime.wday
  difference = target_index - start_index
  return start_datetime if difference.zero?

  delta = (difference + 7) % 7
  start_datetime + delta
end