homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Fill in missing events

 2:51 am on Feb 5, 2014 (gmt 0)

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.



 4:41 am on Feb 5, 2014 (gmt 0)

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.


 8:32 am on Feb 5, 2014 (gmt 0)

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.

For making your list: an array seems appropriate.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved