Given a date, how do I find the nearest Monday in Rails?
I know I can do things like:
Date.tomorrow Date.today
Is there something like Date.nearest :mond
Untested, so you might need to finetune, but here you go:
def Date.nearest_monday today = Date.today wday = today.wday if wday > 4 # over the half of the week today + (7 - wday) # next monday else today - (1 + wday) # previous monday end end