I have a database of events (which I pull regularly from an API). Each event has a begin and end time (format YYYY-MM-DD HH:MM:SS). I'm using PHP to displaying these events on a HTML table calendar. So far no problem.
I need to show an "available" message between events. For example, if there is an event from 06:12 to 09:55, I need the calendar to display a message saying "available" from 00:00 to 06:12, and again from 09:55 to 23:59. There could (and usually will be) multiple events and multiple availability periods each day.
What's the best approach here? My puzzler has puzzled itself sore.
I populate such calendars with all spots "available" EXCEPT for the spots that are specifically scheduled (ie, overwrites the "avaiable" with the specific sheduled event). Saves time and is accurate in that all NOT scheduled times are available.
For the period you're going to display (I've no idea which, but that one) Create one available "event" from begin to end is a one item list Loop over the results of the "busy" events in your database For every busy event, you add, to your list, taking care to deal with all possible cases and edge cases. Once that's done: take care to remove any zero or 1 sec length (or wherever you set your threshold) available slots, and finally split up the available slots that cross a date boundary (as that seems a requirement from your post).
In the end you'll have a lot of code I'm afraid due to the edge cases.