title: round time down if full hour, or up if it exeeds a full hour in php?
body: <p>I'm trying to calculate the duration of services in order to get the end time. Each service has a duration value in minutes, and those are: <code>30</code>, <code>40</code>, <code>50</code>.</p>
  
  <p>Every session starts at a full hour (e.g. 11:00, 12:00, 13:00).</p>
  
  <p>If the total duration lands on a full hour (e.g. 12:00, 13:00, 14:00), it should be set to the hour before, and 59 minutes (e.g. 11:59, 12:59, 13:59). This happens if two 30 minutes services is selected - for example.   </p>
  
  <p>But if it passes an hour, say that the end time is 12:20 or 13:30, then the end time should be set to 12:59 or 13:59.</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>$startTime = $_POST['datetime'];  //  (2015-09-09 11:00)
  
  #   calculate total duration of services in order to get end time
      foreach($_POST['service'] as $service){
          list($service_id,$service_duration) = explode(';',$service);  //  values stored as id;duration
          $service_ids[] = (int)$service_id;  //  new array with ids
          $services_duration_total += (int)$service_duration;  //  in minutes
      }
  //
  #   calculate end time
      $endTime_actual = getdate(strtotime('+'.$services_duration_total.' minutes', strtotime($_POST['datetime'])));  //  actual end time
  </code></pre>
  
  <p>I tried this method:</p>
  
  <pre><code>$endTime_offset = (60-$endTime_actual['minutes'])-1;  //  calculate munutes left in the hour
  $endTime = date('Y-m-d H:i',strtotime('+'.$endTime_offset.' minutes',$endTime_actual[0]));  //  new end time
  </code></pre>
  
  <p>This works if the total duration exceeds 60 minutes, but not if it is exactly 60 minutes, or 120 or 180 for that matter, because it then lands on a full hour. In those cases, as I mentioned, I need the script to round down to last hour, and 59 minutes..</p>
  
  <p>I'm not sure if I explained this correctly, but hopefully you get what I'm trying to accomplish..</p>