dolibarr  9.0.0
date.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2011-2015 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  * or see http://www.gnu.org/
20  */
21 
33 function get_tz_array()
34 {
35  $tzarray=array(
36  -11=>"Pacific/Midway",
37  -10=>"Pacific/Fakaofo",
38  -9=>"America/Anchorage",
39  -8=>"America/Los_Angeles",
40  -7=>"America/Dawson_Creek",
41  -6=>"America/Chicago",
42  -5=>"America/Bogota",
43  -4=>"America/Anguilla",
44  -3=>"America/Araguaina",
45  -2=>"America/Noronha",
46  -1=>"Atlantic/Azores",
47  0=>"Africa/Abidjan",
48  1=>"Europe/Paris",
49  2=>"Europe/Helsinki",
50  3=>"Europe/Moscow",
51  4=>"Asia/Dubai",
52  5=>"Asia/Karachi",
53  6=>"Indian/Chagos",
54  7=>"Asia/Jakarta",
55  8=>"Asia/Hong_Kong",
56  9=>"Asia/Tokyo",
57  10=>"Australia/Sydney",
58  11=>"Pacific/Noumea",
59  12=>"Pacific/Auckland",
60  13=>"Pacific/Enderbury"
61  );
62  return $tzarray;
63 }
64 
65 
72 {
73  return @date_default_timezone_get();
74 }
75 
82 function getServerTimeZoneInt($refgmtdate='now')
83 {
84  global $conf;
85  if (method_exists('DateTimeZone','getOffset'))
86  {
87  // Method 1 (include daylight)
88  $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d');
89  if ($refgmtdate == 'now') $newrefgmtdate=$yearref.'-'.$monthref.'-'.$dayref;
90  elseif ($refgmtdate == 'summer') $newrefgmtdate=$yearref.'-08-01';
91  else $newrefgmtdate=$yearref.'-01-01';
92  $newrefgmtdate.='T00:00:00+00:00';
93  $localtz = new DateTimeZone(getServerTimeZoneString());
94  $localdt = new DateTime($newrefgmtdate, $localtz);
95  $tmp=-1*$localtz->getOffset($localdt);
96  //print $refgmtdate.'='.$tmp;
97  }
98  else
99  {
100  $tmp=0;
101  dol_print_error('','PHP version must be 5.3+');
102  }
103  $tz=round(($tmp<0?1:-1)*abs($tmp/3600));
104  return $tz;
105 }
106 
107 
116 function dol_time_plus_duree($time, $duration_value, $duration_unit)
117 {
118  global $conf;
119 
120  if ($duration_value == 0) return $time;
121  if ($duration_unit == 'h') return $time + (3600*$duration_value);
122  if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value);
123 
124  $deltastring='P';
125 
126  if ($duration_value > 0){ $deltastring.=abs($duration_value); $sub= false; }
127  if ($duration_value < 0){ $deltastring.=abs($duration_value); $sub= true; }
128  if ($duration_unit == 'd') { $deltastring.="D"; }
129  if ($duration_unit == 'm') { $deltastring.="M"; }
130  if ($duration_unit == 'y') { $deltastring.="Y"; }
131 
132  $date = new DateTime();
133  if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC'));
134  $date->setTimestamp($time);
135  $interval = new DateInterval($deltastring);
136 
137  if($sub) $date->sub($interval);
138  else $date->add( $interval );
139 
140  return $date->getTimestamp();
141 }
142 
143 
153 function convertTime2Seconds($iHours=0,$iMinutes=0,$iSeconds=0)
154 {
155  $iResult=($iHours*3600)+($iMinutes*60)+$iSeconds;
156  return $iResult;
157 }
158 
159 
180 function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
181 {
182  global $langs;
183 
184  if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours
185  if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days
186 
187  if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin')
188  {
189  if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US
190 
191  $sTime='';
192  $sDay=0;
193  $sWeek=0;
194 
195  if ($iSecond >= $lengthOfDay)
196  {
197  for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay )
198  {
199  $sDay++;
200  $iSecond-=$lengthOfDay;
201  }
202  $dayTranslate = $langs->trans("Day");
203  if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days");
204  }
205 
206  if ($lengthOfWeek < 7)
207  {
208  if ($sDay)
209  {
210  if ($sDay >= $lengthOfWeek)
211  {
212  $sWeek = (int) (($sDay - $sDay % $lengthOfWeek ) / $lengthOfWeek);
213  $sDay = $sDay % $lengthOfWeek;
214  $weekTranslate = $langs->trans("DurationWeek");
215  if ($sWeek >= 2) $weekTranslate = $langs->trans("DurationWeeks");
216  $sTime.=$sWeek.' '.$weekTranslate.' ';
217  }
218  }
219  }
220  if ($sDay>0)
221  {
222  $dayTranslate = $langs->trans("Day");
223  if ($sDay > 1) $dayTranslate = $langs->trans("Days");
224  $sTime.=$sDay.' '.$dayTranslate.' ';
225  }
226 
227  if ($format == 'all')
228  {
229  if ($iSecond || empty($sDay))
230  {
231  $sTime.= dol_print_date($iSecond,'hourduration',true);
232  }
233  }
234  if ($format == 'allhourmin')
235  {
236  return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60)));
237  }
238  if ($format == 'allhour')
239  {
240  return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600)));
241  }
242  }
243  else if ($format == 'hour') // only hour part
244  {
245  $sTime=dol_print_date($iSecond,'%H',true);
246  }
247  else if ($format == 'fullhour')
248  {
249  if (!empty($iSecond)) {
250  $iSecond=$iSecond/3600;
251  }
252  else {
253  $iSecond=0;
254  }
255  $sTime=$iSecond;
256  }
257  else if ($format == 'min') // only min part
258  {
259  $sTime=dol_print_date($iSecond,'%M',true);
260  }
261  else if ($format == 'sec') // only sec part
262  {
263  $sTime=dol_print_date($iSecond,'%S',true);
264  }
265  else if ($format == 'month') // only month part
266  {
267  $sTime=dol_print_date($iSecond,'%m',true);
268  }
269  else if ($format == 'year') // only year part
270  {
271  $sTime=dol_print_date($iSecond,'%Y',true);
272  }
273  return trim($sTime);
274 }
275 
276 
295 function dol_stringtotime($string, $gm=1)
296 {
297  // Convert date with format DD/MM/YYY HH:MM:SS. This part of code should not be used.
298  if (preg_match('/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$string,$reg))
299  {
300  dol_syslog("dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
301  // Date est au format 'DD/MM/YY' ou 'DD/MM/YY HH:MM:SS'
302  // Date est au format 'DD/MM/YYYY' ou 'DD/MM/YYYY HH:MM:SS'
303  $sday = $reg[1];
304  $smonth = $reg[2];
305  $syear = $reg[3];
306  $shour = $reg[4];
307  $smin = $reg[5];
308  $ssec = $reg[6];
309  if ($syear < 50) $syear+=1900;
310  if ($syear >= 50 && $syear < 100) $syear+=2000;
311  $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
312  }
313  else if (
314  preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339)
315  || preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i',$string,$reg) // Convert date with format YYYY-MM-DD HH:MM:SS
316  || preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYYMMDDTHHMMSSZ
317  )
318  {
319  $syear = $reg[1];
320  $smonth = $reg[2];
321  $sday = $reg[3];
322  $shour = $reg[4];
323  $smin = $reg[5];
324  $ssec = $reg[6];
325  $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
326  }
327 
328  $string=preg_replace('/([^0-9])/i','',$string);
329  $tmp=$string.'000000';
330  $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),($gm?1:0));
331  return $date;
332 }
333 
334 
342 function dol_get_prev_day($day, $month, $year)
343 {
344  $time=dol_mktime(12,0,0,$month,$day,$year,1,0);
345  $time-=24*60*60;
346  $tmparray=dol_getdate($time,true);
347  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
348 }
349 
357 function dol_get_next_day($day, $month, $year)
358 {
359  $time=dol_mktime(12,0,0,$month,$day,$year,1,0);
360  $time+=24*60*60;
361  $tmparray=dol_getdate($time,true);
362  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
363 }
364 
371 function dol_get_prev_month($month, $year)
372 {
373  if ($month == 1)
374  {
375  $prev_month = 12;
376  $prev_year = $year - 1;
377  }
378  else
379  {
380  $prev_month = $month-1;
381  $prev_year = $year;
382  }
383  return array('year' => $prev_year, 'month' => $prev_month);
384 }
385 
392 function dol_get_next_month($month, $year)
393 {
394  if ($month == 12)
395  {
396  $next_month = 1;
397  $next_year = $year + 1;
398  }
399  else
400  {
401  $next_month = $month + 1;
402  $next_year = $year;
403  }
404  return array('year' => $next_year, 'month' => $next_month);
405 }
406 
415 function dol_get_prev_week($day, $week, $month, $year)
416 {
417  $tmparray = dol_get_first_day_week($day, $month, $year);
418 
419  $time=dol_mktime(12,0,0,$month,$tmparray['first_day'],$year,1,0);
420  $time-=24*60*60*7;
421  $tmparray=dol_getdate($time,true);
422  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
423 }
424 
433 function dol_get_next_week($day, $week, $month, $year)
434 {
435  $tmparray = dol_get_first_day_week($day, $month, $year);
436 
437  $time=dol_mktime(12,0,0,$tmparray['first_month'],$tmparray['first_day'],$tmparray['first_year'],1,0);
438  $time+=24*60*60*7;
439  $tmparray=dol_getdate($time,true);
440 
441  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
442 }
443 
453 function dol_get_first_day($year,$month=1,$gm=false)
454 {
455  if ($year > 9999) return '';
456  return dol_mktime(0,0,0,$month,1,$year,$gm);
457 }
458 
459 
467 function dol_get_last_day($year,$month=12,$gm=false)
468 {
469  if ($year > 9999) return '';
470  if ($month == 12)
471  {
472  $month = 1;
473  $year += 1;
474  }
475  else
476  {
477  $month += 1;
478  }
479 
480  // On se deplace au debut du mois suivant, et on retire un jour
481  $datelim=dol_mktime(23,59,59,$month,1,$year,$gm);
482  $datelim -= (3600 * 24);
483 
484  return $datelim;
485 }
486 
495 function dol_get_first_day_week($day,$month,$year,$gm=false)
496 {
497  global $conf;
498 
499  //$day=2; $month=2; $year=2015;
500  $date = dol_mktime(0,0,0,$month,$day,$year,$gm);
501 
502  //Checking conf of start week
503  $start_week = (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1);
504 
505  $tmparray = dol_getdate($date,true); // detail of current day
506 
507  //Calculate days = offset from current day
508  $days = $start_week - $tmparray['wday'];
509  if ($days>=1) $days=7-$days;
510  $days = abs($days);
511  $seconds = $days*24*60*60;
512  //print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>';
513 
514  //Get first day of week
515  $tmpdaytms = date($tmparray[0])-$seconds; // $tmparray[0] is day of parameters
516  $tmpday = date("d",$tmpdaytms);
517 
518  //Check first day of week is in same month than current day or not
519  if ($tmpday>$day)
520  {
521  $prev_month = $month-1;
522  $prev_year = $year;
523 
524  if ($prev_month==0)
525  {
526  $prev_month = 12;
527  $prev_year = $year-1;
528  }
529  }
530  else
531  {
532  $prev_month = $month;
533  $prev_year = $year;
534  }
535  $tmpmonth = $prev_month;
536  $tmpyear = $prev_year;
537 
538  //Get first day of next week
539  $tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0);
540  $tmptime-=24*60*60*7;
541  $tmparray=dol_getdate($tmptime,true);
542  $prev_day = $tmparray['mday'];
543 
544  //Check prev day of week is in same month than first day or not
545  if ($prev_day > $tmpday)
546  {
547  $prev_month = $month-1;
548  $prev_year = $year;
549 
550  if ($prev_month==0)
551  {
552  $prev_month = 12;
553  $prev_year = $year-1;
554  }
555  }
556 
557  $week = date("W",dol_mktime(0,0,0,$tmpmonth,$tmpday,$tmpyear,$gm));
558 
559  return array('year' => $year, 'month' => $month, 'week' => $week, 'first_day' => $tmpday, 'first_month' => $tmpmonth, 'first_year' => $tmpyear, 'prev_year' => $prev_year, 'prev_month' => $prev_month, 'prev_day' => $prev_day);
560 }
561 
573 function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0)
574 {
575  global $conf;
576 
577  $nbFerie = 0;
578 
579  // Check to ensure we use correct parameters
580  if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hours and must be GMT dates';
581 
582  $i=0;
583  while (( ($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd) )
584  && ($i < 50000)) // Loop end when equals (Test on i is a security loop to avoid infinite loop)
585  {
586  $ferie=false;
587  $countryfound=0;
588  $includesaturdayandsunday=1;
589 
590  $jour = date("d", $timestampStart);
591  $mois = date("m", $timestampStart);
592  $annee = date("Y", $timestampStart);
593 
594 
595  // Check into var $conf->global->HOLIDAY_MORE_DAYS MM-DD,YYYY-MM-DD, ...
596  if (! empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS))
597  {
598  $arrayofdaystring=explode(',',$conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS);
599  foreach($arrayofdaystring as $daystring)
600  {
601  $tmp=explode('-',$daystring);
602  if ($tmp[2])
603  {
604  if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie=true;
605  }
606  else
607  {
608  if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie=true;
609  }
610  }
611  }
612 
613  if ($countrycode == 'FR')
614  {
615  $countryfound=1;
616 
617  // Definition of fixed working days
618  if($jour == 1 && $mois == 1) $ferie=true; // 1er january
619  if($jour == 1 && $mois == 5) $ferie=true; // 1er may
620  if($jour == 8 && $mois == 5) $ferie=true; // 5 may
621  if($jour == 14 && $mois == 7) $ferie=true; // 14 july
622  if($jour == 15 && $mois == 8) $ferie=true; // 15 august
623  if($jour == 1 && $mois == 11) $ferie=true; // 1 november
624  if($jour == 11 && $mois == 11) $ferie=true; // 11 november
625  if($jour == 25 && $mois == 12) $ferie=true; // 25 december
626 
627  // Calculation for easter date
628  $date_paques = easter_date($annee);
629  $jour_paques = date("d", $date_paques);
630  $mois_paques = date("m", $date_paques);
631  if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
632  // Pâques
633 
634  // Calculation for the monday of easter date
635  $date_lundi_paques = mktime(
636  date("H", $date_paques),
637  date("i", $date_paques),
638  date("s", $date_paques),
639  date("m", $date_paques),
640  date("d", $date_paques) + 1,
641  date("Y", $date_paques)
642  );
643  $jour_lundi_ascension = date("d", $date_lundi_paques);
644  $mois_lundi_ascension = date("m", $date_lundi_paques);
645  if($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie=true;
646  // Lundi de Pâques
647 
648  // Calcul du jour de l'ascension (38 days after easter day)
649  $date_ascension = mktime(
650  date("H", $date_paques),
651  date("i", $date_paques),
652  date("s", $date_paques),
653  date("m", $date_paques),
654  date("d", $date_paques) + 39,
655  date("Y", $date_paques)
656  );
657  $jour_ascension = date("d", $date_ascension);
658  $mois_ascension = date("m", $date_ascension);
659  if($jour_ascension == $jour && $mois_ascension == $mois) $ferie=true;
660  // Ascension
661 
662  // Calculation of "Pentecote" (11 days after easter day)
663  $date_pentecote = mktime(
664  date("H", $date_paques),
665  date("i", $date_paques),
666  date("s", $date_paques),
667  date("m", $date_paques),
668  date("d", $date_paques) + 49,
669  date("Y", $date_paques)
670  );
671  $jour_pentecote = date("d", $date_pentecote);
672  $mois_pentecote = date("m", $date_pentecote);
673  if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true;
674  // "Pentecote"
675  }
676 
677  // Pentecoste and Ascensione in Italy go to the sunday after: isn't holiday.
678  // Pentecoste is 50 days after Easter, Ascensione 40
679  if ($countrycode == 'IT')
680  {
681  $countryfound=1;
682 
683  // Definition des dates feriees fixes
684  if($jour == 1 && $mois == 1) $ferie=true; // Capodanno
685  if($jour == 6 && $mois == 1) $ferie=true; // Epifania
686  if($jour == 25 && $mois == 4) $ferie=true; // Anniversario Liberazione
687  if($jour == 1 && $mois == 5) $ferie=true; // Festa del Lavoro
688  if($jour == 2 && $mois == 6) $ferie=true; // Festa della Repubblica
689  if($jour == 15 && $mois == 8) $ferie=true; // Ferragosto
690  if($jour == 1 && $mois == 11) $ferie=true; // Tutti i Santi
691  if($jour == 8 && $mois == 12) $ferie=true; // Immacolata Concezione
692  if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre
693  if($jour == 26 && $mois == 12) $ferie=true; // Santo Stefano
694 
695  // Calcul du jour de paques
696  $date_paques = easter_date($annee);
697  $jour_paques = date("d", $date_paques);
698  $mois_paques = date("m", $date_paques);
699  if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
700  // Paques
701  }
702 
703  if ($countrycode == 'IN')
704  {
705  $countryfound=1;
706 
707  if($jour == 1 && $mois == 1) $ferie=true; // New Year's Day
708  if($jour == 26 && $mois == 1) $ferie=true; // Republic Day
709  if($jour == 1 && $mois == 5) $ferie=true; // May Day
710  if($jour == 15 && $mois == 8) $ferie=true; // Independence Day
711  if($jour == 2 && $mois == 10) $ferie=true; // Gandhi Jayanti
712  if($jour == 25 && $mois == 12) $ferie=true; // Christmas
713  }
714 
715  if ($countrycode == 'ES')
716  {
717  $countryfound=1;
718 
719  // Definition des dates feriees fixes
720  if($jour == 1 && $mois == 1) $ferie=true; // Año nuevo
721  if($jour == 6 && $mois == 1) $ferie=true; // Día Reyes
722  if($jour == 1 && $mois == 5) $ferie=true; // 1 Mayo
723  if($jour == 15 && $mois == 8) $ferie=true; // 15 Agosto
724  if($jour == 12 && $mois == 10) $ferie=true; // Día Hispanidad
725  if($jour == 1 && $mois == 11) $ferie=true; // 1 noviembre
726  if($jour == 6 && $mois == 12) $ferie=true; // Constitución
727  if($jour == 8 && $mois == 12) $ferie=true; // Inmaculada
728  if($jour == 25 && $mois == 12) $ferie=true; // 25 diciembre
729 
730  // Calcul día de Pascua
731  $date_paques = easter_date($annee);
732  $jour_paques = date("d", $date_paques);
733  $mois_paques = date("m", $date_paques);
734  if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
735  // Paques
736 
737  // Viernes Santo
738  $date_viernes = mktime(
739  date("H", $date_paques),
740  date("i", $date_paques),
741  date("s", $date_paques),
742  date("m", $date_paques),
743  date("d", $date_paques) -2,
744  date("Y", $date_paques)
745  );
746  $jour_viernes = date("d", $date_viernes);
747  $mois_viernes = date("m", $date_viernes);
748  if($jour_viernes == $jour && $mois_viernes == $mois) $ferie=true;
749  //Viernes Santo
750  }
751 
752  if ($countrycode == 'AT')
753  {
754  $countryfound=1;
755 
756  // Definition des dates feriees fixes
757  if($jour == 1 && $mois == 1) $ferie=true; // Neujahr
758  if($jour == 6 && $mois == 1) $ferie=true; // Hl. 3 Koenige
759  if($jour == 1 && $mois == 5) $ferie=true; // 1. Mai
760  if($jour == 15 && $mois == 8) $ferie=true; // Mariae Himmelfahrt
761  if($jour == 26 && $mois == 10) $ferie=true; // 26. Oktober
762  if($jour == 1 && $mois == 11) $ferie=true; // Allerheiligen
763  if($jour == 8 && $mois == 12) $ferie=true; // Mariae Empfaengnis
764  if($jour == 24 && $mois == 12) $ferie=true; // Heilig abend
765  if($jour == 25 && $mois == 12) $ferie=true; // Christtag
766  if($jour == 26 && $mois == 12) $ferie=true; // Stefanietag
767  if($jour == 31 && $mois == 12) $ferie=true; // Silvester
768 
769  // Easter calculation
770  $date_paques = easter_date($annee);
771  $jour_paques = date("d", $date_paques);
772  $mois_paques = date("m", $date_paques);
773  if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
774  // Easter sunday
775 
776  // Monday after easter
777  $date_eastermonday = mktime(
778  date("H", $date_paques),
779  date("i", $date_paques),
780  date("s", $date_paques),
781  date("m", $date_paques),
782  date("d", $date_paques) + 1,
783  date("Y", $date_paques)
784  );
785  $jour_eastermonday = date("d", $date_eastermonday);
786  $mois_eastermonday = date("m", $date_eastermonday);
787  if($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie=true;
788  // Easter monday
789 
790  // Christi Himmelfahrt (39 days after easter sunday)
791  $date_ch = mktime(
792  date("H", $date_paques),
793  date("i", $date_paques),
794  date("s", $date_paques),
795  date("m", $date_paques),
796  date("d", $date_paques) + 39,
797  date("Y", $date_paques)
798  );
799  $jour_ch = date("d", $date_ch);
800  $mois_ch = date("m", $date_ch);
801  if($jour_ch == $jour && $mois_ch == $mois) $ferie=true;
802  // Christi Himmelfahrt
803 
804  // Pfingsten (50 days after easter sunday)
805  $date_pentecote = mktime(
806  date("H", $date_paques),
807  date("i", $date_paques),
808  date("s", $date_paques),
809  date("m", $date_paques),
810  date("d", $date_paques) + 50,
811  date("Y", $date_paques)
812  );
813  $jour_pentecote = date("d", $date_pentecote);
814  $mois_pentecote = date("m", $date_pentecote);
815  if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true;
816  // Pfingsten
817 
818  // Fronleichnam (60 days after easter sunday)
819  $date_fronleichnam = mktime(
820  date("H", $date_paques),
821  date("i", $date_paques),
822  date("s", $date_paques),
823  date("m", $date_paques),
824  date("d", $date_paques) + 60,
825  date("Y", $date_paques)
826  );
827  $jour_fronleichnam = date("d", $date_fronleichnam);
828  $mois_fronleichnam = date("m", $date_fronleichnam);
829  if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie=true;
830  // Fronleichnam
831  }
832 
833  // If we have to include saturday and sunday
834  if ($includesaturdayandsunday)
835  {
836  $jour_julien = unixtojd($timestampStart);
837  $jour_semaine = jddayofweek($jour_julien, 0);
838  if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true;
839  //Saturday (6) and Sunday (0)
840  }
841 
842  // On incremente compteur
843  if ($ferie) $nbFerie++;
844 
845  // Increase number of days (on go up into loop)
846  $timestampStart=dol_time_plus_duree($timestampStart, 1, 'd');
847  //var_dump($jour.' '.$mois.' '.$annee.' '.$timestampStart);
848 
849  $i++;
850  }
851 
852  return $nbFerie;
853 }
854 
865 function num_between_day($timestampStart, $timestampEnd, $lastday=0)
866 {
867  if ($timestampStart < $timestampEnd)
868  {
869  if ($lastday == 1)
870  {
871  $bit = 0;
872  }
873  else
874  {
875  $bit = 1;
876  }
877  $nbjours = (int) floor(($timestampEnd - $timestampStart)/(60*60*24)) + 1 - $bit;
878  }
879  //print ($timestampEnd - $timestampStart) - $lastday;
880  return $nbjours;
881 }
882 
895 function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='')
896 {
897  global $langs,$mysoc;
898 
899  if (empty($country_code)) $country_code=$mysoc->country_code;
900 
901  dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday.' country_code='.$country_code);
902 
903  // Check parameters
904  if (! is_int($timestampStart) && ! is_float($timestampStart)) return 'ErrorBadParameter_num_open_day';
905  if (! is_int($timestampEnd) && ! is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day';
906 
907  //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday;
908  if ($timestampStart < $timestampEnd)
909  {
910  $numdays = num_between_day($timestampStart, $timestampEnd, $lastday);
911  $numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
912  $nbOpenDay = $numdays - $numholidays;
913  $nbOpenDay.= " " . $langs->trans("Days");
914  if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort");
915  return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
916  }
917  elseif ($timestampStart == $timestampEnd)
918  {
919  $nbOpenDay=$lastday;
920  if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort");
921  return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
922  }
923  else
924  {
925  return $langs->trans("Error");
926  }
927 }
928 
929 
930 
939 function monthArray($outputlangs,$short=0)
940 {
941  $montharray = array (
942  1 => $outputlangs->trans("Month01"),
943  2 => $outputlangs->trans("Month02"),
944  3 => $outputlangs->trans("Month03"),
945  4 => $outputlangs->trans("Month04"),
946  5 => $outputlangs->trans("Month05"),
947  6 => $outputlangs->trans("Month06"),
948  7 => $outputlangs->trans("Month07"),
949  8 => $outputlangs->trans("Month08"),
950  9 => $outputlangs->trans("Month09"),
951  10 => $outputlangs->trans("Month10"),
952  11 => $outputlangs->trans("Month11"),
953  12 => $outputlangs->trans("Month12")
954  );
955 
956  if (! empty($short))
957  {
958  $montharray = array (
959  1 => $outputlangs->trans("MonthShort01"),
960  2 => $outputlangs->trans("MonthShort02"),
961  3 => $outputlangs->trans("MonthShort03"),
962  4 => $outputlangs->trans("MonthShort04"),
963  5 => $outputlangs->trans("MonthShort05"),
964  6 => $outputlangs->trans("MonthShort06"),
965  7 => $outputlangs->trans("MonthShort07"),
966  8 => $outputlangs->trans("MonthShort08"),
967  9 => $outputlangs->trans("MonthShort09"),
968  10 => $outputlangs->trans("MonthShort10"),
969  11 => $outputlangs->trans("MonthShort11"),
970  12 => $outputlangs->trans("MonthShort12")
971  );
972  }
973 
974  return $montharray;
975 }
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition: date.lib.php:180
dol_get_prev_month($month, $year)
Return previous month.
Definition: date.lib.php:371
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='')
Function to return number of working days (and text of units) between two dates (working days) ...
Definition: date.lib.php:895
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition: date.lib.php:495
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition: date.lib.php:295
getServerTimeZoneString()
Return server timezone string.
Definition: date.lib.php:71
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_get_prev_day($day, $month, $year)
Return previous day.
Definition: date.lib.php:342
convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
Convert hours and minutes into seconds.
Definition: date.lib.php:153
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition: date.lib.php:433
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
num_between_day($timestampStart, $timestampEnd, $lastday=0)
Function to return number of days between two dates (date must be UTC date !) Example: 2012-01-01 201...
Definition: date.lib.php:865
num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0)
Fonction retournant le nombre de jour feries, samedis et dimanches entre 2 dates entrees en timestamp...
Definition: date.lib.php:573
dol_get_next_month($month, $year)
Return next month.
Definition: date.lib.php:392
dol_get_next_day($day, $month, $year)
Return next day.
Definition: date.lib.php:357
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
Definition: date.lib.php:82
dol_now($mode='gmt')
Return date for now.
monthArray($outputlangs, $short=0)
Return array of translated months or selected month.
Definition: date.lib.php:939
dol_get_prev_week($day, $week, $month, $year)
Return previous week.
Definition: date.lib.php:415
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
get_tz_array()
Return an array with timezone values.
Definition: date.lib.php:33
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116