function getActiveTimeBetween($start, $end, $work_in_days = false)
{
if (!isset($this->fields['id'])) {
return false;
}
if ($end < $start) {
return 0;
}
$timestart = strtotime($start);
$timeend = strtotime($end);
$datestart = date('Y-m-d', $timestart);
$dateend = date('Y-m-d', $timeend);
// Need to finish at the closing day : set hour to midnight :
/// Before PHP 5.3 need to be 23:59:59 and not 24:00:00
$timerealend = strtotime($dateend . ' 23:59:59');
$activetime = 0;
if ($work_in_days) {
$activetime = $timeend - $timestart;
} else {
$cache_duration = $this->getDurationsCache();
for ($actualtime = $timestart; $actualtime <= $timerealend; $actualtime += DAY_TIMESTAMP) {
$actualdate = date('Y-m-d', $actualtime);
if (!$this->isHoliday($actualdate)) {
$beginhour = '00:00:00';
/// Before PHP 5.3 need to be 23:59:59 and not 24:00:00
$endhour = '23:59:59';
$dayofweek = self::getDayNumberInWeek($actualtime);
$timeoftheday = 0;
if ($actualdate == $datestart) {
// First day : cannot use cache
$beginhour = date('H:i:s', $timestart);
}
if ($actualdate == $dateend) {
// Last day : cannot use cache
$endhour = date('H:i:s', $timeend);
}
if (($actualdate == $datestart || $actualdate == $dateend) && $cache_duration[$dayofweek] > 0) {
$timeoftheday = CalendarSegment::getActiveTimeBetween($this->fields['id'], $dayofweek, $beginhour, $endhour);
} else {
$timeoftheday = $cache_duration[$dayofweek];
}
// echo "time of the day = $timeoftheday ".Html::timestampToString($timeoftheday).'<br>';
$activetime += $timeoftheday;
// echo "cumulate time = $activetime ".Html::timestampToString($activetime).'<br>';
} else {
// echo "$actualdate is an holiday<br>";
}
}
}
return $activetime;
}