I have been cracking my head trying to resolve this problem.
I need to know how many minutes of the day are being worked by a staff member alone in the shop.
Here is the data for daynumber = 0 (monday):
For this day, the staff member with staffid = 32 is alone from 11:00 to 11:05 in the shop.
What I have so far, is just adding all starting times, but basically what I'm thinking is, if I have any way of knowing a staff member is alone, I can calculate time between the index and the next.
for($i=0; $i<count($results); $i++){
if(isset($results[$i+1])){
if($results[$i]->starttime < $results[$i+1]->starttime)
$start = strtotime($results[$i]->starttime);
$end = strtotime($results[$i+1]->endtime);
$minutes += idate('i', $end - $start);
}
}
}
Any thoughts?
UPDATE 1: I get to this but still no luck;
for($i=0; $i<count($results); $i++){
if(isset($results[$i+1])){
$StartDate1 = strtotime($results[$i]->starttime);
$EndDate1 = strtotime($results[$i]->endtime);
$StartDate2 = strtotime($results[$i+1]->starttime);
$EndDate2 = strtotime($results[$i+1]->endtime);
if(($StartDate1 <= $EndDate2) && ($EndDate1 >= $StartDate2)){
$StartDate1 = idate('i', $StartDate1);
$EndDate1 = idate('i', $EndDate1);
$StartDate2 = idate('i', $StartDate2);
$EndDate2 = idate('i', $EndDate2);
$a = abs($EndDate1 - $StartDate1);
$b= abs($EndDate1 - $StartDate2);
$c = abs($EndDate2 - $StartDate2);
$d = abs($EndDate2 - $StartDate1);
$minutes += min([$a,$b,$c,$d]);
}
}
}
What am I doing wrong?