Php - divide time period into equal intervals

Posted by experc on Stack Overflow See other posts from Stack Overflow or by experc
Published on 2010-12-27T07:49:32Z Indexed on 2010/12/27 7:54 UTC
Read the original article Hit count: 244

Filed under:
|
|

Hi! I am working on my php course project and for the past few days I have stucked at the point where I have to create php function which gets 5 parameters which represents information about the working time of some department - when the work starts/ends, when the lunchtime (or any other break) starts/ends and integer representing minutes into how small piecies we should divide time period. Besides - it's possible that there are not any breaks in the working time. The function should return all intervals from working time.

function split_time_into_intervals($work_starts,$work_ends,$break_starts=null;
          $break_ends=null,$minutes_per_interval=60){
$intervals=array();
//all of the function code
return $intervals;
}

So if I have the following parameters for the function

    function split_time_into_intervals("8:30","14:50","11:45";
          "12:25"){
..
}

I would like to retrieve the following array:

$intervals[0]['starts']="8:30";
$intervals[0]['ends']="9:30";
$intervals[1]['starts']="9:30";
$intervals[1]['ends']="10:30";
$intervals[2]['starts']="10:30";
$intervals[2]['ends']="11:30";
$intervals[3]['starts']="11:30";
$intervals[3]['ends']="11:45";
//this interval was smaller than 60 minutes - because of the break (which starts at 11:45)
$intervals[4]['starts']="12:25";//starts when the break ends
$intervals[4]['ends']="13:25"; // interval is again 60 minutes
$intervals[5]['starts']="13:25";
$intervals[5]['ends']="14:25";
$intervals[6]['starts']="14:25";
$intervals[6]['ends']="14:50";
//this period is shorter than 60 minutes - because work ends 

Any advises? I would apriciate any php (or C#) code regarding to this problem!

© Stack Overflow or respective owner

Related posts about php

Related posts about time