Rails: Is there away to get the Date object that is the closest Monday to today?

后端 未结 5 957
误落风尘
误落风尘 2021-02-07 12:54

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

5条回答
  •  孤城傲影
    2021-02-07 13:11

    Assuming you want both directions: Date.today.beginning_of_week + 7*(Date.today.wday/5)

提交回复
热议问题