Reputation: 5840
I want to build an application that has a model "shop" in it. Each shop has opening times. These opening times can be quite complex. I think the complexity is best demonstrated by examples:
As you can see, there are many complex combinations.
The resulting data structure should support three things:
I have tried to model this into an object structure. My current idea is this:
For each case there is a class implementing it, for example:
Each shop has a list of opening times.
My greatest concern is usability: How do I print the opening times modeled like this, and how do the users enter them?
I'm open to other approaches. Nothing is implemented yet, and my stomach aches when thinking about the approach above...
Upvotes: 3
Views: 589
Reputation: 18408
(As far as the data-modeling tag is concerned) One single entity :
OpeningPeriod(CalendarDay, OpeningHour, ClosingHour)
or
OpeningPeriod(OpeningTimeStamp, ClosingTimeStamp).
A full opening/closing schedule for any shop/org is a set of such opening periods.
Don't try to capture some sort of "generic all-encompassing predicative way" to describe any possible opening/closing schedule "in full", all exceptions and exceptions-to-the-exceptions included. You will fail because there is no end to the nature of the "exceptions". Also you will be hitting serious problems very quickly when you start trying to "prioritise" between rules that overlap.
Just try to build as much "standard" rule-based facilities in the UI as possible, plus a facility to manage the schedule at the lowest detail of OpeningPeriod, for handling any possible "exception left unhandled by the provided rules".
Upvotes: 3