title: Google Calendar API algorithm to find open time slots for a given day
body: <p>I'm trying to leverage Google Calendar (and Google Calendar API) for simple scheduling. I'm using PHP, MySQL and google-api-php-client. I'm looking for a algorithm or pseudocode to find open time slots.</p>
  
  <p>My calendar has events for busy times such as when business is closed and for current appointments.  I am able to retrieve event start and end times via two function (Events: list and Freebusy: query). Here is a example list of events for today with start time of 2016-02-19T01:00:00-07:00 and end time of 2016-02-19T23:00:00-07:00 (everything for the current day).</p>
  
  <p><strong>Business is Closed from 12:00am to 11:00am</strong><br>
  start: "2016-02-19T00:00:00-07:00"<br>
  end: "2016-02-19T11:00:00-07:00"</p>
  
  <p><strong>Appointment from 1:30pm to 2:30pm</strong><br>
  start: "2016-02-19T13:30:00-07:00"<br>
  end: "2016-02-19T14:30:00-07:00"</p>
  
  <p><strong>Appointment from 5:00pm to 7:00pm</strong><br>
  start: "2016-02-19T17:00:00-07:00"<br>
  end: "2016-02-19T19:00:00-07:00"</p>
  
  <p><strong>Appointment from 9:00pm to 11:00pm</strong><br>
  start: "2016-02-19T21:00:00-07:00"<br>
  end: "2016-02-19T23:00:00-07:00"  </p>
  
  <p>My open time slots based on this example event set is: 11:00am to 1:30pm, 2:30pm to 5:00pm, 7:00pm to 9:00pm and 11:00pm to 12:00am.</p>
  
  <ol>
  <li>How do I find this set of times programmatically? </li>
  </ol>
  
  <p>Ideally I would like to get a full list of events for a given day with one API call and interpret/manipulate the list instead of making many calls with specific start and end times which would give me the information I'm looking for but be very inefficient. </p>
  
  <ol start="2">
  <li>After I find the set, how do I display results in 30 minute increments i.e. available appointment start times are: </li>
  </ol>
  
  <p>11:00,11:30,12:00,12:30,1:00,2:30,3:00,3:30,4:00,4:30,9:00,9:30,10:00,10:30,11:00,11:30</p>
  
  <p>I'm having a hard time wrapping my head around working with dates/time data sets.</p>
  
  <p>Here is an image of the <a href="http://i.stack.imgur.com/aUCQh.png" rel="nofollow">Google Calendar</a>. Date in question is 2/19/2016</p>
  
  <p>Thank you kindly. Any source that is a result of this discussion will be posted for reference.</p>