How to calculate next, previous business day in Rails?

前端 未结 12 2337
粉色の甜心
粉色の甜心 2021-02-08 08:43

How to calculate next and previous business days in Rails?

12条回答
  •  清歌不尽
    2021-02-08 09:21

    Well, you can use something like yesterday = 1.days.ago to get yesterday's date. Use yesterday.strftime('%w') to get the day of the week as a integer (0=Sunday, 6=Saturday). If yesterday is 0 (Sunday), then the previous day of the week would be 3.days.ago ... you get the idea.

    And you can use tomorrow = 1.days.since to get tomorrow's date.

提交回复
热议问题