Reputation: 1608
My app have several stores. Some stores are open from say 12PM til 04AM the following day.
The issue with our current code is that we store open time and close time. Now that means for the first day you can put 12PM - 11:59PM but the next day it's still open for another 4 hours, before it again opens up at 12PM and technically closes at 1 minute before midnight.
Does anybody have any experience with this issue, and how did you go about solving this and setting it up in the DB?
Upvotes: 3
Views: 787
Reputation: 8345
Instead of storing [start, end]
, store [start, duration]
.
If you want to allow for multiple intervals, store multiple of those pairs per store.
Upvotes: 1
Reputation: 14038
To solve this and any other number of complex cases you might benefit from opening times being a relation, or some form of collection.
For example, a shop that is open from 9-5 but closes an hour for lunch would have two open_periods
, covering each half of their day.
In this method your shop would have a period starting at midnight and ending at 4am, another starting at midday and ending at 23:59:59.
I would suggest then coupling this with an "opening_times" string field for a simple, human readable opening times string.
Add to this @MaxWilliams suggestion of opening periods being a start time and a duration, and you have a very flexible system.
Upvotes: 1