Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

bug in get_times_in_range function

2009-09-24
2013-05-23
  • hanskerkhof
    hanskerkhof
    2009-09-24

    Hi,

    I think I came across a bug in the function get_times_in_range.
    I set up booking calendar to work with 10 minutes time slots. When booking a slot from 07:00 to 07:10 it works fine. But when booking a slot of 07:10 to 07:20 the booking spanned a whole hour, occupying 7 slots. 07:10 to 08:20.

    I think the bug is that when the $start_min > 0 the function also increments the hour (hour++).

    Here is the code i am using to replace the function:

        function get_times_in_range ($min_time = "00:00", $max_time = "24:00",  $time_inc = 30, $include_max_time = false, $debug = false) {
      global $date;
      @list ($year, $month, $day) = explode("-", $date);
      @list ($start_hour, $start_min) = explode(":", $min_time);
      @list ($end_hour, $end_min) = explode(":", $max_time);

      $timestamp_start = mktime((int)$start_hour, (int)$start_min, 0, (int)$month, (int)$day, (int)$year);
      $timestamp_end = mktime((int)$end_hour, (int)$end_min, 0, (int)$month, (int)$day, (int)$year);

      $timestamp_cnt = $timestamp_start;
      while($timestamp_cnt < $timestamp_end){
        $time_strings = date('H:i', $timestamp_cnt);
        $timestamp_cnt = $timestamp_cnt + ($time_inc*60);
      }

      if ($include_max_time) {
      $time_strings = date('H:i', $cnt);
      }
      return $time_strings;
        }

    It wil always return the correct timeslot array, regardles of remainder over an full hour.