Module: Service::DateTime
- Defined in:
- lib/service/time_zone.rb
Class Method Summary collapse
-
.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.
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
66 67 68 69 70 71 72 73 74 |
# File 'lib/service/time_zone.rb', line 66 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 |