In my application users should be able to define dates when they are available. Ie. user joe may define he’s available:
– at every monday, wednesday and sunday between 15:00 and 17:00 from 1.09.2009 to 15.11.2009.
– at 2.09.2009 between 12:00 and 14:00
and so on…
Dates may be defined maximum 1 year in future.
Users may add, edit and delete defined dates.
Other users may search available users ie.
– find all users available 8.09.2009 at 15:30
The problem is how to design sql tables, which allow creating and editing cyclic dates and efficient searching.
I’m using postgresql but rather looking for any guidelines. Maybe someone has experience with similar problem?
Thanks in advance
When I’ve dealt with data like this before, I’ve taken a “rules” approach similar to this to accomodate by-day scheduling and block scheduling:
Note: You would need to add additional constraints to the rules table to make sure that end_date + end_time >= start_date + start_time, etc.
Then, you can create an “availability” view to generate a normalized schedule with user_id, date, start_time, and end_time. Using 8.4, this is easy with the new generate_series datetime capabilities. (http://www.postgresql.org/docs/current/static/functions-srf.html) It is easy enough to write a function that does the same thing if you’re on 8.3 or earlier.