You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2011-08-18 17:37:30

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

error in function "getActiveTimeBetween" calendar.class.php

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

#2 2011-08-18 21:14:39

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#3 2011-08-19 11:27:21

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

Re: error in function "getActiveTimeBetween" calendar.class.php

The for loop don't check the last day  wink .
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...  smile

Offline

#4 2011-08-23 17:04:47

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#5 2011-08-23 17:07:10

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#6 2011-08-24 12:58:45

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#7 2011-08-24 13:08:17

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

Re: error in function "getActiveTimeBetween" calendar.class.php

MoYo wrote:

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

#8 2011-08-24 14:38:46

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

misunderstanding I think :
closing day for me = holidays / non working days


MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI :    Support     Contribute     References     Freshmeat

Offline

#9 2011-08-24 15:55:14

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#10 2011-08-25 11:48:07

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#11 2011-08-25 15:22:05

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

Re: error in function "getActiveTimeBetween" calendar.class.php

MoYo wrote:

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

#12 2011-08-25 17:01:33

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

Von_Neumann wrote:

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

#13 2011-08-25 17:09:04

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#14 2011-08-25 18:09:07

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

Re: error in function "getActiveTimeBetween" calendar.class.php

MoYo wrote:

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.

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

#15 2011-08-25 23:32:28

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: error in function "getActiveTimeBetween" calendar.class.php

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

#16 2011-08-26 17:55:57

Von_Neumann
Member
Registered: 2011-08-18
Posts: 21

Re: error in function "getActiveTimeBetween" calendar.class.php

MoYo wrote:

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

Board footer

Powered by FluxBB