Module: Weekends::Nearest
- Included in:
- Weekend
- Defined in:
- lib/weekends/nearest.rb
Constant Summary collapse
- DAY =
86_400
Instance Method Summary collapse
- #nearest_full_weekends(date) ⇒ Object
- #nearest_saturday(date) ⇒ Object
- #nearest_sunday(date) ⇒ Object
Instance Method Details
#nearest_full_weekends(date) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/weekends/nearest.rb', line 21 def nearest_full_weekends(date) date = time_coerced(date) if on_date?(date) current_weekend_end = nearest_sunday(date) next_saturday = nearest_saturday(current_weekend_end) next_sunday = nearest_sunday(current_weekend_end) next_saturday..next_sunday else nearest_saturday(date)..nearest_sunday(date) end end |
#nearest_saturday(date) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/weekends/nearest.rb', line 5 def nearest_saturday(date) date = time_coerced(date) wday = date.wday diff = wday == 6 ? 7 : 6 - wday date + diff * DAY end |
#nearest_sunday(date) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/weekends/nearest.rb', line 13 def nearest_sunday(date) date = time_coerced(date) wday = date.wday diff = wday == 7 ? 7 : 7 - wday date + diff * DAY end |