Browse Source

FIX Quick hack to solve pb of bad definition of public holidays

Laurent Destailleur 6 years ago
parent
commit
88ff7241f5
2 changed files with 43 additions and 0 deletions
  1. 23 0
      htdocs/core/lib/date.lib.php
  2. 20 0
      test/phpunit/DateLibTest.php

+ 23 - 0
htdocs/core/lib/date.lib.php

@@ -573,6 +573,8 @@ function dol_get_first_day_week($day,$month,$year,$gm=false)
  */
 function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0)
 {
+	global $conf;
+
 	$nbFerie = 0;
 
 	// Check to ensure we use correct parameters
@@ -588,6 +590,27 @@ function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $
 		$jour  = date("d", $timestampStart);
 		$mois  = date("m", $timestampStart);
 		$annee = date("Y", $timestampStart);
+
+
+		// Check into var $conf->global->HOLIDAY_MORE_DAYS   MM-DD,YYYY-MM-DD, ...
+		if (! empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS))
+		{
+			$arrayofdaystring=explode(',',$conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS);
+			foreach($arrayofdaystring as $daystring)
+			{
+				$tmp=explode('-',$daystring);
+				var_dump($tmp);
+				if ($tmp[2])
+				{
+					if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie=true;
+				}
+				else
+				{
+					if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie=true;
+				}
+			}
+		}
+
 		if ($countrycode == 'FR')
 		{
 			$countryfound=1;

+ 20 - 0
test/phpunit/DateLibTest.php

@@ -205,6 +205,26 @@ class DateLibTest extends PHPUnit_Framework_TestCase
         $result=num_public_holiday($date1,$date2,'XX',1);
         print __METHOD__." result=".$result."\n";
         $this->assertEquals(2,$result,'NumPublicHoliday for XX');   // 1 opened day, 2 closed days (even if country unknown)
+
+        $conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS='12-13,2019-12-14';
+
+        $date1=dol_mktime(0, 0, 0, 12, 13, 2018);
+        $date2=dol_mktime(0, 0, 0, 12, 13, 2018);
+        $result=num_public_holiday($date1,$date2,'YY',1);
+        print __METHOD__." result=".$result."\n";
+        $this->assertEquals(1,$result,'NumPublicHoliday for YY the 2018-12-13');   // 0 opened day, 1 closed days (even if country unknown)
+
+        $date1=dol_mktime(0, 0, 0, 12, 14, 2018);
+        $date2=dol_mktime(0, 0, 0, 12, 14, 2018);
+        $result=num_public_holiday($date1,$date2,'YY',1);
+        print __METHOD__." result=".$result."\n";
+        $this->assertEquals(0,$result,'NumPublicHoliday for YY the 2018-12-14');   // 1 opened day, 0 closed days (even if country unknown)
+
+        $date1=dol_mktime(0, 0, 0, 12, 14, 2019);
+        $date2=dol_mktime(0, 0, 0, 12, 14, 2019);
+        $result=num_public_holiday($date1,$date2,'YY',1);
+        print __METHOD__." result=".$result."\n";
+        $this->assertEquals(1,$result,'NumPublicHoliday for YY the 2019-12-14');   // 0 opened day, 1 closed days (even if country unknown)
     }
 
     /**