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);
109 dol_print_error(
null,
'PHP version must be 5.3+');
111 $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
128 if (empty($duration_value)) {
131 if (!in_array($duration_unit, array(
's',
'i',
'mn',
'min',
'h',
'd',
'w',
'm',
'y'))) {
132 $errormsg =
'dol_time_plus_duree call to function with undefined or bad duration_unit : ' . $duration_unit;
136 if ($duration_unit ==
's') {
137 return $time + (int) ($duration_value);
139 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
140 return $time + (int) (60 * $duration_value);
142 if ($duration_unit ==
'h') {
143 return $time + (int) (3600 * $duration_value);
145 if ($duration_unit ==
'w') {
146 return $time + (int) (3600 * 24 * 7 * $duration_value);
153 if ($duration_value > 0) {
154 $deltastring .= abs($duration_value);
157 if ($duration_value < 0) {
158 $deltastring .= abs($duration_value);
161 if ($duration_unit ==
'd') {
164 if ($duration_unit ==
'm') {
167 if ($duration_unit ==
'y') {
171 $date =
new DateTime();
172 if (!function_exists(
'getDolGlobalString') || !
getDolGlobalString(
'MAIN_DATE_IN_MEMORY_ARE_NOT_GMT')) {
173 $date->setTimezone(
new DateTimeZone(
'UTC'));
177 $date->setTimestamp((
int) $time);
178 $interval =
new DateInterval($deltastring);
181 $date->sub($interval);
183 $date->add($interval);
187 if ($ruleforendofmonth == 1 && $duration_unit ==
'm') {
190 $timetotalmonths = (($timeyear * 12) + $timemonth);
192 $monthsexpected = ($timetotalmonths + $duration_value);
194 $newtime = $date->getTimestamp();
198 $newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
200 if ($monthsexpected < $newtimetotalmonths || $monthsexpected > $newtimetotalmonths) {
205 $datelim =
dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
206 $datelim -= (3600 * 24);
208 $date->setTimestamp($datelim);
211 return $date->getTimestamp();
226 $iResult = ((int) $iHours * 3600) + ((int) $iMinutes * 60) + (int) $iSeconds;
257 if (empty($lengthOfDay)) {
258 $lengthOfDay = 86400;
260 if (empty($lengthOfWeek)) {
263 $nbHbyDay = $lengthOfDay / 3600;
267 if ($format ==
'all' || $format ==
'allwithouthour' || $format ==
'allhour' || $format ==
'allhourmin' || $format ==
'allhourminsec') {
268 if ((
int) $iSecond === 0) {
275 if ($iSecond >= $lengthOfDay) {
276 for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) {
278 $iSecond -= $lengthOfDay;
280 $dayTranslate = $langs->trans(
"Day");
281 if ($iSecond >= ($lengthOfDay * 2)) {
282 $dayTranslate = $langs->trans(
"Days");
286 if ($lengthOfWeek < 7) {
288 if ($sDay >= $lengthOfWeek) {
289 $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
290 $sDay %= $lengthOfWeek;
291 $weekTranslate = $langs->trans(
"DurationWeek");
293 $weekTranslate = $langs->trans(
"DurationWeeks");
295 $sTime .= $sWeek.
' '.$weekTranslate.
' ';
300 $dayTranslate = $langs->trans(
"Day");
302 $dayTranslate = $langs->trans(
"Days");
304 $sTime .= $sDay.
' '.$langs->trans(
"d").
' ';
307 if ($format ==
'all') {
308 if ($iSecond || empty($sDay)) {
311 } elseif ($format ==
'allhourminsec') {
312 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60))).
':'.sprintf(
"%02d", ((
int) ($iSecond % 60)));
313 } elseif ($format ==
'allhourmin') {
314 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60)));
315 } elseif ($format ==
'allhour') {
316 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600)));
318 } elseif ($format ==
'hour') {
320 } elseif ($format ==
'fullhour') {
321 if (!empty($iSecond)) {
327 } elseif ($format ==
'min') {
329 } elseif ($format ==
'sec') {
331 } elseif ($format ==
'month') {
333 } elseif ($format ==
'year') {
336 return trim((
string) $sTime);
351 if ($duration_unit ==
's') {
352 $result = $duration_value / 3600;
354 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
355 $result = $duration_value / 60;
357 if ($duration_unit ==
'h') {
358 $result = $duration_value;
360 if ($duration_unit ==
'd') {
361 $result = $duration_value * 24;
363 if ($duration_unit ==
'w') {
364 $result = $duration_value * 24 * 7;
366 if ($duration_unit ==
'm') {
367 $result = $duration_value * 730.484;
369 if ($duration_unit ==
'y') {
370 $result = $duration_value * 365 * 24;
391function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand = 0, $gm =
false)
396 $day_date = intval($day_date);
397 $month_date = intval($month_date);
398 $year_date = intval($year_date);
399 $sql_datefield = $db->sanitize($datefield);
401 if ($month_date > 0) {
402 if ($month_date > 12) {
405 if ($year_date > 0 && empty($day_date)) {
406 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, $month_date, $gm)).
"'";
407 $sqldate .=
" AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
408 } elseif ($year_date > 0 && !empty($day_date)) {
409 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm)).
"'";
410 $sqldate .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
413 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$sql_datefield.
", '%c') = '".$db->escape((
string) $month_date).
"'";
415 } elseif ($year_date > 0) {
416 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, 1, $gm)).
"'";
446 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
447 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
450 $sday = (int) $reg[1];
451 $smonth = (int) $reg[2];
452 $syear = (int) $reg[3];
453 $shour = (int) $reg[4];
454 $smin = (int) $reg[5];
455 $ssec = (int) $reg[6];
459 if ($syear >= 50 && $syear < 100) {
462 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
463 } 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)
464 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
465 || 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)
467 $syear = (int) $reg[1];
468 $smonth = (int) $reg[2];
469 $sday = (int) $reg[3];
470 $shour = (int) $reg[4];
471 $smin = (int) $reg[5];
472 $ssec = (int) $reg[6];
473 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
476 $string = preg_replace(
'/([^0-9])/i',
'', $string);
478 if ($processnotimeasnoon) {
479 $tmp = $string.
'120000';
481 $tmp = $string.
'000000';
486 } elseif (empty($gm) || $gm ===
'tzserver') {
490 $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);
506 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
507 $time -= 24 * 60 * 60;
509 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
522 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
523 $time += 24 * 60 * 60;
525 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
539 $prev_year = $year - 1;
541 $prev_month = $month - 1;
544 return array(
'year' => $prev_year,
'month' => $prev_month);
558 $next_year = $year + 1;
560 $next_month = $month + 1;
563 return array(
'year' => $next_year,
'month' => $next_month);
579 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
580 $time -= 24 * 60 * 60 * 7;
582 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
598 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
599 $time += 24 * 60 * 60 * 7;
602 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
621 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
648 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
649 $datelim -= (3600 * 24);
664 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
665 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
678 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
679 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
694 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
702 $days = $start_week - $tmparray[
'wday'];
707 $seconds = $days * 24 * 60 * 60;
711 $tmpdaytms = (int)
date((
string) $tmparray[
'0']) - $seconds;
712 $tmpday = idate(
"d", $tmpdaytms);
715 if ($tmpday > $day) {
716 $prev_month = $month - 1;
719 if ($prev_month == 0) {
721 $prev_year = $year - 1;
724 $prev_month = $month;
727 $tmpmonth = $prev_month;
728 $tmpyear = $prev_year;
731 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
732 $tmptime -= 24 * 60 * 60 * 7;
734 $prev_day = $tmparray[
'mday'];
737 if ($prev_day > $tmpday) {
738 $prev_month = $month - 1;
741 if ($prev_month == 0) {
743 $prev_year = $year - 1;
747 $week =
date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
749 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);
761 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
762 $days = easter_days($year);
763 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
764 return $tmp->getTimestamp();
783function num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
790 if (($timestampEnd - $timestampStart) % 86400 != 0) {
791 return 'Error Dates must use same hours and must be GMT dates';
794 if (empty($countryCodeOrId)) {
795 $countryCodeOrId =
$mysoc->country_code;
797 if ($includemonday < 0) {
798 $includemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
800 if ($includefriday < 0) {
801 $includefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
803 if ($includesaturday < 0) {
804 $includesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
806 if ($includesunday < 0) {
807 $includesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
810 if (is_numeric($countryCodeOrId)) {
811 $country_id = $countryCodeOrId;
813 $country_id =
dol_getIdFromCode($db, $countryCodeOrId,
'c_country',
'code',
'rowid');
816 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id])) {
818 $tmpArrayOfPublicHolidays = array();
819 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
820 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
821 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".((int) $country_id) : 0).
")";
822 $sql .=
" AND entity IN (0," .getEntity(
'holiday') .
")";
824 $resql = $db->query($sql);
826 $num_rows = $db->num_rows($resql);
828 while ($i < $num_rows) {
829 $obj = $db->fetch_object($resql);
830 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
835 return 'Error sql '.$db->lasterror();
839 $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id] = $tmpArrayOfPublicHolidays;
842 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id];
845 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
848 $specialdayrule = array();
850 $jour = (int) gmdate(
"d", $timestampStart);
851 $mois = (int) gmdate(
"m", $timestampStart);
852 $annee = (int) gmdate(
"Y", $timestampStart);
853 $jour_semaine = (int) gmdate(
"w", $timestampStart);
856 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
857 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
858 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
861 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
864 if ($entrypublicholiday[
'month'] != $mois) {
867 if ($entrypublicholiday[
'day'] != $jour) {
883 if (in_array(
'easter', $specialdayrule)) {
886 $jour_paques = gmdate(
"d", $date_paques);
887 $mois_paques = gmdate(
"m", $date_paques);
888 if ($jour_paques == $jour && $mois_paques == $mois) {
894 if (in_array(
'eastermonday', $specialdayrule)) {
898 $date_lundi_paques = $date_paques + (3600 * 24);
899 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
900 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
901 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
909 if (in_array(
'goodfriday', $specialdayrule)) {
914 $date_good_friday = $easter - (2 * 3600 * 24);
915 $dom_good_friday = gmdate(
"d", $date_good_friday);
916 $month_good_friday = gmdate(
"m", $date_good_friday);
918 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
923 if (in_array(
'ascension', $specialdayrule)) {
926 $date_ascension = $date_paques + (3600 * 24 * 39);
927 $jour_ascension = gmdate(
"d", $date_ascension);
928 $mois_ascension = gmdate(
"m", $date_ascension);
929 if ($jour_ascension == $jour && $mois_ascension == $mois) {
935 if (in_array(
'pentecost', $specialdayrule)) {
938 $date_pentecote = $date_paques + (3600 * 24 * 49);
939 $jour_pentecote = gmdate(
"d", $date_pentecote);
940 $mois_pentecote = gmdate(
"m", $date_pentecote);
941 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
946 if (in_array(
'pentecotemonday', $specialdayrule)) {
949 $date_pentecote = $date_paques + (3600 * 24 * 50);
950 $jour_pentecote = gmdate(
"d", $date_pentecote);
951 $mois_pentecote = gmdate(
"m", $date_pentecote);
952 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
958 if (in_array(
'viernessanto', $specialdayrule)) {
961 $date_viernes = $date_paques - (3600 * 24 * 2);
962 $jour_viernes = gmdate(
"d", $date_viernes);
963 $mois_viernes = gmdate(
"m", $date_viernes);
964 if ($jour_viernes == $jour && $mois_viernes == $mois) {
970 if (in_array(
'fronleichnam', $specialdayrule)) {
973 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
974 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
975 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
976 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
982 if (in_array(
'genevafast', $specialdayrule)) {
984 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
985 $jour_1sunsept =
date(
"d", $date_1sunsept);
986 $mois_1sunsept =
date(
"m", $date_1sunsept);
987 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
997 if ($includefriday || $includesaturday || $includesunday || $includemonday) {
999 if ($includefriday && $jour_semaine == 5) {
1002 if ($includesaturday && $jour_semaine == 6) {
1005 if ($includesunday && $jour_semaine == 0) {
1008 if ($includemonday && $jour_semaine == 1) {
1025 $timestampStart += 86400;
1051function listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $excludesaturday = -1, $excludesunday = -1, $excludefriday = -1, $excludemonday = -1)
1056 if (($timestampEnd - $timestampStart) % 86400 != 0) {
1057 return 'Error Dates must use same hours and must be GMT dates';
1060 if (empty($countryCodeOrId)) {
1061 $countryCodeOrId =
$mysoc->country_code;
1063 if ($excludemonday < 0) {
1064 $excludemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
1066 if ($excludefriday < 0) {
1067 $excludefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
1069 if ($excludesaturday < 0) {
1070 $excludesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1072 if ($excludesunday < 0) {
1073 $excludesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1076 if (is_numeric($countryCodeOrId)) {
1077 $country_id = $countryCodeOrId;
1079 $country_id =
dol_getIdFromCode($db, $countryCodeOrId,
'c_country',
'code',
'rowid');
1082 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id])) {
1084 $tmpArrayOfPublicHolidays = array();
1085 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
1086 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_hrm_public_holiday";
1087 $sql .=
" WHERE active = 1 and fk_country IN (0" . ($country_id > 0 ?
", " . ((int) $country_id) : 0) .
")";
1088 $sql .=
" AND entity IN (0," .
getEntity(
'holiday') .
")";
1090 $resql = $db->query($sql);
1092 $num_rows = $db->num_rows($resql);
1094 while ($i < $num_rows) {
1095 $obj = $db->fetch_object($resql);
1096 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
1101 return 'Error sql ' . $db->lasterror();
1105 $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id] = $tmpArrayOfPublicHolidays;
1108 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id];
1111 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
1113 $nonWorkingDay =
false;
1115 $specialdayrule = array();
1117 $jour = (int) gmdate(
"d", $timestampStart);
1118 $mois = (int) gmdate(
"m", $timestampStart);
1119 $annee = (int) gmdate(
"Y", $timestampStart);
1122 if ($excludefriday || $excludesaturday || $excludesunday) {
1123 $jour_julien = unixtojd($timestampStart);
1124 $jour_semaine = jddayofweek($jour_julien, 0);
1125 if ($excludefriday) {
1126 if ($jour_semaine == 5) {
1127 $nonWorkingDay =
true;
1130 if ($excludesaturday) {
1131 if ($jour_semaine == 6) {
1132 $nonWorkingDay =
true;
1135 if ($excludesunday) {
1136 if ($jour_semaine == 0) {
1137 $nonWorkingDay =
true;
1143 if (!$nonWorkingDay) {
1145 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
1146 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
1147 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
1150 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
1153 if ($entrypublicholiday[
'month'] != $mois) {
1156 if ($entrypublicholiday[
'day'] != $jour) {
1162 $listFeries[] = $timestampStart;
1172 if (!$nonWorkingDay && !$ferie) {
1174 if (in_array(
'easter', $specialdayrule)) {
1177 $jour_paques = gmdate(
"d", $date_paques);
1178 $mois_paques = gmdate(
"m", $date_paques);
1179 if ($jour_paques == $jour && $mois_paques == $mois) {
1181 $listFeries[] = $timestampStart;
1186 if (in_array(
'eastermonday', $specialdayrule)) {
1190 $date_lundi_paques = $date_paques + (3600 * 24);
1191 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
1192 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
1193 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
1195 $listFeries[] = $timestampStart;
1202 if (in_array(
'goodfriday', $specialdayrule)) {
1207 $date_good_friday = $easter - (2 * 3600 * 24);
1208 $dom_good_friday = gmdate(
"d", $date_good_friday);
1209 $month_good_friday = gmdate(
"m", $date_good_friday);
1211 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
1213 $listFeries[] = $timestampStart;
1217 if (in_array(
'ascension', $specialdayrule)) {
1220 $date_ascension = $date_paques + (3600 * 24 * 39);
1221 $jour_ascension = gmdate(
"d", $date_ascension);
1222 $mois_ascension = gmdate(
"m", $date_ascension);
1223 if ($jour_ascension == $jour && $mois_ascension == $mois) {
1225 $listFeries[] = $timestampStart;
1230 if (in_array(
'pentecost', $specialdayrule)) {
1233 $date_pentecote = $date_paques + (3600 * 24 * 49);
1234 $jour_pentecote = gmdate(
"d", $date_pentecote);
1235 $mois_pentecote = gmdate(
"m", $date_pentecote);
1236 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1238 $listFeries[] = $timestampStart;
1243 if (in_array(
'pentecotemonday', $specialdayrule)) {
1246 $date_pentecote = $date_paques + (3600 * 24 * 50);
1247 $jour_pentecote = gmdate(
"d", $date_pentecote);
1248 $mois_pentecote = gmdate(
"m", $date_pentecote);
1249 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1251 $listFeries[] = $timestampStart;
1256 if (in_array(
'viernessanto', $specialdayrule)) {
1259 $date_viernes = $date_paques - (3600 * 24 * 2);
1260 $jour_viernes = gmdate(
"d", $date_viernes);
1261 $mois_viernes = gmdate(
"m", $date_viernes);
1262 if ($jour_viernes == $jour && $mois_viernes == $mois) {
1264 $listFeries[] = $timestampStart;
1269 if (in_array(
'fronleichnam', $specialdayrule)) {
1272 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
1273 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
1274 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
1275 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
1277 $listFeries[] = $timestampStart;
1282 if (in_array(
'genevafast', $specialdayrule)) {
1284 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
1285 $jour_1sunsept =
date(
"d", $date_1sunsept);
1286 $mois_1sunsept =
date(
"m", $date_1sunsept);
1287 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
1289 $listFeries[] = $timestampStart;
1319 if ($timestampStart <= $timestampEnd) {
1320 if ($lastday == 1) {
1325 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
1355 if ($timestampStart > $timestampEnd) {
1359 $start =
dol_getdate((
int) $timestampStart,
false, $forcetimezone);
1360 $end =
dol_getdate((
int) $timestampEnd,
false, $forcetimezone);
1363 $daystart = min($start[
'mday'], 30);
1364 $dayend = min($end[
'mday'], 30);
1366 $nbdays = ($dayend - $daystart) + 30 * ($end[
'mon'] - $start[
'mon']) + 360 * ($end[
'year'] - $start[
'year']);
1367 if ($lastday == 1) {
1371 return max(0, $nbdays);
1383 $year = (int) $year;
1384 $isleapyear = (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0);
1386 return $isleapyear ? 366 : 365;
1405function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $countryCodeOrId =
'', $user_id = 0)
1407 global $langs,
$mysoc, $hookmanager;
1409 if (empty($countryCodeOrId) || $countryCodeOrId < 0) {
1410 $countryCodeOrId =
$mysoc->country_code;
1413 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' countryCodeOrId='.$countryCodeOrId);
1416 if (!is_int($timestampStart) && !is_float($timestampStart)) {
1417 return 'ErrorBadParameter_num_open_day';
1419 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
1420 return 'ErrorBadParameter_num_open_day';
1425 if ($timestampStart < $timestampEnd) {
1430 $nbOpenDay = $a - $b;
1433 $halfday = (int) $halfday;
1438 $isStartDayWorking = (
num_public_holiday($timestampStart, $timestampStart, $countryCodeOrId, 1) == 0);
1440 $isEndDayWorking = (
num_public_holiday($timestampEnd, $timestampEnd, $countryCodeOrId, 1) == 0);
1443 if (($halfday == -1 || $halfday == 2) && $isStartDayWorking) {
1448 if (($halfday == 1 || $halfday == 2) &&
date(
'Y-m-d', $timestampStart) !=
date(
'Y-m-d', $timestampEnd) && $isEndDayWorking) {
1451 } elseif ($timestampStart == $timestampEnd) {
1452 $isSingleDayHoliday =
false;
1454 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId, $lastday);
1455 if ($numholidays == 1) {
1456 $isSingleDayHoliday =
true;
1459 if (!$isSingleDayHoliday) {
1460 $nbOpenDay = $lastday - 0.5 * abs((
int) $halfday);
1463 return $langs->trans(
"Error");
1469 if ($user_id > 0 && is_object($hookmanager)) {
1470 $parameters = array(
1471 'timestampStart' => $timestampStart,
1472 'timestampEnd' => $timestampEnd,
1473 'inhour' => $inhour,
1474 'lastday' => $lastday,
1475 'halfday' => $halfday,
1476 'countryCodeOrId' => $countryCodeOrId,
1477 'user_id' => $user_id,
1478 'nbOpenDay' => $nbOpenDay,
1481 $reshook = $hookmanager->executeHooks(
'numOpenDay', $parameters, $hookmanager, $action);
1482 if ($reshook > 0 && isset($hookmanager->resArray[
'nbOpenDay'])) {
1483 $nbOpenDay = $hookmanager->resArray[
'nbOpenDay'];
1488 return (
int) ($nbOpenDay * 24);
1505 $montharray = array(
1506 1 => $outputlangs->trans(
"Month01"),
1507 2 => $outputlangs->trans(
"Month02"),
1508 3 => $outputlangs->trans(
"Month03"),
1509 4 => $outputlangs->trans(
"Month04"),
1510 5 => $outputlangs->trans(
"Month05"),
1511 6 => $outputlangs->trans(
"Month06"),
1512 7 => $outputlangs->trans(
"Month07"),
1513 8 => $outputlangs->trans(
"Month08"),
1514 9 => $outputlangs->trans(
"Month09"),
1515 10 => $outputlangs->trans(
"Month10"),
1516 11 => $outputlangs->trans(
"Month11"),
1517 12 => $outputlangs->trans(
"Month12")
1520 if (!empty($short)) {
1521 $montharray = array(
1522 1 => $outputlangs->trans(
"MonthShort01"),
1523 2 => $outputlangs->trans(
"MonthShort02"),
1524 3 => $outputlangs->trans(
"MonthShort03"),
1525 4 => $outputlangs->trans(
"MonthShort04"),
1526 5 => $outputlangs->trans(
"MonthShort05"),
1527 6 => $outputlangs->trans(
"MonthShort06"),
1528 7 => $outputlangs->trans(
"MonthShort07"),
1529 8 => $outputlangs->trans(
"MonthShort08"),
1530 9 => $outputlangs->trans(
"MonthShort09"),
1531 10 => $outputlangs->trans(
"MonthShort10"),
1532 11 => $outputlangs->trans(
"MonthShort11"),
1533 12 => $outputlangs->trans(
"MonthShort12")
1549 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1551 for ($day = 1; $day <= $nb_days; $day++) {
1553 $TWeek[$week_number] = $week_number;
1567 $TFirstDayOfWeek = array();
1571 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1572 foreach ($TWeek as $weekNb) {
1574 if ($startwithweeksofpreviousyear) {
1575 if ((
int) $weekNb >= 52) {
1576 $yeartouse = $year - 1;
1578 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1579 $yeartouse = $year + 1;
1581 $TFirstDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb));
1583 return $TFirstDayOfWeek;
1595 $TLastDayOfWeek = array();
1597 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1598 foreach ($TWeek as $weekNb) {
1600 if ($startwithweeksofpreviousyear) {
1601 if ((
int) $weekNb >= 52) {
1602 $yeartouse = $year - 1;
1604 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1605 $yeartouse = $year + 1;
1607 $TLastDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb.
'+6 days'));
1609 return $TLastDayOfWeek;
1622 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1623 $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)
num_days_in_year($year)
Function to return the real number of days of a year (365, or 366 for a leap year).
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_30_360($timestampStart, $timestampEnd, $lastday=0, $forcetimezone='')
Function to return number of days between two dates using the 30/360 day count convention: every mont...
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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_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_stringtotime($string, $gm=1, $processnotimeasnoon=0)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
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).
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