dolibarr  7.0.0-beta
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@capnetworks.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 
171 function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
172 {
173  global $langs;
174 
175  if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours
176  if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days
177 
178  if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin')
179  {
180  if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US
181 
182  $sTime='';
183  $sDay=0;
184  $sWeek=0;
185 
186  if ($iSecond >= $lengthOfDay)
187  {
188  for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay )
189  {
190  $sDay++;
191  $iSecond-=$lengthOfDay;
192  }
193  $dayTranslate = $langs->trans("Day");
194  if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days");
195  }
196 
197  if ($lengthOfWeek < 7)
198  {
199  if ($sDay)
200  {
201  if ($sDay >= $lengthOfWeek)
202  {
203  $sWeek = (int) (($sDay - $sDay % $lengthOfWeek ) / $lengthOfWeek);
204  $sDay = $sDay % $lengthOfWeek;
205  $weekTranslate = $langs->trans("DurationWeek");
206  if ($sWeek >= 2) $weekTranslate = $langs->trans("DurationWeeks");
207  $sTime.=$sWeek.' '.$weekTranslate.' ';
208  }
209  }
210  }
211  if ($sDay>0)
212  {
213  $dayTranslate = $langs->trans("Day");
214  if ($sDay > 1) $dayTranslate = $langs->trans("Days");
215  $sTime.=$sDay.' '.$dayTranslate.' ';
216  }
217 
218  if ($format == 'all')
219  {
220  if ($iSecond || empty($sDay))
221  {
222  $sTime.= dol_print_date($iSecond,'hourduration',true);
223  }
224  }
225  if ($format == 'allhourmin')
226  {
227  return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60)));
228  }
229  if ($format == 'allhour')
230  {
231  return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600)));
232  }
233  }
234  else if ($format == 'hour') // only hour part
235  {
236  $sTime=dol_print_date($iSecond,'%H',true);
237  }
238  else if ($format == 'fullhour')
239  {
240  if (!empty($iSecond)) {
241  $iSecond=$iSecond/3600;
242  }
243  else {
244  $iSecond=0;
245  }
246  $sTime=$iSecond;
247  }
248  else if ($format == 'min') // only min part
249  {
250  $sTime=dol_print_date($iSecond,'%M',true);
251  }
252  else if ($format == 'sec') // only sec part
253  {
254  $sTime=dol_print_date($iSecond,'%S',true);
255  }
256  else if ($format == 'month') // only month part
257  {
258  $sTime=dol_print_date($iSecond,'%m',true);
259  }
260  else if ($format == 'year') // only year part
261  {
262  $sTime=dol_print_date($iSecond,'%Y',true);
263  }
264  return trim($sTime);
265 }
266 
267 
286 function dol_stringtotime($string, $gm=1)
287 {
288  // Convert date with format DD/MM/YYY HH:MM:SS. This part of code should not be used.
289  if (preg_match('/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$string,$reg))
290  {
291  dol_syslog("dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
292  // Date est au format 'DD/MM/YY' ou 'DD/MM/YY HH:MM:SS'
293  // Date est au format 'DD/MM/YYYY' ou 'DD/MM/YYYY HH:MM:SS'
294  $sday = $reg[1];
295  $smonth = $reg[2];
296  $syear = $reg[3];
297  $shour = $reg[4];
298  $smin = $reg[5];
299  $ssec = $reg[6];
300  if ($syear < 50) $syear+=1900;
301  if ($syear >= 50 && $syear < 100) $syear+=2000;
302  $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
303  }
304  else if (
305  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)
306  || 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
307  || 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
308  )
309  {
310  $syear = $reg[1];
311  $smonth = $reg[2];
312  $sday = $reg[3];
313  $shour = $reg[4];
314  $smin = $reg[5];
315  $ssec = $reg[6];
316  $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
317  }
318 
319  $string=preg_replace('/([^0-9])/i','',$string);
320  $tmp=$string.'000000';
321  $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));
322  return $date;
323 }
324 
325 
333 function dol_get_prev_day($day, $month, $year)
334 {
335  $time=dol_mktime(12,0,0,$month,$day,$year,1,0);
336  $time-=24*60*60;
337  $tmparray=dol_getdate($time,true);
338  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
339 }
340 
348 function dol_get_next_day($day, $month, $year)
349 {
350  $time=dol_mktime(12,0,0,$month,$day,$year,1,0);
351  $time+=24*60*60;
352  $tmparray=dol_getdate($time,true);
353  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
354 }
355 
362 function dol_get_prev_month($month, $year)
363 {
364  if ($month == 1)
365  {
366  $prev_month = 12;
367  $prev_year = $year - 1;
368  }
369  else
370  {
371  $prev_month = $month-1;
372  $prev_year = $year;
373  }
374  return array('year' => $prev_year, 'month' => $prev_month);
375 }
376 
383 function dol_get_next_month($month, $year)
384 {
385  if ($month == 12)
386  {
387  $next_month = 1;
388  $next_year = $year + 1;
389  }
390  else
391  {
392  $next_month = $month + 1;
393  $next_year = $year;
394  }
395  return array('year' => $next_year, 'month' => $next_month);
396 }
397 
406 function dol_get_prev_week($day, $week, $month, $year)
407 {
408  $tmparray = dol_get_first_day_week($day, $month, $year);
409 
410  $time=dol_mktime(12,0,0,$month,$tmparray['first_day'],$year,1,0);
411  $time-=24*60*60*7;
412  $tmparray=dol_getdate($time,true);
413  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
414 }
415 
424 function dol_get_next_week($day, $week, $month, $year)
425 {
426  $tmparray = dol_get_first_day_week($day, $month, $year);
427 
428  $time=dol_mktime(12,0,0,$tmparray['first_month'],$tmparray['first_day'],$tmparray['first_year'],1,0);
429  $time+=24*60*60*7;
430  $tmparray=dol_getdate($time,true);
431 
432  return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
433 
434 }
435 
445 function dol_get_first_day($year,$month=1,$gm=false)
446 {
447  if ($year > 9999) return '';
448  return dol_mktime(0,0,0,$month,1,$year,$gm);
449 }
450 
451 
459 function dol_get_last_day($year,$month=12,$gm=false)
460 {
461  if ($year > 9999) return '';
462  if ($month == 12)
463  {
464  $month = 1;
465  $year += 1;
466  }
467  else
468  {
469  $month += 1;
470  }
471 
472  // On se deplace au debut du mois suivant, et on retire un jour
473  $datelim=dol_mktime(23,59,59,$month,1,$year,$gm);
474  $datelim -= (3600 * 24);
475 
476  return $datelim;
477 }
478 
487 function dol_get_first_day_week($day,$month,$year,$gm=false)
488 {
489  global $conf;
490 
491  //$day=2; $month=2; $year=2015;
492  $date = dol_mktime(0,0,0,$month,$day,$year,$gm);
493 
494  //Checking conf of start week
495  $start_week = (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1);
496 
497  $tmparray = dol_getdate($date,true); // detail of current day
498 
499  //Calculate days = offset from current day
500  $days = $start_week - $tmparray['wday'];
501  if ($days>=1) $days=7-$days;
502  $days = abs($days);
503  $seconds = $days*24*60*60;
504  //print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>';
505 
506  //Get first day of week
507  $tmpdaytms = date($tmparray[0])-$seconds; // $tmparray[0] is day of parameters
508  $tmpday = date("d",$tmpdaytms);
509 
510  //Check first day of week is in same month than current day or not
511  if ($tmpday>$day)
512  {
513  $prev_month = $month-1;
514  $prev_year = $year;
515 
516  if ($prev_month==0)
517  {
518  $prev_month = 12;
519  $prev_year = $year-1;
520  }
521  }
522  else
523  {
524  $prev_month = $month;
525  $prev_year = $year;
526  }
527  $tmpmonth = $prev_month;
528  $tmpyear = $prev_year;
529 
530  //Get first day of next week
531  $tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0);
532  $tmptime-=24*60*60*7;
533  $tmparray=dol_getdate($tmptime,true);
534  $prev_day = $tmparray['mday'];
535 
536  //Check prev day of week is in same month than first day or not
537  if ($prev_day > $tmpday)
538  {
539  $prev_month = $month-1;
540  $prev_year = $year;
541 
542  if ($prev_month==0)
543  {
544  $prev_month = 12;
545  $prev_year = $year-1;
546  }
547  }
548 
549  $week = date("W",dol_mktime(0,0,0,$tmpmonth,$tmpday,$tmpyear,$gm));
550 
551  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);
552 }
553 
565 function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0)
566 {
567  $nbFerie = 0;
568 
569  // Check to ensure we use correct parameters
570  if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hours and must be GMT dates';
571 
572  $i=0;
573  while (( ($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd) )
574  && ($i < 50000)) // Loop end when equals (Test on i is a security loop to avoid infinite loop)
575  {
576  $ferie=false;
577  $countryfound=0;
578 
579  $jour = date("d", $timestampStart);
580  $mois = date("m", $timestampStart);
581  $annee = date("Y", $timestampStart);
582  if ($countrycode == 'FR')
583  {
584  $countryfound=1;
585 
586  // Definition des dates feriees fixes
587  if($jour == 1 && $mois == 1) $ferie=true; // 1er janvier
588  if($jour == 1 && $mois == 5) $ferie=true; // 1er mai
589  if($jour == 8 && $mois == 5) $ferie=true; // 5 mai
590  if($jour == 14 && $mois == 7) $ferie=true; // 14 juillet
591  if($jour == 15 && $mois == 8) $ferie=true; // 15 aout
592  if($jour == 1 && $mois == 11) $ferie=true; // 1 novembre
593  if($jour == 11 && $mois == 11) $ferie=true; // 11 novembre
594  if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre
595 
596  // Calcul du jour de paques
597  $date_paques = easter_date($annee);
598  $jour_paques = date("d", $date_paques);
599  $mois_paques = date("m", $date_paques);
600  if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
601  // Paques
602 
603  // Calcul du jour de l ascension (38 jours apres Paques)
604  $date_ascension = mktime(
605  date("H", $date_paques),
606  date("i", $date_paques),
607  date("s", $date_paques),
608  date("m", $date_paques),
609  date("d", $date_paques) + 38,
610  date("Y", $date_paques)
611  );
612  $jour_ascension = date("d", $date_ascension);
613  $mois_ascension = date("m", $date_ascension);
614  if($jour_ascension == $jour && $mois_ascension == $mois) $ferie=true;
615  //Ascension
616 
617  // Calcul de Pentecote (11 jours apres Paques)
618  $date_pentecote = mktime(
619  date("H", $date_ascension),
620  date("i", $date_ascension),
621  date("s", $date_ascension),
622  date("m", $date_ascension),
623  date("d", $date_ascension) + 11,
624  date("Y", $date_ascension)
625  );
626  $jour_pentecote = date("d", $date_pentecote);
627  $mois_pentecote = date("m", $date_pentecote);
628  if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true;
629  //Pentecote
630 
631  // Calul des samedis et dimanches
632  $jour_julien = unixtojd($timestampStart);
633  $jour_semaine = jddayofweek($jour_julien, 0);
634  if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true;
635  //Samedi (6) et dimanche (0)
636  }
637 
638  // Pentecoste and Ascensione in Italy go to the sunday after: isn't holiday.
639  // Pentecoste is 50 days after Easter, Ascensione 40
640  if ($countrycode == 'IT')
641  {
642  $countryfound=1;
643 
644  // Definition des dates feriees fixes
645  if($jour == 1 && $mois == 1) $ferie=true; // Capodanno
646  if($jour == 6 && $mois == 1) $ferie=true; // Epifania
647  if($jour == 25 && $mois == 4) $ferie=true; // Anniversario Liberazione
648  if($jour == 1 && $mois == 5) $ferie=true; // Festa del Lavoro
649  if($jour == 2 && $mois == 6) $ferie=true; // Festa della Repubblica
650  if($jour == 15 && $mois == 8) $ferie=true; // Ferragosto
651  if($jour == 1 && $mois == 11) $ferie=true; // Tutti i Santi
652  if($jour == 8 && $mois == 12) $ferie=true; // Immacolata Concezione
653  if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre
654  if($jour == 26 && $mois == 12) $ferie=true; // Santo Stefano
655 
656  // Calcul du jour de paques
657  $date_paques = easter_date($annee);
658  $jour_paques = date("d", $date_paques);
659  $mois_paques = date("m", $date_paques);
660  if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
661  // Paques
662 
663  // Calul des samedis et dimanches
664  $jour_julien = unixtojd($timestampStart);
665  $jour_semaine = jddayofweek($jour_julien, 0);
666  if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true;
667  //Samedi (6) et dimanche (0)
668  }
669 
670  if ($countrycode == 'ES')
671  {
672  $countryfound=1;
673 
674  // Definition des dates feriees fixes
675  if($jour == 1 && $mois == 1) $ferie=true; // Año nuevo
676  if($jour == 6 && $mois == 1) $ferie=true; // Día Reyes
677  if($jour == 1 && $mois == 5) $ferie=true; // 1 Mayo
678  if($jour == 15 && $mois == 8) $ferie=true; // 15 Agosto
679  if($jour == 12 && $mois == 10) $ferie=true; // Día Hispanidad
680  if($jour == 1 && $mois == 11) $ferie=true; // 1 noviembre
681  if($jour == 6 && $mois == 12) $ferie=true; // Constitución
682  if($jour == 8 && $mois == 12) $ferie=true; // Inmaculada
683  if($jour == 25 && $mois == 12) $ferie=true; // 25 diciembre
684 
685  // Calcul día de Pascua
686  $date_paques = easter_date($annee);
687  $jour_paques = date("d", $date_paques);
688  $mois_paques = date("m", $date_paques);
689  if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
690  // Paques
691 
692  // Viernes Santo
693  $date_viernes = mktime(
694  date("H", $date_paques),
695  date("i", $date_paques),
696  date("s", $date_paques),
697  date("m", $date_paques),
698  date("d", $date_paques) -2,
699  date("Y", $date_paques)
700  );
701  $jour_viernes = date("d", $date_viernes);
702  $mois_viernes = date("m", $date_viernes);
703  if($jour_viernes == $jour && $mois_viernes == $mois) $ferie=true;
704  //Viernes Santo
705 
706  // Calul des samedis et dimanches
707  $jour_julien = unixtojd($timestampStart);
708  $jour_semaine = jddayofweek($jour_julien, 0);
709  if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true;
710  //Samedi (6) et dimanche (0)
711  }
712 
713  if ($countrycode == 'AT')
714  {
715  $countryfound=1;
716 
717  // Definition des dates feriees fixes
718  if($jour == 1 && $mois == 1) $ferie=true; // Neujahr
719  if($jour == 6 && $mois == 1) $ferie=true; // Hl. 3 Koenige
720  if($jour == 1 && $mois == 5) $ferie=true; // 1. Mai
721  if($jour == 15 && $mois == 8) $ferie=true; // Mariae Himmelfahrt
722  if($jour == 26 && $mois == 10) $ferie=true; // 26. Oktober
723  if($jour == 1 && $mois == 11) $ferie=true; // Allerheiligen
724  if($jour == 8 && $mois == 12) $ferie=true; // Mariae Empfaengnis
725  if($jour == 24 && $mois == 12) $ferie=true; // Heilig abend
726  if($jour == 25 && $mois == 12) $ferie=true; // Christtag
727  if($jour == 26 && $mois == 12) $ferie=true; // Stefanietag
728  if($jour == 31 && $mois == 12) $ferie=true; // Silvester
729 
730  // Easter calculation
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  // Easter sunday
736 
737  // Monday after easter
738  $date_eastermonday = 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) + 1,
744  date("Y", $date_paques)
745  );
746  $jour_eastermonday = date("d", $date_eastermonday);
747  $mois_eastermonday = date("m", $date_eastermonday);
748  if($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie=true;
749  // Easter monday
750 
751  // Christi Himmelfahrt (39 days after easter sunday)
752  $date_ch = mktime(
753  date("H", $date_paques),
754  date("i", $date_paques),
755  date("s", $date_paques),
756  date("m", $date_paques),
757  date("d", $date_paques) + 39,
758  date("Y", $date_paques)
759  );
760  $jour_ch = date("d", $date_ch);
761  $mois_ch = date("m", $date_ch);
762  if($jour_ch == $jour && $mois_ch == $mois) $ferie=true;
763  // Christi Himmelfahrt
764 
765  // Pfingsten (50 days after easter sunday)
766  $date_pentecote = mktime(
767  date("H", $date_paques),
768  date("i", $date_paques),
769  date("s", $date_paques),
770  date("m", $date_paques),
771  date("d", $date_paques) + 50,
772  date("Y", $date_paques)
773  );
774  $jour_pentecote = date("d", $date_pentecote);
775  $mois_pentecote = date("m", $date_pentecote);
776  if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true;
777  // Pfingsten
778 
779  // Fronleichnam (60 days after easter sunday)
780  $date_fronleichnam = mktime(
781  date("H", $date_paques),
782  date("i", $date_paques),
783  date("s", $date_paques),
784  date("m", $date_paques),
785  date("d", $date_paques) + 60,
786  date("Y", $date_paques)
787  );
788  $jour_fronleichnam = date("d", $date_fronleichnam);
789  $mois_fronleichnam = date("m", $date_fronleichnam);
790  if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie=true;
791  // Fronleichnam
792 
793  // Calul des samedis et dimanches
794  $jour_julien = unixtojd($timestampStart);
795  $jour_semaine = jddayofweek($jour_julien, 0);
796  if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true;
797  //Samedi (6) et dimanche (0)
798  }
799 
800  // Cas pays non defini
801  if (! $countryfound)
802  {
803  // Calul des samedis et dimanches
804  $jour_julien = unixtojd($timestampStart);
805  $jour_semaine = jddayofweek($jour_julien, 0);
806  if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true;
807  //Samedi (6) et dimanche (0)
808  }
809 
810  // On incremente compteur
811  if ($ferie) $nbFerie++;
812 
813  // Increase number of days (on go up into loop)
814  $timestampStart=dol_time_plus_duree($timestampStart, 1, 'd');
815  //var_dump($jour.' '.$mois.' '.$annee.' '.$timestampStart);
816 
817  $i++;
818  }
819 
820  return $nbFerie;
821 }
822 
833 function num_between_day($timestampStart, $timestampEnd, $lastday=0)
834 {
835  if ($timestampStart < $timestampEnd)
836  {
837  if ($lastday == 1)
838  {
839  $bit = 0;
840  }
841  else
842  {
843  $bit = 1;
844  }
845  $nbjours = (int) floor(($timestampEnd - $timestampStart)/(60*60*24)) + 1 - $bit;
846  }
847  //print ($timestampEnd - $timestampStart) - $lastday;
848  return $nbjours;
849 }
850 
863 function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='')
864 {
865  global $langs,$mysoc;
866 
867  if (empty($country_code)) $country_code=$mysoc->country_code;
868 
869  dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday.' country_code='.$country_code);
870 
871  // Check parameters
872  if (! is_int($timestampStart) && ! is_float($timestampStart)) return 'ErrorBadParameter_num_open_day';
873  if (! is_int($timestampEnd) && ! is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day';
874 
875  //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday;
876  if ($timestampStart < $timestampEnd)
877  {
878  $numdays = num_between_day($timestampStart, $timestampEnd, $lastday);
879  $numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
880  $nbOpenDay = $numdays - $numholidays;
881  $nbOpenDay.= " " . $langs->trans("Days");
882  if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort");
883  return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
884  }
885  elseif ($timestampStart == $timestampEnd)
886  {
887  $nbOpenDay=$lastday;
888  if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort");
889  return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
890  }
891  else
892  {
893  return $langs->trans("Error");
894  }
895 }
896 
897 
898 
907 function monthArray($outputlangs,$short=0)
908 {
909  $montharray = array (
910  1 => $outputlangs->trans("January"),
911  2 => $outputlangs->trans("February"),
912  3 => $outputlangs->trans("March"),
913  4 => $outputlangs->trans("April"),
914  5 => $outputlangs->trans("May"),
915  6 => $outputlangs->trans("June"),
916  7 => $outputlangs->trans("July"),
917  8 => $outputlangs->trans("August"),
918  9 => $outputlangs->trans("September"),
919  10 => $outputlangs->trans("October"),
920  11 => $outputlangs->trans("November"),
921  12 => $outputlangs->trans("December")
922  );
923 
924  if (! empty($short))
925  {
926  $montharray = array (
927  1 => $outputlangs->trans("JanuaryMin"),
928  2 => $outputlangs->trans("FebruaryMin"),
929  3 => $outputlangs->trans("MarchMin"),
930  4 => $outputlangs->trans("AprilMin"),
931  5 => $outputlangs->trans("MayMin"),
932  6 => $outputlangs->trans("JuneMin"),
933  7 => $outputlangs->trans("JulyMin"),
934  8 => $outputlangs->trans("AugustMin"),
935  9 => $outputlangs->trans("SeptemberMin"),
936  10 => $outputlangs->trans("OctoberMin"),
937  11 => $outputlangs->trans("NovemberMin"),
938  12 => $outputlangs->trans("DecemberMin")
939  );
940  }
941 
942  return $montharray;
943 }
944 
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:171
dol_get_prev_month($month, $year)
Return previous month.
Definition: date.lib.php:362
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:863
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition: date.lib.php:487
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
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:286
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:333
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:424
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:833
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:565
dol_get_next_month($month, $year)
Return next month.
Definition: date.lib.php:383
dol_get_next_day($day, $month, $year)
Return next day.
Definition: date.lib.php:348
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:907
dol_get_prev_week($day, $week, $month, $year)
Return previous week.
Definition: date.lib.php:406
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:459
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