I would say that your time interval should be as follows:
TimeSlot rental_id : int -> foreign key to your rental table (housing, whatever) start_time : time end_time : time day_of_week : int 1-7
Then a search from availability between two points will be: (let's call these AVAILABLE_SLOTS)
( (wanted_start_time >= TimeSlotTable.start_time && wanted_start_time <= TimeSlotTable.end_time) OR (wanted_end_time >= TimeSlotTable.start_time && wanted_end_time <= TimeSlotTable.end_time) ) AND Optionally: ( wanted_day_of_week = TimeSlotTable.day_of_week)
where TimeSlotTable is the name of your table.
Then, if you really want to get more detail from the query, you might have an exception table. That is, a table in which the owner of the lease indicates if they are not available on a certain day, which will require the user interface to request a date in addition to the time. (let's call it EXCEPTIONS)
ExceptionTimeSlot rental_id : int -> foreign key to your rental table (housing, whatever) date : date
and request:
( wanted_date = ExceptionTimeSlotTable.date)
Finally, you want rent_ids to be in AVAILABLE_TIMESLOTS, but not in EXCEPTIONS.
All this is similar to an event calendar, so you can select an even calendar and configure it for your purposes and call the time intervals of events.
source share