Comparing times only, without dates?

后端 未结 8 1253
不知归路
不知归路 2021-01-31 16:30

I need to write a method that will check if Time.now is in between the open hours and the close hours of a shop.

The open and close hours are saved as a Tim

8条回答
  •  一个人的身影
    2021-01-31 16:51

    There is a nice library https://github.com/bokmann/business_time which will do this and more for you.

    BusinessTime::Config.with(beginning_of_workday: "8:30 am", end_of_workday: "5:30 pm") do
      Time.now.during_business_hours?
    end
    

    It will do much more for you, like rolling a time to next or previous opening time, counting business hours between two timestamps, etc.

提交回复
热议问题