How would you store a business's hours in the db/model of a Rails app?

后端 未结 5 747
余生分开走
余生分开走 2021-01-31 05:43

I\'m creating a Rails app that will store the opening and closing hours for a business. Originally, I thought of simply using a text data type and letting it be free-form:

5条回答
  •  生来不讨喜
    2021-01-31 06:37

    So I just found out ice_cube can handle recurring durations:

    > schedule = IceCube::Schedule.new(Time.now, :duration => 3600)
    > schedule.add_recurrence_rule Rule.daily
    > schedule.occurs_at?(Time.now + 1000)
    true
    > schedule.occurs_at?(Time.now + 1.day + 1000)
    true
    > schedule.occurs_at?(Time.now + 4000)
    false
    

    I suspect that you can handle a lot of different situations using ice_cube in this manner.

    Incidentally, I'm implementing a similar open/closed business schedule. I'd be interested to know how you've done it, and if you have a github repo we can collaborate on together.

提交回复
热议问题