Ejemplo n.º 1
0
 /**
  *
  * @param float $start_hour
  * @param float $end_hour
  * @param float $step_hour
  * @return array
  */
 public static function get_time_array($start_hour, $end_hour, $step_hour, $minimum_hour = null, $maximum_hour = null, $locale = null)
 {
     if (!is_numeric($start_hour) && !is_numeric($end_hour) && $step_hour > 0) {
         $sql_date1 = DateTool::datetime_to_sql($start_hour, $locale);
         $sql_date2 = DateTool::datetime_to_sql($end_hour, $locale);
         //			debug($sql_date1);
         //			debug($sql_date2);
         $timestamp1 = strtotime($sql_date1);
         $timestamp2 = strtotime($sql_date2);
         $hour_difference = ($timestamp2 - $timestamp1) / 3600;
         //debug($hour_difference);
         $start_hour = DateTool::get_hour_as_float($start_hour);
     } elseif (is_numeric($start_hour) && is_numeric($end_hour) && $start_hour < $end_hour && $step_hour > 0) {
         $hour_difference = $end_hour - $start_hour;
         //debug($hour_difference);
     }
     if (isset($hour_difference)) {
         //debug($hour_difference);
         $times = array();
         $current_time = $start_hour;
         $end_hour = $start_hour + $hour_difference;
         //debug($end_hour);
         while ($current_time < $end_hour) {
             if (isset($minimum_hour) && isset($maximum_hour)) {
                 if ($minimum_hour <= $current_time && $current_time < $maximum_hour) {
                     $times[] = DateTool::get_time_from_hour($current_time);
                 }
             } elseif (!isset($minimum_hour) && isset($maximum_hour)) {
                 if ($current_time < $maximum_hour) {
                     $times[] = DateTool::get_time_from_hour($current_time);
                 } else {
                     /*
                      * Max time has been overcome
                      */
                     break;
                 }
             } elseif (isset($minimum_hour) && !isset($maximum_hour)) {
                 if ($minimum_hour <= $current_time) {
                     $times[] = DateTool::get_time_from_hour($current_time);
                 }
             } else {
                 $times[] = DateTool::get_time_from_hour($current_time);
             }
             $current_time += $step_hour;
         }
         //debug($times);
         return $times;
     }
 }