title: How to check for conflict with multiple datetime RANGES
body: <p>I am stumped about how to go about checking to see if multiple *date/time value -ranges- (meaning: start <strong>and</strong> end times) are in conflict with one another.</p>
  
  <p>Summary &amp; samples of data I need to work with.</p>
  
  <p>I have an (app) events table, that is used to create a form for the user to go through and check off (checkboxes) all the sessions/events they attended.</p>
  
  <p>The names of the checkboxes are generated using info about the session.  (month/day start/end times along with a session id)</p>
  
  <p>ie:  hours_9_5_p02_800_845</p>
  
  <pre><code>9 = month
  5 = date
  p02 = session id/event code
  800 = start time
  845 = end time
  </code></pre>
  
  <p>all delimited by an underscore ("_")</p>
  
  <p>If the user checks (and submits) multiple sessions, there will be many of these values to check for a time conflict..</p>
  
  <pre><code>hours_9_5_p08_755_800
  hours_9_5_p02_800_845
  hours_9_5_p02_800_855
  hours_9_5_p03_800_845
  hours_9_5_p04_820_835
  hours_9_5_p04_845_900
  hours_9_5_REG_900_915
  hours_9_5_REG_1300_1305
  hours_9_5_REG_1310_1335
  hours_9_5_REG_1320_1335
  </code></pre>
  
  <p>The above is an example of the fieldlist/array that I 'could' get as a user selection/submission that I need to check for any possible conflicts (obviously the user couldnt be two places at once) :)  And the above have many/several overlapping of just the same exact time slots selected.</p>
  
  <p>** I am open to either PHP, (checking after the user submits) or javascript/jQuery  (if it can do the date/time RANGE conflict checking, it might be easier to then highlight those rows/elements on the page if done on the front end)</p>
  
  <p>I'd image, first you need to parse those checkbox names/strings from the fieldlist array...</p>
  
  <p>which I have done like so:  (php)</p>
  
  <pre><code>function conflictParse($delimiter, $targetString){
      //echo 'fired';
      $breakDown = explode($delimiter, $targetString);
      $startTime = substr_replace($breakDown[4] , ':', -2, 0);
      $endTime = substr_replace($breakDown[5] , ':', -2, 0);
      $startString = "$breakDown[1]/$breakDown[2]/2015 $startTime";
      $endString = "$breakDown[1]/$breakDown[2]/2015 $endTime";
      $startFormat = strtotime($startString);
      $endFormat = strtotime($endString);
      $start = date('m/d/Y G:i',$startFormat);
      $end = date('m/d/Y G:i',$endFormat);
  
      return "Session Times: $start -- $end &lt;br&gt;";
  }
  echo conflictParse('_','hours_9_5_p02_800_845');
  </code></pre>
  
  <p>but I am not clear on HOW to go about using this RANGE of a date start &amp; end time to check against <strong>MULTIPLE</strong> other date start/end time <strong>RANGES</strong>?</p>
  
  <p>maybe just sticking with having PHP parse/check conflict upon submit and then return some array of the (original) names page to the page  (for some jQuery to use and highlight the elements..etc  (but I can handle that aspect later.. for right now I am need help on how I can get the above parse 'date/time' start/end range values checked for conflicts against other 'date/time' start/end range values</p>
  
  <p>update:</p>
  
  <p>Here is the current nested associative array I have to work with for comparing:  </p>
  
  <pre><code>Array ( 
      [0] =&gt; Array ( 
          [id] =&gt; hours_9_9_p02_800_845 
          [fullStart] =&gt; 09/09/2015 8:00 
          [fullEnd] =&gt; 09/09/2015 8:45 
          [month] =&gt; 9 
          [date] =&gt; 9 
          [session_code] =&gt; p02 
          [start] =&gt; 8:00 
          [end] =&gt; 8:45 
          [hasConflict] =&gt; false 
      ) 
      [1] =&gt; Array ( 
          [id] =&gt; hours_9_9_p02_800_855 
          [fullStart] =&gt; 09/09/2015 8:00 
          [fullEnd] =&gt; 09/09/2015 8:55 
          [month] =&gt; 9 
          [date] =&gt; 9 
          [session_code] =&gt; p02 
          [start] =&gt; 8:00 
          [end] =&gt; 8:55 
          [hasConflict] =&gt; false 
      ) 
      [2] =&gt; Array ( 
          [id] =&gt; hours_9_9_p03_800_845 
          [fullStart] =&gt; 09/09/2015 8:00 
          [fullEnd] =&gt; 09/09/2015 8:45 
          [month] =&gt; 9 
          [date] =&gt; 9 
          [session_code] =&gt; p03 
          [start] =&gt; 8:00 
          [end] =&gt; 8:45 
          [hasConflict] =&gt; false 
      ) 
      [3] =&gt; Array ( 
          [id] =&gt; hours_9_9_p04_820_830 
          [fullStart] =&gt; 09/09/2015 8:20 
          [fullEnd] =&gt; 09/09/2015 8:30 
          [month] =&gt; 9 
          [date] =&gt; 9 
          [session_code] =&gt; p04 
          [start] =&gt; 8:20 
          [end] =&gt; 8:30 
          [hasConflict] =&gt; false 
      ) 
      [4] =&gt; Array ( 
          [id] =&gt; hours_9_9_p04_845_900 
          [fullStart] =&gt; 09/09/2015 8:45 
          [fullEnd] =&gt; 09/09/2015 9:00 
          [month] =&gt; 9 
          [date] =&gt; 9 
          [session_code] =&gt; p04 
          [start] =&gt; 8:45 
          [end] =&gt; 9:00 
          [hasConflict] =&gt; false 
      ) 
      [5] =&gt; Array ( 
          [id] =&gt; hours_9_9_REG_1300_1315 
          [fullStart] =&gt; 09/09/2015 13:00 
          [fullEnd] =&gt; 09/09/2015 13:15 
          [month] =&gt; 9 
          [date] =&gt; 9 
          [session_code] =&gt; REG 
          [start] =&gt; 13:00 
          [end] =&gt; 13:15 
          [hasConflict] =&gt; false 
      ) 
      [6] =&gt; Array ( 
          [id] =&gt; hours_9_9_REG_1300_1330 
          [fullStart] =&gt; 09/09/2015 13:00 
          [fullEnd] =&gt; 09/09/2015 13:30 
          [month] =&gt; 9 
          [date] =&gt; 9 
          [session_code] =&gt; REG 
          [start] =&gt; 13:00 
          [end] =&gt; 13:30 
          [hasConflict] =&gt; false 
      ) 
  ) 
  </code></pre>
  
  <p>I need to convert your js functions over to PHP and of course use the fullStart/fullEnd variables in my time compares I guess..??</p>
  
  <p>(but your function is still confusing me as I see references to event1, event 2.. (to match your example)..</p>
  
  <p>update 2:</p>
  
  <p>The above is my object/array (associative array) that I got from selecting some check boxes, and submitting my form...</p>
  
  <p>Here is my attempt to convert your JS code to PHP based [with some update variablenames]:  (and the commented out lines just to try and get some sort of output somewhere)</p>
  
  <pre><code>print_r($conflict_list);
  
      function checkFirst($cf_presX, $cf_presY) {
          //$cf_presX['fullStart'] &lt; $cf_presY['fallStart'] ? checkConflict($cf_presX, $cf_presY) : checkConflict($cf_presY, $cf_presX);
  
          echo 'Pres Check: '.$cf_presX[0] . '&lt;br&gt;';
          echo 'Pres Check: '.$cf_presY[0] . '&lt;br&gt;';
          /*
          function checkConflict ($cc_presX, $cc_presY) {      
              if ($cc_presX.['fullEnd'] &gt; $cc_presY.['fullStart']) {
                  $cc_presX.['hasConflict'] = true;
                  $cc_presY.['hasConflict'] = true;
              }
          }
          */
      }
  
      function setConflicts($events) {
          for ($i = 0; $i &lt; count($events); $i++) {
              for ($j = 0; $i &lt; count($events); $j++) {
                // if it is not the same event
                // if (i !== j) is the same $age['Peter']
                if ($events[$i]['id'] !== $events[$j]['id']) {
                  checkFirst($events[$i], $events[$j]);
                }
              }
          }
      }
      setConflicts($conflict_list);
  </code></pre>
  
  <p>I just keep getting a loop with undefined offset: (counting up to the 100k+ mark)</p>
  
  <blockquote>
    <p>Notice: Undefined offset: 0 in
    C:\wamp\www\projects\misc\conflict_check_new.php on line 49 Pres
    Check:</p>
    
    <p>Notice: Undefined offset: 0 in
    C:\wamp\www\projects\misc\conflict_check_new.php on line 50 Pres
    Check:</p>
    
    <p>Notice: Undefined offset: 0 in
    C:\wamp\www\projects\misc\conflict_check_new.php on line 49 Pres
    Check:</p>
  </blockquote>