39 -11 =>
"Pacific/Pago_Pago",
40 -10 =>
"Pacific/Honolulu",
41 -9 =>
"America/Anchorage",
42 -8 =>
"America/Los_Angeles",
43 -7 =>
"America/Dawson_Creek",
44 -6 =>
"America/Chicago",
45 -5 =>
"America/Bogota",
46 -4 =>
"America/Asuncion",
47 -3 =>
"America/Araguaina",
48 -2 =>
"America/Noronha",
49 -1 =>
"Atlantic/Azores",
52 2 =>
"Europe/Helsinki",
58 8 =>
"Asia/Hong_Kong",
60 10 =>
"Australia/Sydney",
61 11 =>
"Pacific/Noumea",
62 12 =>
"Pacific/Auckland",
63 13 =>
"Pacific/Fakaofo",
64 14 =>
"Pacific/Kiritimati"
77 return @date_default_timezone_get();
88 if (method_exists(
'DateTimeZone',
'getOffset')) {
94 if ($refgmtdate ==
'now') {
95 $newrefgmtdate = $yearref.
'-'.$monthref.
'-'.$dayref;
96 } elseif ($refgmtdate ==
'summer') {
97 $newrefgmtdate = $yearref.
'-08-01';
99 $newrefgmtdate = $yearref.
'-01-01';
101 $newrefgmtdate .=
'T00:00:00+00:00';
103 $localdt =
new DateTime($newrefgmtdate, $localtz);
104 $tmp = -1 * $localtz->getOffset($localdt);
110 $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
127 if (empty($duration_value)) {
130 if ($duration_unit ==
's') {
131 return $time + (int) ($duration_value);
133 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
134 return $time + (int) (60 * $duration_value);
136 if ($duration_unit ==
'h') {
137 return $time + (int) (3600 * $duration_value);
139 if ($duration_unit ==
'w') {
140 return $time + (int) (3600 * 24 * 7 * $duration_value);
147 if ($duration_value > 0) {
148 $deltastring .= abs($duration_value);
151 if ($duration_value < 0) {
152 $deltastring .= abs($duration_value);
155 if ($duration_unit ==
'd') {
158 if ($duration_unit ==
'm') {
161 if ($duration_unit ==
'y') {
165 $date =
new DateTime();
166 if (!function_exists(
'getDolGlobalString') || !
getDolGlobalString(
'MAIN_DATE_IN_MEMORY_ARE_NOT_GMT')) {
167 $date->setTimezone(
new DateTimeZone(
'UTC'));
171 $date->setTimestamp((
int) $time);
172 $interval =
new DateInterval($deltastring);
175 $date->sub($interval);
177 $date->add($interval);
181 if ($ruleforendofmonth == 1 && $duration_unit ==
'm') {
184 $timetotalmonths = (($timeyear * 12) + $timemonth);
186 $monthsexpected = ($timetotalmonths + $duration_value);
188 $newtime = $date->getTimestamp();
192 $newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
194 if ($monthsexpected < $newtimetotalmonths || $monthsexpected > $newtimetotalmonths) {
199 $datelim =
dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
200 $datelim -= (3600 * 24);
202 $date->setTimestamp($datelim);
205 return $date->getTimestamp();
220 $iResult = ((int) $iHours * 3600) + ((int) $iMinutes * 60) + (int) $iSeconds;
251 if (empty($lengthOfDay)) {
252 $lengthOfDay = 86400;
254 if (empty($lengthOfWeek)) {
257 $nbHbyDay = $lengthOfDay / 3600;
261 if ($format ==
'all' || $format ==
'allwithouthour' || $format ==
'allhour' || $format ==
'allhourmin' || $format ==
'allhourminsec') {
262 if ((
int) $iSecond === 0) {
269 if ($iSecond >= $lengthOfDay) {
270 for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) {
272 $iSecond -= $lengthOfDay;
274 $dayTranslate = $langs->trans(
"Day");
275 if ($iSecond >= ($lengthOfDay * 2)) {
276 $dayTranslate = $langs->trans(
"Days");
280 if ($lengthOfWeek < 7) {
282 if ($sDay >= $lengthOfWeek) {
283 $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
284 $sDay %= $lengthOfWeek;
285 $weekTranslate = $langs->trans(
"DurationWeek");
287 $weekTranslate = $langs->trans(
"DurationWeeks");
289 $sTime .= $sWeek.
' '.$weekTranslate.
' ';
294 $dayTranslate = $langs->trans(
"Day");
296 $dayTranslate = $langs->trans(
"Days");
298 $sTime .= $sDay.
' '.$langs->trans(
"d").
' ';
301 if ($format ==
'all') {
302 if ($iSecond || empty($sDay)) {
305 } elseif ($format ==
'allhourminsec') {
306 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60))).
':'.sprintf(
"%02d", ((
int) ($iSecond % 60)));
307 } elseif ($format ==
'allhourmin') {
308 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60)));
309 } elseif ($format ==
'allhour') {
310 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600)));
312 } elseif ($format ==
'hour') {
314 } elseif ($format ==
'fullhour') {
315 if (!empty($iSecond)) {
321 } elseif ($format ==
'min') {
323 } elseif ($format ==
'sec') {
325 } elseif ($format ==
'month') {
327 } elseif ($format ==
'year') {
330 return trim((
string) $sTime);
345 if ($duration_unit ==
's') {
346 $result = $duration_value / 3600;
348 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
349 $result = $duration_value / 60;
351 if ($duration_unit ==
'h') {
352 $result = $duration_value;
354 if ($duration_unit ==
'd') {
355 $result = $duration_value * 24;
357 if ($duration_unit ==
'w') {
358 $result = $duration_value * 24 * 7;
360 if ($duration_unit ==
'm') {
361 $result = $duration_value * 730.484;
363 if ($duration_unit ==
'y') {
364 $result = $duration_value * 365 * 24;
385function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand = 0, $gm =
false)
390 $day_date = intval($day_date);
391 $month_date = intval($month_date);
392 $year_date = intval($year_date);
394 if ($month_date > 0) {
395 if ($month_date > 12) {
398 if ($year_date > 0 && empty($day_date)) {
399 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, $month_date, $gm));
400 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
401 } elseif ($year_date > 0 && !empty($day_date)) {
402 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm));
403 $sqldate .=
"' AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
406 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$datefield.
", '%c') = '".$db->escape((
string) $month_date).
"'";
408 } elseif ($year_date > 0) {
409 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, 1, $gm));
410 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, 12, $gm)).
"'";
438 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
439 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
442 $sday = (int) $reg[1];
443 $smonth = (int) $reg[2];
444 $syear = (int) $reg[3];
445 $shour = (int) $reg[4];
446 $smin = (int) $reg[5];
447 $ssec = (int) $reg[6];
451 if ($syear >= 50 && $syear < 100) {
454 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
455 } 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)
456 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
457 || 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)
459 $syear = (int) $reg[1];
460 $smonth = (int) $reg[2];
461 $sday = (int) $reg[3];
462 $shour = (int) $reg[4];
463 $smin = (int) $reg[5];
464 $ssec = (int) $reg[6];
465 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
468 $string = preg_replace(
'/([^0-9])/i',
'', $string);
469 $tmp = $string.
'000000';
473 } elseif (empty($gm) || $gm ===
'tzserver') {
477 $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);
493 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
494 $time -= 24 * 60 * 60;
496 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
509 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
510 $time += 24 * 60 * 60;
512 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
526 $prev_year = $year - 1;
528 $prev_month = $month - 1;
531 return array(
'year' => $prev_year,
'month' => $prev_month);
545 $next_year = $year + 1;
547 $next_month = $month + 1;
550 return array(
'year' => $next_year,
'month' => $next_month);
566 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
567 $time -= 24 * 60 * 60 * 7;
569 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
585 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
586 $time += 24 * 60 * 60 * 7;
589 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
608 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
635 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
636 $datelim -= (3600 * 24);
651 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
652 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
665 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
666 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
681 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
689 $days = $start_week - $tmparray[
'wday'];
694 $seconds = $days * 24 * 60 * 60;
698 $tmpdaytms = (int)
date((
string) $tmparray[
'0']) - $seconds;
699 $tmpday = idate(
"d", $tmpdaytms);
702 if ($tmpday > $day) {
703 $prev_month = $month - 1;
706 if ($prev_month == 0) {
708 $prev_year = $year - 1;
711 $prev_month = $month;
714 $tmpmonth = $prev_month;
715 $tmpyear = $prev_year;
718 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
719 $tmptime -= 24 * 60 * 60 * 7;
721 $prev_day = $tmparray[
'mday'];
724 if ($prev_day > $tmpday) {
725 $prev_month = $month - 1;
728 if ($prev_month == 0) {
730 $prev_year = $year - 1;
734 $week =
date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
736 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);
748 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
749 $days = easter_days($year);
750 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
751 return $tmp->getTimestamp();
770function num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
772 global $conf, $db,
$mysoc;
777 if (($timestampEnd - $timestampStart) % 86400 != 0) {
778 return 'Error Dates must use same hours and must be GMT dates';
781 if (empty($countryCodeOrId)) {
782 $countryCodeOrId =
$mysoc->country_code;
784 if ($includemonday < 0) {
785 $includemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
787 if ($includefriday < 0) {
788 $includefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
790 if ($includesaturday < 0) {
791 $includesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
793 if ($includesunday < 0) {
794 $includesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
797 if (is_numeric($countryCodeOrId)) {
798 $country_id = $countryCodeOrId;
800 $country_id =
dol_getIdFromCode($db, $countryCodeOrId,
'c_country',
'code',
'rowid');
803 if (empty($conf->cache[
'arrayOfActivePublicHolidays_'.$country_id])) {
805 $tmpArrayOfPublicHolidays = array();
806 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
807 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
808 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".$country_id : 0).
")";
809 $sql .=
" AND entity IN (0," .getEntity(
'holiday') .
")";
811 $resql = $db->query($sql);
813 $num_rows = $db->num_rows($resql);
815 while ($i < $num_rows) {
816 $obj = $db->fetch_object($resql);
817 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
822 return 'Error sql '.$db->lasterror();
826 $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id] = $tmpArrayOfPublicHolidays;
829 $arrayOfPublicHolidays = $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id];
832 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
835 $specialdayrule = array();
837 $jour = (int) gmdate(
"d", $timestampStart);
838 $mois = (int) gmdate(
"m", $timestampStart);
839 $annee = (int) gmdate(
"Y", $timestampStart);
840 $jour_semaine = (int) gmdate(
"w", $timestampStart);
843 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
844 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
845 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
848 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
851 if ($entrypublicholiday[
'month'] != $mois) {
854 if ($entrypublicholiday[
'day'] != $jour) {
870 if (in_array(
'easter', $specialdayrule)) {
873 $jour_paques = gmdate(
"d", $date_paques);
874 $mois_paques = gmdate(
"m", $date_paques);
875 if ($jour_paques == $jour && $mois_paques == $mois) {
881 if (in_array(
'eastermonday', $specialdayrule)) {
885 $date_lundi_paques = $date_paques + (3600 * 24);
886 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
887 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
888 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
896 if (in_array(
'goodfriday', $specialdayrule)) {
901 $date_good_friday = $easter - (2 * 3600 * 24);
902 $dom_good_friday = gmdate(
"d", $date_good_friday);
903 $month_good_friday = gmdate(
"m", $date_good_friday);
905 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
910 if (in_array(
'ascension', $specialdayrule)) {
913 $date_ascension = $date_paques + (3600 * 24 * 39);
914 $jour_ascension = gmdate(
"d", $date_ascension);
915 $mois_ascension = gmdate(
"m", $date_ascension);
916 if ($jour_ascension == $jour && $mois_ascension == $mois) {
922 if (in_array(
'pentecost', $specialdayrule)) {
925 $date_pentecote = $date_paques + (3600 * 24 * 49);
926 $jour_pentecote = gmdate(
"d", $date_pentecote);
927 $mois_pentecote = gmdate(
"m", $date_pentecote);
928 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
933 if (in_array(
'pentecotemonday', $specialdayrule)) {
936 $date_pentecote = $date_paques + (3600 * 24 * 50);
937 $jour_pentecote = gmdate(
"d", $date_pentecote);
938 $mois_pentecote = gmdate(
"m", $date_pentecote);
939 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
945 if (in_array(
'viernessanto', $specialdayrule)) {
948 $date_viernes = $date_paques - (3600 * 24 * 2);
949 $jour_viernes = gmdate(
"d", $date_viernes);
950 $mois_viernes = gmdate(
"m", $date_viernes);
951 if ($jour_viernes == $jour && $mois_viernes == $mois) {
957 if (in_array(
'fronleichnam', $specialdayrule)) {
960 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
961 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
962 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
963 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
969 if (in_array(
'genevafast', $specialdayrule)) {
971 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
972 $jour_1sunsept =
date(
"d", $date_1sunsept);
973 $mois_1sunsept =
date(
"m", $date_1sunsept);
974 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
984 if ($includefriday || $includesaturday || $includesunday || $includemonday) {
986 if ($includefriday && $jour_semaine == 5) {
989 if ($includesaturday && $jour_semaine == 6) {
992 if ($includesunday && $jour_semaine == 0) {
995 if ($includemonday && $jour_semaine == 1) {
1035function listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $excludesaturday = -1, $excludesunday = -1, $excludefriday = -1, $excludemonday = -1)
1037 global $conf, $db,
$mysoc;
1040 if (($timestampEnd - $timestampStart) % 86400 != 0) {
1041 return 'Error Dates must use same hours and must be GMT dates';
1044 if (empty($countryCodeOrId)) {
1045 $countryCodeOrId =
$mysoc->country_code;
1047 if ($excludemonday < 0) {
1048 $excludemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
1050 if ($excludefriday < 0) {
1051 $excludefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
1053 if ($excludesaturday < 0) {
1054 $excludesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1056 if ($excludesunday < 0) {
1057 $excludesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1060 if (is_numeric($countryCodeOrId)) {
1061 $country_id = $countryCodeOrId;
1063 $country_id =
dol_getIdFromCode($db, $countryCodeOrId,
'c_country',
'code',
'rowid');
1066 if (empty($conf->cache[
'arrayOfActivePublicHolidays_' . $country_id])) {
1068 $tmpArrayOfPublicHolidays = array();
1069 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
1070 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_hrm_public_holiday";
1071 $sql .=
" WHERE active = 1 and fk_country IN (0" . ($country_id > 0 ?
", " . $country_id : 0) .
")";
1072 $sql .=
" AND entity IN (0," .
getEntity(
'holiday') .
")";
1074 $resql = $db->query($sql);
1076 $num_rows = $db->num_rows($resql);
1078 while ($i < $num_rows) {
1079 $obj = $db->fetch_object($resql);
1080 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
1085 return 'Error sql ' . $db->lasterror();
1089 $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id] = $tmpArrayOfPublicHolidays;
1092 $arrayOfPublicHolidays = $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id];
1095 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
1097 $nonWorkingDay =
false;
1099 $specialdayrule = array();
1101 $jour = (int) gmdate(
"d", $timestampStart);
1102 $mois = (int) gmdate(
"m", $timestampStart);
1103 $annee = (int) gmdate(
"Y", $timestampStart);
1106 if ($excludefriday || $excludesaturday || $excludesunday) {
1107 $jour_julien = unixtojd($timestampStart);
1108 $jour_semaine = jddayofweek($jour_julien, 0);
1109 if ($excludefriday) {
1110 if ($jour_semaine == 5) {
1111 $nonWorkingDay =
true;
1114 if ($excludesaturday) {
1115 if ($jour_semaine == 6) {
1116 $nonWorkingDay =
true;
1119 if ($excludesunday) {
1120 if ($jour_semaine == 0) {
1121 $nonWorkingDay =
true;
1127 if (!$nonWorkingDay) {
1129 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
1130 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
1131 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
1134 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
1137 if ($entrypublicholiday[
'month'] != $mois) {
1140 if ($entrypublicholiday[
'day'] != $jour) {
1146 $listFeries[] = $timestampStart;
1156 if (!$nonWorkingDay && !$ferie) {
1158 if (in_array(
'easter', $specialdayrule)) {
1161 $jour_paques = gmdate(
"d", $date_paques);
1162 $mois_paques = gmdate(
"m", $date_paques);
1163 if ($jour_paques == $jour && $mois_paques == $mois) {
1165 $listFeries[] = $timestampStart;
1170 if (in_array(
'eastermonday', $specialdayrule)) {
1174 $date_lundi_paques = $date_paques + (3600 * 24);
1175 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
1176 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
1177 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
1179 $listFeries[] = $timestampStart;
1186 if (in_array(
'goodfriday', $specialdayrule)) {
1191 $date_good_friday = $easter - (2 * 3600 * 24);
1192 $dom_good_friday = gmdate(
"d", $date_good_friday);
1193 $month_good_friday = gmdate(
"m", $date_good_friday);
1195 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
1197 $listFeries[] = $timestampStart;
1201 if (in_array(
'ascension', $specialdayrule)) {
1204 $date_ascension = $date_paques + (3600 * 24 * 39);
1205 $jour_ascension = gmdate(
"d", $date_ascension);
1206 $mois_ascension = gmdate(
"m", $date_ascension);
1207 if ($jour_ascension == $jour && $mois_ascension == $mois) {
1209 $listFeries[] = $timestampStart;
1214 if (in_array(
'pentecost', $specialdayrule)) {
1217 $date_pentecote = $date_paques + (3600 * 24 * 49);
1218 $jour_pentecote = gmdate(
"d", $date_pentecote);
1219 $mois_pentecote = gmdate(
"m", $date_pentecote);
1220 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1222 $listFeries[] = $timestampStart;
1227 if (in_array(
'pentecotemonday', $specialdayrule)) {
1230 $date_pentecote = $date_paques + (3600 * 24 * 50);
1231 $jour_pentecote = gmdate(
"d", $date_pentecote);
1232 $mois_pentecote = gmdate(
"m", $date_pentecote);
1233 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1235 $listFeries[] = $timestampStart;
1240 if (in_array(
'viernessanto', $specialdayrule)) {
1243 $date_viernes = $date_paques - (3600 * 24 * 2);
1244 $jour_viernes = gmdate(
"d", $date_viernes);
1245 $mois_viernes = gmdate(
"m", $date_viernes);
1246 if ($jour_viernes == $jour && $mois_viernes == $mois) {
1248 $listFeries[] = $timestampStart;
1253 if (in_array(
'fronleichnam', $specialdayrule)) {
1256 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
1257 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
1258 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
1259 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
1261 $listFeries[] = $timestampStart;
1266 if (in_array(
'genevafast', $specialdayrule)) {
1268 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
1269 $jour_1sunsept =
date(
"d", $date_1sunsept);
1270 $mois_1sunsept =
date(
"m", $date_1sunsept);
1271 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
1273 $listFeries[] = $timestampStart;
1303 if ($timestampStart <= $timestampEnd) {
1304 if ($lastday == 1) {
1309 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
1329function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $countryCodeOrId =
'')
1333 if (empty($countryCodeOrId) || $countryCodeOrId < 0) {
1334 $countryCodeOrId =
$mysoc->country_code;
1337 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' countryCodeOrId='.$countryCodeOrId);
1340 if (!is_int($timestampStart) && !is_float($timestampStart)) {
1341 return 'ErrorBadParameter_num_open_day';
1343 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
1344 return 'ErrorBadParameter_num_open_day';
1347 if ($timestampStart < $timestampEnd) {
1352 $nbOpenDay = $a - $b;
1355 $halfday = (int) $halfday;
1360 $isStartDayWorking = (
num_public_holiday($timestampStart, $timestampStart, $countryCodeOrId, 1) == 0);
1362 $isEndDayWorking = (
num_public_holiday($timestampEnd, $timestampEnd, $countryCodeOrId, 1) == 0);
1365 if (($halfday == -1 || $halfday == 2) && $isStartDayWorking) {
1370 if (($halfday == 1 || $halfday == 2) &&
date(
'Y-m-d', $timestampStart) !=
date(
'Y-m-d', $timestampEnd) && $isEndDayWorking) {
1376 return $nbOpenDay * 24;
1380 } elseif ($timestampStart == $timestampEnd) {
1383 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId, $lastday);
1384 if ($numholidays == 1) {
1389 $nbOpenDay = $lastday;
1394 return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
1396 return $langs->trans(
"Error");
1412 $montharray = array(
1413 1 => $outputlangs->trans(
"Month01"),
1414 2 => $outputlangs->trans(
"Month02"),
1415 3 => $outputlangs->trans(
"Month03"),
1416 4 => $outputlangs->trans(
"Month04"),
1417 5 => $outputlangs->trans(
"Month05"),
1418 6 => $outputlangs->trans(
"Month06"),
1419 7 => $outputlangs->trans(
"Month07"),
1420 8 => $outputlangs->trans(
"Month08"),
1421 9 => $outputlangs->trans(
"Month09"),
1422 10 => $outputlangs->trans(
"Month10"),
1423 11 => $outputlangs->trans(
"Month11"),
1424 12 => $outputlangs->trans(
"Month12")
1427 if (!empty($short)) {
1428 $montharray = array(
1429 1 => $outputlangs->trans(
"MonthShort01"),
1430 2 => $outputlangs->trans(
"MonthShort02"),
1431 3 => $outputlangs->trans(
"MonthShort03"),
1432 4 => $outputlangs->trans(
"MonthShort04"),
1433 5 => $outputlangs->trans(
"MonthShort05"),
1434 6 => $outputlangs->trans(
"MonthShort06"),
1435 7 => $outputlangs->trans(
"MonthShort07"),
1436 8 => $outputlangs->trans(
"MonthShort08"),
1437 9 => $outputlangs->trans(
"MonthShort09"),
1438 10 => $outputlangs->trans(
"MonthShort10"),
1439 11 => $outputlangs->trans(
"MonthShort11"),
1440 12 => $outputlangs->trans(
"MonthShort12")
1456 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1458 for ($day = 1; $day < $nb_days; $day++) {
1460 $TWeek[$week_number] = $week_number;
1474 $TFirstDayOfWeek = array();
1475 foreach ($TWeek as $weekNb) {
1476 if (in_array(
'01', $TWeek) && in_array(
'52', $TWeek) && $weekNb ==
'01') {
1479 $TFirstDayOfWeek[$weekNb] =
date(
'd', strtotime($year.
'W'.$weekNb));
1481 return $TFirstDayOfWeek;
1493 $TLastDayOfWeek = array();
1494 foreach ($TWeek as $weekNb) {
1495 $TLastDayOfWeek[$weekNb] =
date(
'd', strtotime($year.
'W'.$weekNb.
'+6 days'));
1497 return $TLastDayOfWeek;
1510 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1511 $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.
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='')
Function to return number of working days (and text of units) between two dates (working days)
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_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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date