40 -11 =>
"Pacific/Pago_Pago",
41 -10 =>
"Pacific/Honolulu",
42 -9 =>
"America/Anchorage",
43 -8 =>
"America/Los_Angeles",
44 -7 =>
"America/Dawson_Creek",
45 -6 =>
"America/Chicago",
46 -5 =>
"America/Bogota",
47 -4 =>
"America/Asuncion",
48 -3 =>
"America/Araguaina",
49 -2 =>
"America/Noronha",
50 -1 =>
"Atlantic/Azores",
53 2 =>
"Europe/Helsinki",
59 8 =>
"Asia/Hong_Kong",
61 10 =>
"Australia/Sydney",
62 11 =>
"Pacific/Noumea",
63 12 =>
"Pacific/Auckland",
64 13 =>
"Pacific/Fakaofo",
65 14 =>
"Pacific/Kiritimati"
78 return @date_default_timezone_get();
89 if (method_exists(
'DateTimeZone',
'getOffset')) {
95 if ($refgmtdate ==
'now') {
96 $newrefgmtdate = $yearref.
'-'.$monthref.
'-'.$dayref;
97 } elseif ($refgmtdate ==
'summer') {
98 $newrefgmtdate = $yearref.
'-08-01';
100 $newrefgmtdate = $yearref.
'-01-01';
102 $newrefgmtdate .=
'T00:00:00+00:00';
104 $localdt =
new DateTime($newrefgmtdate, $localtz);
105 $tmp = -1 * $localtz->getOffset($localdt);
111 $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
131 if (empty($duration_value)) {
134 if ($duration_unit ==
's') {
135 return $time + (int) ($duration_value);
137 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
138 return $time + (int) (60 * $duration_value);
140 if ($duration_unit ==
'h') {
141 return $time + (int) (3600 * $duration_value);
143 if ($duration_unit ==
'w') {
144 return $time + (int) (3600 * 24 * 7 * $duration_value);
151 if ($duration_value > 0) {
152 $deltastring .= abs($duration_value);
155 if ($duration_value < 0) {
156 $deltastring .= abs($duration_value);
159 if ($duration_unit ==
'd') {
162 if ($duration_unit ==
'm') {
165 if ($duration_unit ==
'y') {
169 $date =
new DateTime();
171 $date->setTimezone(
new DateTimeZone(
'UTC'));
172 } elseif ($tz !==
'') {
173 $date->setTimezone(
new DateTimeZone($tz ==
'tzserver' ? date_default_timezone_get() : $tz));
174 } elseif (!function_exists(
'getDolGlobalString') || !
getDolGlobalString(
'MAIN_DATE_IN_MEMORY_ARE_NOT_GMT')) {
175 $date->setTimezone(
new DateTimeZone(
'UTC'));
179 $date->setTimestamp((
int) $time);
180 $interval =
new DateInterval($deltastring);
183 $date->sub($interval);
185 $date->add($interval);
189 if ($ruleforendofmonth == 1 && $duration_unit ==
'm' && $tz !==
'') {
191 $origin =
new DateTime(
'@'.((
int) $time));
192 $origin->setTimezone($date->getTimezone());
193 $monthsexpected = ((int) $origin->format(
'Y') * 12) + (
int) $origin->format(
'n') + (int) $duration_value;
194 if (((
int) $date->format(
'Y') * 12) + (
int) $date->format(
'n') != $monthsexpected) {
195 $date->modify(
'last day of previous month');
197 } elseif ($ruleforendofmonth == 1 && $duration_unit ==
'm') {
200 $timetotalmonths = (($timeyear * 12) + $timemonth);
202 $monthsexpected = ($timetotalmonths + $duration_value);
204 $newtime = $date->getTimestamp();
208 $newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
210 if ($monthsexpected < $newtimetotalmonths || $monthsexpected > $newtimetotalmonths) {
215 $datelim =
dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
216 $datelim -= (3600 * 24);
218 $date->setTimestamp($datelim);
221 return $date->getTimestamp();
236 $iResult = ((int) $iHours * 3600) + ((int) $iMinutes * 60) + (int) $iSeconds;
267 if (empty($lengthOfDay)) {
268 $lengthOfDay = 86400;
270 if (empty($lengthOfWeek)) {
273 $nbHbyDay = $lengthOfDay / 3600;
277 if ($format ==
'all' || $format ==
'allwithouthour' || $format ==
'allhour' || $format ==
'allhourmin' || $format ==
'allhourminsec') {
278 if ((
int) $iSecond === 0) {
285 if ($iSecond >= $lengthOfDay) {
286 for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) {
288 $iSecond -= $lengthOfDay;
290 $dayTranslate = $langs->trans(
"Day");
291 if ($iSecond >= ($lengthOfDay * 2)) {
292 $dayTranslate = $langs->trans(
"Days");
296 if ($lengthOfWeek < 7) {
298 if ($sDay >= $lengthOfWeek) {
299 $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
300 $sDay %= $lengthOfWeek;
301 $weekTranslate = $langs->trans(
"DurationWeek");
303 $weekTranslate = $langs->trans(
"DurationWeeks");
305 $sTime .= $sWeek.
' '.$weekTranslate.
' ';
310 $dayTranslate = $langs->trans(
"Day");
312 $dayTranslate = $langs->trans(
"Days");
314 $sTime .= $sDay.
' '.$langs->trans(
"d").
' ';
317 if ($format ==
'all') {
318 if ($iSecond || empty($sDay)) {
321 } elseif ($format ==
'allhourminsec') {
322 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60))).
':'.sprintf(
"%02d", ((
int) ($iSecond % 60)));
323 } elseif ($format ==
'allhourmin') {
324 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60)));
325 } elseif ($format ==
'allhour') {
326 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600)));
328 } elseif ($format ==
'hour') {
330 } elseif ($format ==
'fullhour') {
331 if (!empty($iSecond)) {
337 } elseif ($format ==
'min') {
339 } elseif ($format ==
'sec') {
341 } elseif ($format ==
'month') {
343 } elseif ($format ==
'year') {
346 return trim((
string) $sTime);
361 if ($duration_unit ==
's') {
362 $result = $duration_value / 3600;
364 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
365 $result = $duration_value / 60;
367 if ($duration_unit ==
'h') {
368 $result = $duration_value;
370 if ($duration_unit ==
'd') {
371 $result = $duration_value * 24;
373 if ($duration_unit ==
'w') {
374 $result = $duration_value * 24 * 7;
376 if ($duration_unit ==
'm') {
377 $result = $duration_value * 730.484;
379 if ($duration_unit ==
'y') {
380 $result = $duration_value * 365 * 24;
401function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand = 0, $gm =
false)
406 $day_date = intval($day_date);
407 $month_date = intval($month_date);
408 $year_date = intval($year_date);
409 $sql_datefield =
$db->sanitize($datefield);
411 if ($month_date > 0) {
412 if ($month_date > 12) {
415 if ($year_date > 0 && empty($day_date)) {
416 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".
$db->idate(
dol_get_first_day($year_date, $month_date, $gm)).
"'";
417 $sqldate .=
" AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
418 } elseif ($year_date > 0 && !empty($day_date)) {
419 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".
$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm)).
"'";
420 $sqldate .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
423 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$sql_datefield.
", '%c') = '".
$db->escape((
string) $month_date).
"'";
425 } elseif ($year_date > 0) {
426 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".
$db->idate(
dol_get_first_day($year_date, 1, $gm)).
"'";
455 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
456 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
459 $sday = (int) $reg[1];
460 $smonth = (int) $reg[2];
461 $syear = (int) $reg[3];
462 $shour = (int) $reg[4];
463 $smin = (int) $reg[5];
464 $ssec = (int) $reg[6];
468 if ($syear >= 50 && $syear < 100) {
471 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
472 } elseif (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)
473 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
474 || 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)
476 $syear = (int) $reg[1];
477 $smonth = (int) $reg[2];
478 $sday = (int) $reg[3];
479 $shour = (int) $reg[4];
480 $smin = (int) $reg[5];
481 $ssec = (int) $reg[6];
482 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
485 $string = preg_replace(
'/([^0-9])/i',
'', $string);
486 $tmp = $string.
'000000';
490 } elseif (empty($gm) || $gm ===
'tzserver') {
494 $date =
dol_mktime((
int) substr($tmp, 8, 2), (
int) substr($tmp, 10, 2), (
int) substr($tmp, 12, 2), (
int) substr($tmp, 4, 2), (
int) substr($tmp, 6, 2), (
int) substr($tmp, 0, 4), $gm);
510 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
511 $time -= 24 * 60 * 60;
513 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
526 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
527 $time += 24 * 60 * 60;
529 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
543 $prev_year = $year - 1;
545 $prev_month = $month - 1;
548 return array(
'year' => $prev_year,
'month' => $prev_month);
562 $next_year = $year + 1;
564 $next_month = $month + 1;
567 return array(
'year' => $next_year,
'month' => $next_month);
583 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
584 $time -= 24 * 60 * 60 * 7;
586 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
602 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
603 $time += 24 * 60 * 60 * 7;
606 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
625 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
652 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
653 $datelim -= (3600 * 24);
668 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
669 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
682 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
683 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
698 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
706 $days = $start_week - $tmparray[
'wday'];
711 $seconds = $days * 24 * 60 * 60;
715 $tmpdaytms = (int)
date((
string) $tmparray[
'0']) - $seconds;
716 $tmpday = idate(
"d", $tmpdaytms);
719 if ($tmpday > $day) {
720 $prev_month = $month - 1;
723 if ($prev_month == 0) {
725 $prev_year = $year - 1;
728 $prev_month = $month;
731 $tmpmonth = $prev_month;
732 $tmpyear = $prev_year;
735 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
736 $tmptime -= 24 * 60 * 60 * 7;
738 $prev_day = $tmparray[
'mday'];
741 if ($prev_day > $tmpday) {
742 $prev_month = $month - 1;
745 if ($prev_month == 0) {
747 $prev_year = $year - 1;
751 $week =
date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
753 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);
765 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
766 $days = easter_days($year);
767 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
768 return $tmp->getTimestamp();
787function num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
794 if (($timestampEnd - $timestampStart) % 86400 != 0) {
795 return 'Error Dates must use same hours and must be GMT dates';
798 if (empty($countryCodeOrId)) {
799 $countryCodeOrId =
$mysoc->country_code;
801 if ($includemonday < 0) {
802 $includemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
804 if ($includefriday < 0) {
805 $includefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
807 if ($includesaturday < 0) {
808 $includesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
810 if ($includesunday < 0) {
811 $includesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
814 if (is_numeric($countryCodeOrId)) {
815 $country_id = $countryCodeOrId;
820 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id])) {
822 $tmpArrayOfPublicHolidays = array();
823 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
824 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
825 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".((int) $country_id) : 0).
")";
826 $sql .=
" AND entity IN (0," .getEntity(
'holiday') .
")";
828 $resql =
$db->query($sql);
830 $num_rows =
$db->num_rows($resql);
832 while ($i < $num_rows) {
833 $obj =
$db->fetch_object($resql);
834 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
839 return 'Error sql '.$db->lasterror();
843 $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id] = $tmpArrayOfPublicHolidays;
846 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id];
849 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
852 $specialdayrule = array();
854 $jour = (int) gmdate(
"d", $timestampStart);
855 $mois = (int) gmdate(
"m", $timestampStart);
856 $annee = (int) gmdate(
"Y", $timestampStart);
857 $jour_semaine = (int) gmdate(
"w", $timestampStart);
860 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
861 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
862 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
865 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
868 if ($entrypublicholiday[
'month'] != $mois) {
871 if ($entrypublicholiday[
'day'] != $jour) {
887 if (in_array(
'easter', $specialdayrule)) {
890 $jour_paques = gmdate(
"d", $date_paques);
891 $mois_paques = gmdate(
"m", $date_paques);
892 if ($jour_paques == $jour && $mois_paques == $mois) {
898 if (in_array(
'eastermonday', $specialdayrule)) {
902 $date_lundi_paques = $date_paques + (3600 * 24);
903 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
904 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
905 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
913 if (in_array(
'goodfriday', $specialdayrule)) {
918 $date_good_friday = $easter - (2 * 3600 * 24);
919 $dom_good_friday = gmdate(
"d", $date_good_friday);
920 $month_good_friday = gmdate(
"m", $date_good_friday);
922 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
927 if (in_array(
'ascension', $specialdayrule)) {
930 $date_ascension = $date_paques + (3600 * 24 * 39);
931 $jour_ascension = gmdate(
"d", $date_ascension);
932 $mois_ascension = gmdate(
"m", $date_ascension);
933 if ($jour_ascension == $jour && $mois_ascension == $mois) {
939 if (in_array(
'pentecost', $specialdayrule)) {
942 $date_pentecote = $date_paques + (3600 * 24 * 49);
943 $jour_pentecote = gmdate(
"d", $date_pentecote);
944 $mois_pentecote = gmdate(
"m", $date_pentecote);
945 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
950 if (in_array(
'pentecotemonday', $specialdayrule)) {
953 $date_pentecote = $date_paques + (3600 * 24 * 50);
954 $jour_pentecote = gmdate(
"d", $date_pentecote);
955 $mois_pentecote = gmdate(
"m", $date_pentecote);
956 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
962 if (in_array(
'viernessanto', $specialdayrule)) {
965 $date_viernes = $date_paques - (3600 * 24 * 2);
966 $jour_viernes = gmdate(
"d", $date_viernes);
967 $mois_viernes = gmdate(
"m", $date_viernes);
968 if ($jour_viernes == $jour && $mois_viernes == $mois) {
974 if (in_array(
'fronleichnam', $specialdayrule)) {
977 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
978 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
979 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
980 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
986 if (in_array(
'genevafast', $specialdayrule)) {
988 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
989 $jour_1sunsept =
date(
"d", $date_1sunsept);
990 $mois_1sunsept =
date(
"m", $date_1sunsept);
991 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
1001 if ($includefriday || $includesaturday || $includesunday || $includemonday) {
1003 if ($includefriday && $jour_semaine == 5) {
1006 if ($includesaturday && $jour_semaine == 6) {
1009 if ($includesunday && $jour_semaine == 0) {
1012 if ($includemonday && $jour_semaine == 1) {
1029 $timestampStart += 86400;
1055function listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $excludesaturday = -1, $excludesunday = -1, $excludefriday = -1, $excludemonday = -1)
1060 if (($timestampEnd - $timestampStart) % 86400 != 0) {
1061 return 'Error Dates must use same hours and must be GMT dates';
1064 if (empty($countryCodeOrId)) {
1065 $countryCodeOrId =
$mysoc->country_code;
1067 if ($excludemonday < 0) {
1068 $excludemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
1070 if ($excludefriday < 0) {
1071 $excludefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
1073 if ($excludesaturday < 0) {
1074 $excludesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1076 if ($excludesunday < 0) {
1077 $excludesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1080 if (is_numeric($countryCodeOrId)) {
1081 $country_id = $countryCodeOrId;
1086 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id])) {
1088 $tmpArrayOfPublicHolidays = array();
1089 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
1090 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_hrm_public_holiday";
1091 $sql .=
" WHERE active = 1 and fk_country IN (0" . ($country_id > 0 ?
", " . ((int) $country_id) : 0) .
")";
1092 $sql .=
" AND entity IN (0," .
getEntity(
'holiday') .
")";
1094 $resql =
$db->query($sql);
1096 $num_rows =
$db->num_rows($resql);
1098 while ($i < $num_rows) {
1099 $obj =
$db->fetch_object($resql);
1100 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
1105 return 'Error sql ' .
$db->lasterror();
1109 $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id] = $tmpArrayOfPublicHolidays;
1112 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id];
1115 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
1117 $nonWorkingDay =
false;
1119 $specialdayrule = array();
1121 $jour = (int) gmdate(
"d", $timestampStart);
1122 $mois = (int) gmdate(
"m", $timestampStart);
1123 $annee = (int) gmdate(
"Y", $timestampStart);
1126 if ($excludefriday || $excludesaturday || $excludesunday) {
1127 $jour_julien = unixtojd($timestampStart);
1128 $jour_semaine = jddayofweek($jour_julien, 0);
1129 if ($excludefriday) {
1130 if ($jour_semaine == 5) {
1131 $nonWorkingDay =
true;
1134 if ($excludesaturday) {
1135 if ($jour_semaine == 6) {
1136 $nonWorkingDay =
true;
1139 if ($excludesunday) {
1140 if ($jour_semaine == 0) {
1141 $nonWorkingDay =
true;
1147 if (!$nonWorkingDay) {
1149 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
1150 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
1151 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
1154 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
1157 if ($entrypublicholiday[
'month'] != $mois) {
1160 if ($entrypublicholiday[
'day'] != $jour) {
1166 $listFeries[] = $timestampStart;
1176 if (!$nonWorkingDay && !$ferie) {
1178 if (in_array(
'easter', $specialdayrule)) {
1181 $jour_paques = gmdate(
"d", $date_paques);
1182 $mois_paques = gmdate(
"m", $date_paques);
1183 if ($jour_paques == $jour && $mois_paques == $mois) {
1185 $listFeries[] = $timestampStart;
1190 if (in_array(
'eastermonday', $specialdayrule)) {
1194 $date_lundi_paques = $date_paques + (3600 * 24);
1195 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
1196 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
1197 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
1199 $listFeries[] = $timestampStart;
1206 if (in_array(
'goodfriday', $specialdayrule)) {
1211 $date_good_friday = $easter - (2 * 3600 * 24);
1212 $dom_good_friday = gmdate(
"d", $date_good_friday);
1213 $month_good_friday = gmdate(
"m", $date_good_friday);
1215 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
1217 $listFeries[] = $timestampStart;
1221 if (in_array(
'ascension', $specialdayrule)) {
1224 $date_ascension = $date_paques + (3600 * 24 * 39);
1225 $jour_ascension = gmdate(
"d", $date_ascension);
1226 $mois_ascension = gmdate(
"m", $date_ascension);
1227 if ($jour_ascension == $jour && $mois_ascension == $mois) {
1229 $listFeries[] = $timestampStart;
1234 if (in_array(
'pentecost', $specialdayrule)) {
1237 $date_pentecote = $date_paques + (3600 * 24 * 49);
1238 $jour_pentecote = gmdate(
"d", $date_pentecote);
1239 $mois_pentecote = gmdate(
"m", $date_pentecote);
1240 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1242 $listFeries[] = $timestampStart;
1247 if (in_array(
'pentecotemonday', $specialdayrule)) {
1250 $date_pentecote = $date_paques + (3600 * 24 * 50);
1251 $jour_pentecote = gmdate(
"d", $date_pentecote);
1252 $mois_pentecote = gmdate(
"m", $date_pentecote);
1253 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1255 $listFeries[] = $timestampStart;
1260 if (in_array(
'viernessanto', $specialdayrule)) {
1263 $date_viernes = $date_paques - (3600 * 24 * 2);
1264 $jour_viernes = gmdate(
"d", $date_viernes);
1265 $mois_viernes = gmdate(
"m", $date_viernes);
1266 if ($jour_viernes == $jour && $mois_viernes == $mois) {
1268 $listFeries[] = $timestampStart;
1273 if (in_array(
'fronleichnam', $specialdayrule)) {
1276 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
1277 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
1278 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
1279 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
1281 $listFeries[] = $timestampStart;
1286 if (in_array(
'genevafast', $specialdayrule)) {
1288 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
1289 $jour_1sunsept =
date(
"d", $date_1sunsept);
1290 $mois_1sunsept =
date(
"m", $date_1sunsept);
1291 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
1293 $listFeries[] = $timestampStart;
1323 if ($timestampStart <= $timestampEnd) {
1324 if ($lastday == 1) {
1329 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
1353function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $countryCodeOrId =
'', $user_id = 0)
1355 global $langs,
$mysoc, $hookmanager;
1357 if (empty($countryCodeOrId) || $countryCodeOrId < 0) {
1358 $countryCodeOrId =
$mysoc->country_code;
1361 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' countryCodeOrId='.$countryCodeOrId);
1364 if (!is_int($timestampStart) && !is_float($timestampStart)) {
1365 return 'ErrorBadParameter_num_open_day';
1367 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
1368 return 'ErrorBadParameter_num_open_day';
1373 if ($timestampStart < $timestampEnd) {
1378 $nbOpenDay = $a - $b;
1381 $halfday = (int) $halfday;
1386 $isStartDayWorking = (
num_public_holiday($timestampStart, $timestampStart, $countryCodeOrId, 1) == 0);
1388 $isEndDayWorking = (
num_public_holiday($timestampEnd, $timestampEnd, $countryCodeOrId, 1) == 0);
1391 if (($halfday == -1 || $halfday == 2) && $isStartDayWorking) {
1396 if (($halfday == 1 || $halfday == 2) &&
date(
'Y-m-d', $timestampStart) !=
date(
'Y-m-d', $timestampEnd) && $isEndDayWorking) {
1399 } elseif ($timestampStart == $timestampEnd) {
1400 $isSingleDayHoliday =
false;
1402 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId, $lastday);
1403 if ($numholidays == 1) {
1404 $isSingleDayHoliday =
true;
1407 if (!$isSingleDayHoliday) {
1408 $nbOpenDay = $lastday - 0.5 * abs((
int) $halfday);
1411 return $langs->trans(
"Error");
1417 if ($user_id > 0 && is_object($hookmanager)) {
1418 $parameters = array(
1419 'timestampStart' => $timestampStart,
1420 'timestampEnd' => $timestampEnd,
1421 'inhour' => $inhour,
1422 'lastday' => $lastday,
1423 'halfday' => $halfday,
1424 'countryCodeOrId' => $countryCodeOrId,
1425 'user_id' => $user_id,
1426 'nbOpenDay' => $nbOpenDay,
1429 $reshook = $hookmanager->executeHooks(
'numOpenDay', $parameters, $hookmanager, $action);
1430 if ($reshook > 0 && isset($hookmanager->resArray[
'nbOpenDay'])) {
1431 $nbOpenDay = $hookmanager->resArray[
'nbOpenDay'];
1436 return (
int) ($nbOpenDay * 24);
1453 $montharray = array(
1454 1 => $outputlangs->trans(
"Month01"),
1455 2 => $outputlangs->trans(
"Month02"),
1456 3 => $outputlangs->trans(
"Month03"),
1457 4 => $outputlangs->trans(
"Month04"),
1458 5 => $outputlangs->trans(
"Month05"),
1459 6 => $outputlangs->trans(
"Month06"),
1460 7 => $outputlangs->trans(
"Month07"),
1461 8 => $outputlangs->trans(
"Month08"),
1462 9 => $outputlangs->trans(
"Month09"),
1463 10 => $outputlangs->trans(
"Month10"),
1464 11 => $outputlangs->trans(
"Month11"),
1465 12 => $outputlangs->trans(
"Month12")
1468 if (!empty($short)) {
1469 $montharray = array(
1470 1 => $outputlangs->trans(
"MonthShort01"),
1471 2 => $outputlangs->trans(
"MonthShort02"),
1472 3 => $outputlangs->trans(
"MonthShort03"),
1473 4 => $outputlangs->trans(
"MonthShort04"),
1474 5 => $outputlangs->trans(
"MonthShort05"),
1475 6 => $outputlangs->trans(
"MonthShort06"),
1476 7 => $outputlangs->trans(
"MonthShort07"),
1477 8 => $outputlangs->trans(
"MonthShort08"),
1478 9 => $outputlangs->trans(
"MonthShort09"),
1479 10 => $outputlangs->trans(
"MonthShort10"),
1480 11 => $outputlangs->trans(
"MonthShort11"),
1481 12 => $outputlangs->trans(
"MonthShort12")
1497 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1499 for ($day = 1; $day <= $nb_days; $day++) {
1501 $TWeek[$week_number] = $week_number;
1515 $TFirstDayOfWeek = array();
1519 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1520 foreach ($TWeek as $weekNb) {
1522 if ($startwithweeksofpreviousyear) {
1523 if ((
int) $weekNb >= 52) {
1524 $yeartouse = $year - 1;
1526 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1527 $yeartouse = $year + 1;
1529 $TFirstDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb));
1531 return $TFirstDayOfWeek;
1543 $TLastDayOfWeek = array();
1545 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1546 foreach ($TWeek as $weekNb) {
1548 if ($startwithweeksofpreviousyear) {
1549 if ((
int) $weekNb >= 52) {
1550 $yeartouse = $year - 1;
1552 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1553 $yeartouse = $year + 1;
1555 $TLastDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb.
'+6 days'));
1557 return $TLastDayOfWeek;
1570 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1571 $week = $date->format(
"W");
dol_get_prev_month($month, $year)
Return previous month.
listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId='', $lastday=0, $excludesaturday=-1, $excludesunday=-1, $excludefriday=-1, $excludemonday=-1)
Return the list of public holidays including Friday, Saturday and Sunday (or not) between 2 dates in ...
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_next_day($day, $month, $year)
Return next day.
dol_get_next_week($day, $week, $month, $year)
Return next week.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
getServerTimeZoneString()
Return server timezone string.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
getLastDayOfEachWeek($TWeek, $year)
Return array of last day of weeks.
getWeekNumbersOfMonth($month, $year)
Return array of week numbers.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
getGMTEasterDatetime($year)
Return the easter day in GMT time.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='', $user_id=0)
Function to return number of working days (and text of units) between two dates (working days)
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
get_tz_array()
Return an array with timezone values.
dol_get_prev_day($day, $month, $year)
Return previous day.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
getFirstDayOfEachWeek($TWeek, $year)
Return array of first day of weeks.
dol_get_next_month($month, $year)
Return next month.
getWeekNumber($day, $month, $year)
Return week number.
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...
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId='', $lastday=0, $includesaturday=-1, $includesunday=-1, $includefriday=-1, $includemonday=-1)
Return the number of non working days including Friday, Saturday and Sunday (or not) between 2 dates ...
convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
Convert hours and minutes into seconds.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
dol_get_prev_week($day, $week, $month, $year)
Return previous week.
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...
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
monthArray($outputlangs, $short=0)
Return array of translated months or selected month.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date