From fa098adc78a9031d5f35efc9975775361430bbad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 5 Mar 2014 21:29:33 +0100 Subject: [PATCH] Fix: infinite loop in function num_public_holiday --- htdocs/core/lib/date.lib.php | 12 +++++++----- test/phpunit/DateLibTest.php | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 9e28fda317b..5d336ccc2c2 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -585,7 +585,7 @@ function dol_get_first_day_week($day,$month,$year,$gm=false) } /** - * Fonction retournant le nombre de jour feries samedis et dimanches entre 2 dates entrees en timestamp + * Fonction retournant le nombre de jour feries, samedis et dimanches entre 2 dates entrees en timestamp. Dates must be UTC with hour, day, min to 0 * Called by function num_open_day * * @param timestamp $timestampStart Timestamp de debut @@ -597,7 +597,10 @@ function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR') { $nbFerie = 0; - while ($timestampStart != $timestampEnd) + // Check to ensure we use correct parameters + if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hour and be GMT dates'; + + while ($timestampStart < $timestampEnd) // Loop end when equals { $ferie=false; $countryfound=0; @@ -707,9 +710,9 @@ function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR') // On incremente compteur if ($ferie) $nbFerie++; - // Incrementation du nombre de jour (on avance dans la boucle) + // Increase number of days (on go up into loop) $jour++; - $timestampStart=mktime(0,0,0,$mois,$jour,$annee); + $timestampStart=dol_mktime(0,0,0,$mois,$jour,$annee,1); // Generate GMT date for next day } return $nbFerie; @@ -765,7 +768,6 @@ function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $ha //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday; if ($timestampStart < $timestampEnd) { - //print num_between_day($timestampStart, $timestampEnd, $lastday).' - '.num_public_holiday($timestampStart, $timestampEnd); $nbOpenDay = num_between_day($timestampStart, $timestampEnd, $lastday) - num_public_holiday($timestampStart, $timestampEnd, $lastday); $nbOpenDay.= " " . $langs->trans("Days"); if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); diff --git a/test/phpunit/DateLibTest.php b/test/phpunit/DateLibTest.php index d5567ab55b3..8cf7520f9fd 100644 --- a/test/phpunit/DateLibTest.php +++ b/test/phpunit/DateLibTest.php @@ -150,7 +150,7 @@ class DateLibTest extends PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals(1,$result); - // With different date before and after sunlight hour (day to change is 2014-03-30) + // With different date before and after sunlight hour (day to change sunlight hour is 2014-03-30) $date1=dol_mktime(0, 0, 0, 3, 28, 2014, true); $date2=dol_mktime(0, 0, 0, 3, 31, 2014, true);