You are not logged in.
Pages: 1
Topic closed
This function does not consider the closing day of the ticket.
The for loop is wrong!!
This is a possible solution:
function getActiveTimeBetween($start, $end, $force_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);
$datestartCiclo = strtotime($datestart);
$dateend = date('Y-m-d',$timeend);
$dateendCiclo = strtotime($dateend);
$activetime = 0;
if ($force_work_in_days) {
$activetime = $timeend-$timestart;
} else {
$cache_duration = importArrayFromDB($this->fields['cache_duration']);
for ($datestartCiclo; $datestartCiclo<=$dateendCiclo ; $datestartCiclo+=DAY_TIMESTAMP) {
$actualdate = date('Y-m-d',$datestartCiclo);
if (!$this->isHoliday($actualdate)) {
$beginhour = '00:00:00';
$endhour = '24:00:00';
$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 ".timestampToString($timeoftheday).'<br>';
$activetime+=$timeoftheday;
// echo "cumulate time = $activetime ".timestampToString($activetime).'<br>';
} else {
// echo "$actualdate is an holiday<br>";
}
}
}
return $activetime;
}
Offline
the for loop check all days. The if (!$this->isHoliday($actualdate)) do the job by checking closing days...
I do not understand your changes.
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
The for loop don't check the last day .
Your function doesn't calculate the hours of the closing day of the ticket.
With my changes, the function returns the hours worked also in the closing days of the ticket.
You must add the DAY_TIMESTAMP on the date without hh:mm:ss, otherwise the for loop doesn't consider the closing date.
Trust me...
Offline
Could you give us a real example because all the tests I do not cause troubles.
You say : "the function returns the hours worked also in the closing days of the ticket."
But this is a closing day so no hour must be take into account...
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
your solution have troubles :
$dayofweek = self::getDayNumberInWeek($actualtime);
$actualtime is not set...
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
Test the function with two dates with different days...
I need to get the real worked HOUR (not days) between two date.
When I set the variable $force_work_in_days to false, inside the for loop there is an if statement:
if ($actualdate==$dateend) { // Last day : cannot use cache
$endhour = date('H:i:s',$timeend);
}
As you can see, the procedure never goes inside this if, because the $actualdate value isn't the same of $dateend value... never! Then the variable $endhour is never set on the last day.
As I explained before, the for loop must be only on the days number, without time.
I have solved the problem whith my edit.
Offline
You say : "the function returns the hours worked also in the closing days of the ticket."
But this is a closing day so no hour must be take into account...
Why?
If I need to get the real worked HOUR between two date, I also need the worked hours in the closing days.
The procedure already provides this with:
if ($actualdate==$dateend) { // Last day : cannot use cache
$endhour = date('H:i:s',$timeend);
}
, but the procedure never goes inside here.
Last edited by Von_Neumann (2011-08-24 13:10:13)
Offline
misunderstanding I think :
closing day for me = holidays / non working days
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
I found an example with troubles.
The proposed solution : https://forge.indepnet.net/projects/glp … ions/15498
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
Your proposed solution is good, but ther's an error.
Put
$timerealend = strtotime($dateend.' 23:59:59');
instead
$timerealend = strtotime($dateend.' 24:00:00');
otherwise the strtotime function return false (my PHP version is 5.2.17).
When this is done, the problem is solved (for me).
Thanks
Offline
misunderstanding I think :
closing day for me = holidays / non working days
Yes, there was a misunderstanding...
I meant the closing date of the ticket.
Offline
Your proposed solution is good, but ther's an error.
Put
$timerealend = strtotime($dateend.' 23:59:59');
instead
$timerealend = strtotime($dateend.' 24:00:00');otherwise the strtotime function return false (my PHP version is 5.2.17).
When this is done, the problem is solved (for me).
Thanks
Yes this is a problem before PHP 5.3.
I will fixed it
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
This problem is present several times is the calendar files :
All the fixes here : https://forge.indepnet.net/projects/glp … 15504/diff
Could you check if all is ok ? thanks for your contribution.
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
This problem is present several times is the calendar files :
All the fixes here : https://forge.indepnet.net/projects/glp … 15504/diffCould you check if all is ok ? thanks for your contribution.
I confirm that everything is ok now.
Perhaps it is not necessary to change all $endhour variables, because used by mysql (I think).
But even with these changes the class goes well.
Thanks
Last edited by Von_Neumann (2011-08-25 18:16:33)
Offline
all of them (minus 1) are passed to getActiveTimeBetween... So need to be 23:59:59 because strtotime will be done.
MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI : Support Contribute References Freshmeat
Offline
all of them (minus 1) are passed to getActiveTimeBetween... So need to be 23:59:59 because strtotime will be done.
ok ... I trust you :-D
Thanks again
Offline
Pages: 1
Topic closed