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));
130 if (empty($duration_value)) {
133 if ($duration_unit ==
's') {
134 return $time + (int) ($duration_value);
136 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
137 return $time + (int) (60 * $duration_value);
139 if ($duration_unit ==
'h') {
140 return $time + (int) (3600 * $duration_value);
142 if ($duration_unit ==
'w') {
143 return $time + (int) (3600 * 24 * 7 * $duration_value);
150 if ($duration_value > 0) {
151 $deltastring .= abs($duration_value);
154 if ($duration_value < 0) {
155 $deltastring .= abs($duration_value);
158 if ($duration_unit ==
'd') {
161 if ($duration_unit ==
'm') {
164 if ($duration_unit ==
'y') {
168 $date =
new DateTime();
170 $date->setTimezone(
new DateTimeZone(
'UTC'));
171 } elseif ($tz !==
'') {
172 $date->setTimezone(
new DateTimeZone($tz ==
'tzserver' ? date_default_timezone_get() : $tz));
173 } elseif (!function_exists(
'getDolGlobalString') || !
getDolGlobalString(
'MAIN_DATE_IN_MEMORY_ARE_NOT_GMT')) {
174 $date->setTimezone(
new DateTimeZone(
'UTC'));
178 $date->setTimestamp((
int) $time);
179 $interval =
new DateInterval($deltastring);
182 $date->sub($interval);
184 $date->add($interval);
188 if ($ruleforendofmonth == 1 && $duration_unit ==
'm' && $tz !==
'') {
190 $origin =
new DateTime(
'@'.((
int) $time));
191 $origin->setTimezone($date->getTimezone());
192 $monthsexpected = ((int) $origin->format(
'Y') * 12) + (
int) $origin->format(
'n') + (int) $duration_value;
193 if (((
int) $date->format(
'Y') * 12) + (
int) $date->format(
'n') != $monthsexpected) {
194 $date->modify(
'last day of previous month');
196 } elseif ($ruleforendofmonth == 1 && $duration_unit ==
'm') {
199 $timetotalmonths = (($timeyear * 12) + $timemonth);
201 $monthsexpected = ($timetotalmonths + $duration_value);
203 $newtime = $date->getTimestamp();
207 $newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
209 if ($monthsexpected < $newtimetotalmonths || $monthsexpected > $newtimetotalmonths) {
214 $datelim =
dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
215 $datelim -= (3600 * 24);
217 $date->setTimestamp($datelim);
220 return $date->getTimestamp();
235 $iResult = ((int) $iHours * 3600) + ((int) $iMinutes * 60) + (int) $iSeconds;
266 if (empty($lengthOfDay)) {
267 $lengthOfDay = 86400;
269 if (empty($lengthOfWeek)) {
272 $nbHbyDay = $lengthOfDay / 3600;
276 if ($format ==
'all' || $format ==
'allwithouthour' || $format ==
'allhour' || $format ==
'allhourmin' || $format ==
'allhourminsec') {
277 if ((
int) $iSecond === 0) {
284 if ($iSecond >= $lengthOfDay) {
285 for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) {
287 $iSecond -= $lengthOfDay;
289 $dayTranslate = $langs->trans(
"Day");
290 if ($iSecond >= ($lengthOfDay * 2)) {
291 $dayTranslate = $langs->trans(
"Days");
295 if ($lengthOfWeek < 7) {
297 if ($sDay >= $lengthOfWeek) {
298 $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
299 $sDay %= $lengthOfWeek;
300 $weekTranslate = $langs->trans(
"DurationWeek");
302 $weekTranslate = $langs->trans(
"DurationWeeks");
304 $sTime .= $sWeek.
' '.$weekTranslate.
' ';
309 $dayTranslate = $langs->trans(
"Day");
311 $dayTranslate = $langs->trans(
"Days");
313 $sTime .= $sDay.
' '.$langs->trans(
"d").
' ';
316 if ($format ==
'all') {
317 if ($iSecond || empty($sDay)) {
320 } elseif ($format ==
'allhourminsec') {
321 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60))).
':'.sprintf(
"%02d", ((
int) ($iSecond % 60)));
322 } elseif ($format ==
'allhourmin') {
323 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60)));
324 } elseif ($format ==
'allhour') {
325 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600)));
327 } elseif ($format ==
'hour') {
329 } elseif ($format ==
'fullhour') {
330 if (!empty($iSecond)) {
336 } elseif ($format ==
'min') {
338 } elseif ($format ==
'sec') {
340 } elseif ($format ==
'month') {
342 } elseif ($format ==
'year') {
345 return trim((
string) $sTime);
360 if ($duration_unit ==
's') {
361 $result = $duration_value / 3600;
363 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
364 $result = $duration_value / 60;
366 if ($duration_unit ==
'h') {
367 $result = $duration_value;
369 if ($duration_unit ==
'd') {
370 $result = $duration_value * 24;
372 if ($duration_unit ==
'w') {
373 $result = $duration_value * 24 * 7;
375 if ($duration_unit ==
'm') {
376 $result = $duration_value * 730.484;
378 if ($duration_unit ==
'y') {
379 $result = $duration_value * 365 * 24;
400function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand = 0, $gm =
false)
405 $day_date = intval($day_date);
406 $month_date = intval($month_date);
407 $year_date = intval($year_date);
409 if ($month_date > 0) {
410 if ($month_date > 12) {
413 if ($year_date > 0 && empty($day_date)) {
414 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, $month_date, $gm));
415 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
416 } elseif ($year_date > 0 && !empty($day_date)) {
417 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm));
418 $sqldate .=
"' AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
421 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$datefield.
", '%c') = '".$db->escape((
string) $month_date).
"'";
423 } elseif ($year_date > 0) {
424 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, 1, $gm));
425 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, 12, $gm)).
"'";
453 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
454 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
457 $sday = (int) $reg[1];
458 $smonth = (int) $reg[2];
459 $syear = (int) $reg[3];
460 $shour = (int) $reg[4];
461 $smin = (int) $reg[5];
462 $ssec = (int) $reg[6];
466 if ($syear >= 50 && $syear < 100) {
469 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
470 } 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)
471 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
472 || 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)
474 $syear = (int) $reg[1];
475 $smonth = (int) $reg[2];
476 $sday = (int) $reg[3];
477 $shour = (int) $reg[4];
478 $smin = (int) $reg[5];
479 $ssec = (int) $reg[6];
480 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
483 $string = preg_replace(
'/([^0-9])/i',
'', $string);
484 $tmp = $string.
'000000';
488 } elseif (empty($gm) || $gm ===
'tzserver') {
492 $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);
508 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
509 $time -= 24 * 60 * 60;
511 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
524 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
525 $time += 24 * 60 * 60;
527 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
541 $prev_year = $year - 1;
543 $prev_month = $month - 1;
546 return array(
'year' => $prev_year,
'month' => $prev_month);
560 $next_year = $year + 1;
562 $next_month = $month + 1;
565 return array(
'year' => $next_year,
'month' => $next_month);
581 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
582 $time -= 24 * 60 * 60 * 7;
584 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
600 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
601 $time += 24 * 60 * 60 * 7;
604 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
623 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
650 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
651 $datelim -= (3600 * 24);
666 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
667 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
680 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
681 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
696 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
704 $days = $start_week - $tmparray[
'wday'];
709 $seconds = $days * 24 * 60 * 60;
713 $tmpdaytms = (int)
date((
string) $tmparray[
'0']) - $seconds;
714 $tmpday = idate(
"d", $tmpdaytms);
717 if ($tmpday > $day) {
718 $prev_month = $month - 1;
721 if ($prev_month == 0) {
723 $prev_year = $year - 1;
726 $prev_month = $month;
729 $tmpmonth = $prev_month;
730 $tmpyear = $prev_year;
733 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
734 $tmptime -= 24 * 60 * 60 * 7;
736 $prev_day = $tmparray[
'mday'];
739 if ($prev_day > $tmpday) {
740 $prev_month = $month - 1;
743 if ($prev_month == 0) {
745 $prev_year = $year - 1;
749 $week =
date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
751 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);
763 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
764 $days = easter_days($year);
765 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
766 return $tmp->getTimestamp();
785function num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
787 global $conf, $db,
$mysoc;
792 if (($timestampEnd - $timestampStart) % 86400 != 0) {
793 return 'Error Dates must use same hours and must be GMT dates';
796 if (empty($countryCodeOrId)) {
797 $countryCodeOrId =
$mysoc->country_code;
799 if ($includemonday < 0) {
800 $includemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
802 if ($includefriday < 0) {
803 $includefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
805 if ($includesaturday < 0) {
806 $includesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
808 if ($includesunday < 0) {
809 $includesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
812 if (is_numeric($countryCodeOrId)) {
813 $country_id = $countryCodeOrId;
815 $country_id =
dol_getIdFromCode($db, $countryCodeOrId,
'c_country',
'code',
'rowid');
818 if (empty($conf->cache[
'arrayOfActivePublicHolidays_'.$country_id])) {
820 $tmpArrayOfPublicHolidays = array();
821 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
822 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
823 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".$country_id : 0).
")";
824 $sql .=
" AND entity IN (0," .getEntity(
'holiday') .
")";
826 $resql = $db->query($sql);
828 $num_rows = $db->num_rows($resql);
830 while ($i < $num_rows) {
831 $obj = $db->fetch_object($resql);
832 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
837 return 'Error sql '.$db->lasterror();
841 $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id] = $tmpArrayOfPublicHolidays;
844 $arrayOfPublicHolidays = $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id];
847 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
850 $specialdayrule = array();
852 $jour = (int) gmdate(
"d", $timestampStart);
853 $mois = (int) gmdate(
"m", $timestampStart);
854 $annee = (int) gmdate(
"Y", $timestampStart);
855 $jour_semaine = (int) gmdate(
"w", $timestampStart);
858 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
859 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
860 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
863 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
866 if ($entrypublicholiday[
'month'] != $mois) {
869 if ($entrypublicholiday[
'day'] != $jour) {
885 if (in_array(
'easter', $specialdayrule)) {
888 $jour_paques = gmdate(
"d", $date_paques);
889 $mois_paques = gmdate(
"m", $date_paques);
890 if ($jour_paques == $jour && $mois_paques == $mois) {
896 if (in_array(
'eastermonday', $specialdayrule)) {
900 $date_lundi_paques = $date_paques + (3600 * 24);
901 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
902 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
903 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
911 if (in_array(
'goodfriday', $specialdayrule)) {
916 $date_good_friday = $easter - (2 * 3600 * 24);
917 $dom_good_friday = gmdate(
"d", $date_good_friday);
918 $month_good_friday = gmdate(
"m", $date_good_friday);
920 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
925 if (in_array(
'ascension', $specialdayrule)) {
928 $date_ascension = $date_paques + (3600 * 24 * 39);
929 $jour_ascension = gmdate(
"d", $date_ascension);
930 $mois_ascension = gmdate(
"m", $date_ascension);
931 if ($jour_ascension == $jour && $mois_ascension == $mois) {
937 if (in_array(
'pentecost', $specialdayrule)) {
940 $date_pentecote = $date_paques + (3600 * 24 * 49);
941 $jour_pentecote = gmdate(
"d", $date_pentecote);
942 $mois_pentecote = gmdate(
"m", $date_pentecote);
943 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
948 if (in_array(
'pentecotemonday', $specialdayrule)) {
951 $date_pentecote = $date_paques + (3600 * 24 * 50);
952 $jour_pentecote = gmdate(
"d", $date_pentecote);
953 $mois_pentecote = gmdate(
"m", $date_pentecote);
954 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
960 if (in_array(
'viernessanto', $specialdayrule)) {
963 $date_viernes = $date_paques - (3600 * 24 * 2);
964 $jour_viernes = gmdate(
"d", $date_viernes);
965 $mois_viernes = gmdate(
"m", $date_viernes);
966 if ($jour_viernes == $jour && $mois_viernes == $mois) {
972 if (in_array(
'fronleichnam', $specialdayrule)) {
975 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
976 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
977 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
978 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
984 if (in_array(
'genevafast', $specialdayrule)) {
986 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
987 $jour_1sunsept =
date(
"d", $date_1sunsept);
988 $mois_1sunsept =
date(
"m", $date_1sunsept);
989 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
999 if ($includefriday || $includesaturday || $includesunday || $includemonday) {
1001 if ($includefriday && $jour_semaine == 5) {
1004 if ($includesaturday && $jour_semaine == 6) {
1007 if ($includesunday && $jour_semaine == 0) {
1010 if ($includemonday && $jour_semaine == 1) {
1027 $timestampStart += 86400;
1053function listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $excludesaturday = -1, $excludesunday = -1, $excludefriday = -1, $excludemonday = -1)
1055 global $conf, $db,
$mysoc;
1058 if (($timestampEnd - $timestampStart) % 86400 != 0) {
1059 return 'Error Dates must use same hours and must be GMT dates';
1062 if (empty($countryCodeOrId)) {
1063 $countryCodeOrId =
$mysoc->country_code;
1065 if ($excludemonday < 0) {
1066 $excludemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
1068 if ($excludefriday < 0) {
1069 $excludefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
1071 if ($excludesaturday < 0) {
1072 $excludesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1074 if ($excludesunday < 0) {
1075 $excludesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1078 if (is_numeric($countryCodeOrId)) {
1079 $country_id = $countryCodeOrId;
1081 $country_id =
dol_getIdFromCode($db, $countryCodeOrId,
'c_country',
'code',
'rowid');
1084 if (empty($conf->cache[
'arrayOfActivePublicHolidays_' . $country_id])) {
1086 $tmpArrayOfPublicHolidays = array();
1087 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
1088 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_hrm_public_holiday";
1089 $sql .=
" WHERE active = 1 and fk_country IN (0" . ($country_id > 0 ?
", " . $country_id : 0) .
")";
1090 $sql .=
" AND entity IN (0," .
getEntity(
'holiday') .
")";
1092 $resql = $db->query($sql);
1094 $num_rows = $db->num_rows($resql);
1096 while ($i < $num_rows) {
1097 $obj = $db->fetch_object($resql);
1098 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
1103 return 'Error sql ' . $db->lasterror();
1107 $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id] = $tmpArrayOfPublicHolidays;
1110 $arrayOfPublicHolidays = $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id];
1113 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
1115 $nonWorkingDay =
false;
1117 $specialdayrule = array();
1119 $jour = (int) gmdate(
"d", $timestampStart);
1120 $mois = (int) gmdate(
"m", $timestampStart);
1121 $annee = (int) gmdate(
"Y", $timestampStart);
1124 if ($excludefriday || $excludesaturday || $excludesunday) {
1125 $jour_julien = unixtojd($timestampStart);
1126 $jour_semaine = jddayofweek($jour_julien, 0);
1127 if ($excludefriday) {
1128 if ($jour_semaine == 5) {
1129 $nonWorkingDay =
true;
1132 if ($excludesaturday) {
1133 if ($jour_semaine == 6) {
1134 $nonWorkingDay =
true;
1137 if ($excludesunday) {
1138 if ($jour_semaine == 0) {
1139 $nonWorkingDay =
true;
1145 if (!$nonWorkingDay) {
1147 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
1148 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
1149 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
1152 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
1155 if ($entrypublicholiday[
'month'] != $mois) {
1158 if ($entrypublicholiday[
'day'] != $jour) {
1164 $listFeries[] = $timestampStart;
1174 if (!$nonWorkingDay && !$ferie) {
1176 if (in_array(
'easter', $specialdayrule)) {
1179 $jour_paques = gmdate(
"d", $date_paques);
1180 $mois_paques = gmdate(
"m", $date_paques);
1181 if ($jour_paques == $jour && $mois_paques == $mois) {
1183 $listFeries[] = $timestampStart;
1188 if (in_array(
'eastermonday', $specialdayrule)) {
1192 $date_lundi_paques = $date_paques + (3600 * 24);
1193 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
1194 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
1195 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
1197 $listFeries[] = $timestampStart;
1204 if (in_array(
'goodfriday', $specialdayrule)) {
1209 $date_good_friday = $easter - (2 * 3600 * 24);
1210 $dom_good_friday = gmdate(
"d", $date_good_friday);
1211 $month_good_friday = gmdate(
"m", $date_good_friday);
1213 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
1215 $listFeries[] = $timestampStart;
1219 if (in_array(
'ascension', $specialdayrule)) {
1222 $date_ascension = $date_paques + (3600 * 24 * 39);
1223 $jour_ascension = gmdate(
"d", $date_ascension);
1224 $mois_ascension = gmdate(
"m", $date_ascension);
1225 if ($jour_ascension == $jour && $mois_ascension == $mois) {
1227 $listFeries[] = $timestampStart;
1232 if (in_array(
'pentecost', $specialdayrule)) {
1235 $date_pentecote = $date_paques + (3600 * 24 * 49);
1236 $jour_pentecote = gmdate(
"d", $date_pentecote);
1237 $mois_pentecote = gmdate(
"m", $date_pentecote);
1238 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1240 $listFeries[] = $timestampStart;
1245 if (in_array(
'pentecotemonday', $specialdayrule)) {
1248 $date_pentecote = $date_paques + (3600 * 24 * 50);
1249 $jour_pentecote = gmdate(
"d", $date_pentecote);
1250 $mois_pentecote = gmdate(
"m", $date_pentecote);
1251 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1253 $listFeries[] = $timestampStart;
1258 if (in_array(
'viernessanto', $specialdayrule)) {
1261 $date_viernes = $date_paques - (3600 * 24 * 2);
1262 $jour_viernes = gmdate(
"d", $date_viernes);
1263 $mois_viernes = gmdate(
"m", $date_viernes);
1264 if ($jour_viernes == $jour && $mois_viernes == $mois) {
1266 $listFeries[] = $timestampStart;
1271 if (in_array(
'fronleichnam', $specialdayrule)) {
1274 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
1275 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
1276 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
1277 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
1279 $listFeries[] = $timestampStart;
1284 if (in_array(
'genevafast', $specialdayrule)) {
1286 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
1287 $jour_1sunsept =
date(
"d", $date_1sunsept);
1288 $mois_1sunsept =
date(
"m", $date_1sunsept);
1289 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
1291 $listFeries[] = $timestampStart;
1321 if ($timestampStart <= $timestampEnd) {
1322 if ($lastday == 1) {
1327 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
1347function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $countryCodeOrId =
'')
1351 if (empty($countryCodeOrId) || $countryCodeOrId < 0) {
1352 $countryCodeOrId =
$mysoc->country_code;
1355 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' countryCodeOrId='.$countryCodeOrId);
1358 if (!is_int($timestampStart) && !is_float($timestampStart)) {
1359 return 'ErrorBadParameter_num_open_day';
1361 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
1362 return 'ErrorBadParameter_num_open_day';
1365 if ($timestampStart < $timestampEnd) {
1370 $nbOpenDay = $a - $b;
1373 $halfday = (int) $halfday;
1378 $isStartDayWorking = (
num_public_holiday($timestampStart, $timestampStart, $countryCodeOrId, 1) == 0);
1380 $isEndDayWorking = (
num_public_holiday($timestampEnd, $timestampEnd, $countryCodeOrId, 1) == 0);
1383 if (($halfday == -1 || $halfday == 2) && $isStartDayWorking) {
1388 if (($halfday == 1 || $halfday == 2) &&
date(
'Y-m-d', $timestampStart) !=
date(
'Y-m-d', $timestampEnd) && $isEndDayWorking) {
1394 return $nbOpenDay * 24;
1398 } elseif ($timestampStart == $timestampEnd) {
1401 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId, $lastday);
1402 if ($numholidays == 1) {
1407 $nbOpenDay = $lastday;
1412 return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
1414 return $langs->trans(
"Error");
1430 $montharray = array(
1431 1 => $outputlangs->trans(
"Month01"),
1432 2 => $outputlangs->trans(
"Month02"),
1433 3 => $outputlangs->trans(
"Month03"),
1434 4 => $outputlangs->trans(
"Month04"),
1435 5 => $outputlangs->trans(
"Month05"),
1436 6 => $outputlangs->trans(
"Month06"),
1437 7 => $outputlangs->trans(
"Month07"),
1438 8 => $outputlangs->trans(
"Month08"),
1439 9 => $outputlangs->trans(
"Month09"),
1440 10 => $outputlangs->trans(
"Month10"),
1441 11 => $outputlangs->trans(
"Month11"),
1442 12 => $outputlangs->trans(
"Month12")
1445 if (!empty($short)) {
1446 $montharray = array(
1447 1 => $outputlangs->trans(
"MonthShort01"),
1448 2 => $outputlangs->trans(
"MonthShort02"),
1449 3 => $outputlangs->trans(
"MonthShort03"),
1450 4 => $outputlangs->trans(
"MonthShort04"),
1451 5 => $outputlangs->trans(
"MonthShort05"),
1452 6 => $outputlangs->trans(
"MonthShort06"),
1453 7 => $outputlangs->trans(
"MonthShort07"),
1454 8 => $outputlangs->trans(
"MonthShort08"),
1455 9 => $outputlangs->trans(
"MonthShort09"),
1456 10 => $outputlangs->trans(
"MonthShort10"),
1457 11 => $outputlangs->trans(
"MonthShort11"),
1458 12 => $outputlangs->trans(
"MonthShort12")
1474 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1476 for ($day = 1; $day <= $nb_days; $day++) {
1478 $TWeek[$week_number] = $week_number;
1492 $TFirstDayOfWeek = array();
1496 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1497 foreach ($TWeek as $weekNb) {
1499 if ($startwithweeksofpreviousyear) {
1500 if ((
int) $weekNb >= 52) {
1501 $yeartouse = $year - 1;
1503 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1504 $yeartouse = $year + 1;
1506 $TFirstDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb));
1508 return $TFirstDayOfWeek;
1520 $TLastDayOfWeek = array();
1522 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1523 foreach ($TWeek as $weekNb) {
1525 if ($startwithweeksofpreviousyear) {
1526 if ((
int) $weekNb >= 52) {
1527 $yeartouse = $year - 1;
1529 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1530 $yeartouse = $year + 1;
1532 $TLastDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb.
'+6 days'));
1534 return $TLastDayOfWeek;
1547 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1548 $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.
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_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.
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