static function getActiveTimeBetween($calendars_id, $day, $begin_time, $end_time)
{
global $DB;
$sum = 0;
// Do not check hour if day before the end day of after the begin day
$query = "SELECT TIMEDIFF(LEAST('{$end_time}',`end`),\n GREATEST(`begin`,'{$begin_time}')) AS TDIFF\n FROM `glpi_calendarsegments`\n WHERE `calendars_id` = '{$calendars_id}'\n AND `day` = '{$day}'\n AND (`begin` < '{$end_time}')\n AND ('{$begin_time}' < `end`)";
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
list($hour, $minute, $second) = explode(':', $data['TDIFF']);
$sum += $hour * HOUR_TIMESTAMP + $minute * MINUTE_TIMESTAMP + $second;
}
}
}
return $sum;
}