40 -11 =>
"Pacific/Pago_Pago",
41 -10 =>
"Pacific/Honolulu",
42 -9 =>
"America/Anchorage",
43 -8 =>
"America/Los_Angeles",
44 -7 =>
"America/Dawson_Creek",
45 -6 =>
"America/Chicago",
46 -5 =>
"America/Bogota",
47 -4 =>
"America/Asuncion",
48 -3 =>
"America/Araguaina",
49 -2 =>
"America/Noronha",
50 -1 =>
"Atlantic/Azores",
53 2 =>
"Europe/Helsinki",
59 8 =>
"Asia/Hong_Kong",
61 10 =>
"Australia/Sydney",
62 11 =>
"Pacific/Noumea",
63 12 =>
"Pacific/Auckland",
64 13 =>
"Pacific/Fakaofo",
65 14 =>
"Pacific/Kiritimati"
78 return @date_default_timezone_get();
89 if (method_exists(
'DateTimeZone',
'getOffset')) {
95 if ($refgmtdate ==
'now') {
96 $newrefgmtdate = $yearref.
'-'.$monthref.
'-'.$dayref;
97 } elseif ($refgmtdate ==
'summer') {
98 $newrefgmtdate = $yearref.
'-08-01';
100 $newrefgmtdate = $yearref.
'-01-01';
102 $newrefgmtdate .=
'T00:00:00+00:00';
104 $localdt =
new DateTime($newrefgmtdate, $localtz);
105 $tmp = -1 * $localtz->getOffset($localdt);
111 $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
128 if (empty($duration_value)) {
131 if ($duration_unit ==
's') {
132 return $time + (int) ($duration_value);
134 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
135 return $time + (int) (60 * $duration_value);
137 if ($duration_unit ==
'h') {
138 return $time + (int) (3600 * $duration_value);
140 if ($duration_unit ==
'w') {
141 return $time + (int) (3600 * 24 * 7 * $duration_value);
148 if ($duration_value > 0) {
149 $deltastring .= abs($duration_value);
152 if ($duration_value < 0) {
153 $deltastring .= abs($duration_value);
156 if ($duration_unit ==
'd') {
159 if ($duration_unit ==
'm') {
162 if ($duration_unit ==
'y') {
166 $date =
new DateTime();
167 if (!function_exists(
'getDolGlobalString') || !
getDolGlobalString(
'MAIN_DATE_IN_MEMORY_ARE_NOT_GMT')) {
168 $date->setTimezone(
new DateTimeZone(
'UTC'));
172 $date->setTimestamp((
int) $time);
173 $interval =
new DateInterval($deltastring);
176 $date->sub($interval);
178 $date->add($interval);
182 if ($ruleforendofmonth == 1 && $duration_unit ==
'm') {
185 $timetotalmonths = (($timeyear * 12) + $timemonth);
187 $monthsexpected = ($timetotalmonths + $duration_value);
189 $newtime = $date->getTimestamp();
193 $newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
195 if ($monthsexpected < $newtimetotalmonths || $monthsexpected > $newtimetotalmonths) {
200 $datelim =
dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
201 $datelim -= (3600 * 24);
203 $date->setTimestamp($datelim);
206 return $date->getTimestamp();
221 $iResult = ((int) $iHours * 3600) + ((int) $iMinutes * 60) + (int) $iSeconds;
252 if (empty($lengthOfDay)) {
253 $lengthOfDay = 86400;
255 if (empty($lengthOfWeek)) {
258 $nbHbyDay = $lengthOfDay / 3600;
262 if ($format ==
'all' || $format ==
'allwithouthour' || $format ==
'allhour' || $format ==
'allhourmin' || $format ==
'allhourminsec') {
263 if ((
int) $iSecond === 0) {
270 if ($iSecond >= $lengthOfDay) {
271 for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) {
273 $iSecond -= $lengthOfDay;
275 $dayTranslate = $langs->trans(
"Day");
276 if ($iSecond >= ($lengthOfDay * 2)) {
277 $dayTranslate = $langs->trans(
"Days");
281 if ($lengthOfWeek < 7) {
283 if ($sDay >= $lengthOfWeek) {
284 $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
285 $sDay %= $lengthOfWeek;
286 $weekTranslate = $langs->trans(
"DurationWeek");
288 $weekTranslate = $langs->trans(
"DurationWeeks");
290 $sTime .= $sWeek.
' '.$weekTranslate.
' ';
295 $dayTranslate = $langs->trans(
"Day");
297 $dayTranslate = $langs->trans(
"Days");
299 $sTime .= $sDay.
' '.$langs->trans(
"d").
' ';
302 if ($format ==
'all') {
303 if ($iSecond || empty($sDay)) {
306 } elseif ($format ==
'allhourminsec') {
307 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60))).
':'.sprintf(
"%02d", ((
int) ($iSecond % 60)));
308 } elseif ($format ==
'allhourmin') {
309 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60)));
310 } elseif ($format ==
'allhour') {
311 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond / 3600)));
313 } elseif ($format ==
'hour') {
315 } elseif ($format ==
'fullhour') {
316 if (!empty($iSecond)) {
322 } elseif ($format ==
'min') {
324 } elseif ($format ==
'sec') {
326 } elseif ($format ==
'month') {
328 } elseif ($format ==
'year') {
331 return trim((
string) $sTime);
346 if ($duration_unit ==
's') {
347 $result = $duration_value / 3600;
349 if ($duration_unit ==
'i' || $duration_unit ==
'mn' || $duration_unit ==
'min') {
350 $result = $duration_value / 60;
352 if ($duration_unit ==
'h') {
353 $result = $duration_value;
355 if ($duration_unit ==
'd') {
356 $result = $duration_value * 24;
358 if ($duration_unit ==
'w') {
359 $result = $duration_value * 24 * 7;
361 if ($duration_unit ==
'm') {
362 $result = $duration_value * 730.484;
364 if ($duration_unit ==
'y') {
365 $result = $duration_value * 365 * 24;
386function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand = 0, $gm =
false)
391 $day_date = intval($day_date);
392 $month_date = intval($month_date);
393 $year_date = intval($year_date);
395 if ($month_date > 0) {
396 if ($month_date > 12) {
399 if ($year_date > 0 && empty($day_date)) {
400 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".
$db->idate(
dol_get_first_day($year_date, $month_date, $gm));
401 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
402 } elseif ($year_date > 0 && !empty($day_date)) {
403 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".
$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm));
404 $sqldate .=
"' AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
407 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$datefield.
", '%c') = '".
$db->escape((
string) $month_date).
"'";
409 } elseif ($year_date > 0) {
410 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".
$db->idate(
dol_get_first_day($year_date, 1, $gm));
411 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, 12, $gm)).
"'";
439 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
440 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
443 $sday = (int) $reg[1];
444 $smonth = (int) $reg[2];
445 $syear = (int) $reg[3];
446 $shour = (int) $reg[4];
447 $smin = (int) $reg[5];
448 $ssec = (int) $reg[6];
452 if ($syear >= 50 && $syear < 100) {
455 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
456 } 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)
457 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
458 || 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)
460 $syear = (int) $reg[1];
461 $smonth = (int) $reg[2];
462 $sday = (int) $reg[3];
463 $shour = (int) $reg[4];
464 $smin = (int) $reg[5];
465 $ssec = (int) $reg[6];
466 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
469 $string = preg_replace(
'/([^0-9])/i',
'', $string);
470 $tmp = $string.
'000000';
474 } elseif (empty($gm) || $gm ===
'tzserver') {
478 $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);
494 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
495 $time -= 24 * 60 * 60;
497 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
510 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
511 $time += 24 * 60 * 60;
513 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
527 $prev_year = $year - 1;
529 $prev_month = $month - 1;
532 return array(
'year' => $prev_year,
'month' => $prev_month);
546 $next_year = $year + 1;
548 $next_month = $month + 1;
551 return array(
'year' => $next_year,
'month' => $next_month);
567 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
568 $time -= 24 * 60 * 60 * 7;
570 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
586 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
587 $time += 24 * 60 * 60 * 7;
590 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
609 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
636 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
637 $datelim -= (3600 * 24);
652 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
653 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
666 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
667 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
682 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
690 $days = $start_week - $tmparray[
'wday'];
695 $seconds = $days * 24 * 60 * 60;
699 $tmpdaytms = (int)
date((
string) $tmparray[
'0']) - $seconds;
700 $tmpday = idate(
"d", $tmpdaytms);
703 if ($tmpday > $day) {
704 $prev_month = $month - 1;
707 if ($prev_month == 0) {
709 $prev_year = $year - 1;
712 $prev_month = $month;
715 $tmpmonth = $prev_month;
716 $tmpyear = $prev_year;
719 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
720 $tmptime -= 24 * 60 * 60 * 7;
722 $prev_day = $tmparray[
'mday'];
725 if ($prev_day > $tmpday) {
726 $prev_month = $month - 1;
729 if ($prev_month == 0) {
731 $prev_year = $year - 1;
735 $week =
date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
737 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);
749 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
750 $days = easter_days($year);
751 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
752 return $tmp->getTimestamp();
771function num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
778 if (($timestampEnd - $timestampStart) % 86400 != 0) {
779 return 'Error Dates must use same hours and must be GMT dates';
782 if (empty($countryCodeOrId)) {
783 $countryCodeOrId =
$mysoc->country_code;
785 if ($includemonday < 0) {
786 $includemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
788 if ($includefriday < 0) {
789 $includefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
791 if ($includesaturday < 0) {
792 $includesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
794 if ($includesunday < 0) {
795 $includesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
798 if (is_numeric($countryCodeOrId)) {
799 $country_id = $countryCodeOrId;
804 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id])) {
806 $tmpArrayOfPublicHolidays = array();
807 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
808 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
809 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".$country_id : 0).
")";
810 $sql .=
" AND entity IN (0," .getEntity(
'holiday') .
")";
812 $resql =
$db->query($sql);
814 $num_rows =
$db->num_rows($resql);
816 while ($i < $num_rows) {
817 $obj =
$db->fetch_object($resql);
818 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
823 return 'Error sql '.$db->lasterror();
827 $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id] = $tmpArrayOfPublicHolidays;
830 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id];
833 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
836 $specialdayrule = array();
838 $jour = (int) gmdate(
"d", $timestampStart);
839 $mois = (int) gmdate(
"m", $timestampStart);
840 $annee = (int) gmdate(
"Y", $timestampStart);
841 $jour_semaine = (int) gmdate(
"w", $timestampStart);
844 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
845 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
846 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
849 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
852 if ($entrypublicholiday[
'month'] != $mois) {
855 if ($entrypublicholiday[
'day'] != $jour) {
871 if (in_array(
'easter', $specialdayrule)) {
874 $jour_paques = gmdate(
"d", $date_paques);
875 $mois_paques = gmdate(
"m", $date_paques);
876 if ($jour_paques == $jour && $mois_paques == $mois) {
882 if (in_array(
'eastermonday', $specialdayrule)) {
886 $date_lundi_paques = $date_paques + (3600 * 24);
887 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
888 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
889 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
897 if (in_array(
'goodfriday', $specialdayrule)) {
902 $date_good_friday = $easter - (2 * 3600 * 24);
903 $dom_good_friday = gmdate(
"d", $date_good_friday);
904 $month_good_friday = gmdate(
"m", $date_good_friday);
906 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
911 if (in_array(
'ascension', $specialdayrule)) {
914 $date_ascension = $date_paques + (3600 * 24 * 39);
915 $jour_ascension = gmdate(
"d", $date_ascension);
916 $mois_ascension = gmdate(
"m", $date_ascension);
917 if ($jour_ascension == $jour && $mois_ascension == $mois) {
923 if (in_array(
'pentecost', $specialdayrule)) {
926 $date_pentecote = $date_paques + (3600 * 24 * 49);
927 $jour_pentecote = gmdate(
"d", $date_pentecote);
928 $mois_pentecote = gmdate(
"m", $date_pentecote);
929 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
934 if (in_array(
'pentecotemonday', $specialdayrule)) {
937 $date_pentecote = $date_paques + (3600 * 24 * 50);
938 $jour_pentecote = gmdate(
"d", $date_pentecote);
939 $mois_pentecote = gmdate(
"m", $date_pentecote);
940 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
946 if (in_array(
'viernessanto', $specialdayrule)) {
949 $date_viernes = $date_paques - (3600 * 24 * 2);
950 $jour_viernes = gmdate(
"d", $date_viernes);
951 $mois_viernes = gmdate(
"m", $date_viernes);
952 if ($jour_viernes == $jour && $mois_viernes == $mois) {
958 if (in_array(
'fronleichnam', $specialdayrule)) {
961 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
962 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
963 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
964 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
970 if (in_array(
'genevafast', $specialdayrule)) {
972 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
973 $jour_1sunsept =
date(
"d", $date_1sunsept);
974 $mois_1sunsept =
date(
"m", $date_1sunsept);
975 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
985 if ($includefriday || $includesaturday || $includesunday || $includemonday) {
987 if ($includefriday && $jour_semaine == 5) {
990 if ($includesaturday && $jour_semaine == 6) {
993 if ($includesunday && $jour_semaine == 0) {
996 if ($includemonday && $jour_semaine == 1) {
1036function listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $excludesaturday = -1, $excludesunday = -1, $excludefriday = -1, $excludemonday = -1)
1041 if (($timestampEnd - $timestampStart) % 86400 != 0) {
1042 return 'Error Dates must use same hours and must be GMT dates';
1045 if (empty($countryCodeOrId)) {
1046 $countryCodeOrId =
$mysoc->country_code;
1048 if ($excludemonday < 0) {
1049 $excludemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
1051 if ($excludefriday < 0) {
1052 $excludefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
1054 if ($excludesaturday < 0) {
1055 $excludesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1057 if ($excludesunday < 0) {
1058 $excludesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1061 if (is_numeric($countryCodeOrId)) {
1062 $country_id = $countryCodeOrId;
1067 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id])) {
1069 $tmpArrayOfPublicHolidays = array();
1070 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
1071 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_hrm_public_holiday";
1072 $sql .=
" WHERE active = 1 and fk_country IN (0" . ($country_id > 0 ?
", " . $country_id : 0) .
")";
1073 $sql .=
" AND entity IN (0," .
getEntity(
'holiday') .
")";
1075 $resql =
$db->query($sql);
1077 $num_rows =
$db->num_rows($resql);
1079 while ($i < $num_rows) {
1080 $obj =
$db->fetch_object($resql);
1081 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
1086 return 'Error sql ' .
$db->lasterror();
1090 $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id] = $tmpArrayOfPublicHolidays;
1093 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id];
1096 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
1098 $nonWorkingDay =
false;
1100 $specialdayrule = array();
1102 $jour = (int) gmdate(
"d", $timestampStart);
1103 $mois = (int) gmdate(
"m", $timestampStart);
1104 $annee = (int) gmdate(
"Y", $timestampStart);
1107 if ($excludefriday || $excludesaturday || $excludesunday) {
1108 $jour_julien = unixtojd($timestampStart);
1109 $jour_semaine = jddayofweek($jour_julien, 0);
1110 if ($excludefriday) {
1111 if ($jour_semaine == 5) {
1112 $nonWorkingDay =
true;
1115 if ($excludesaturday) {
1116 if ($jour_semaine == 6) {
1117 $nonWorkingDay =
true;
1120 if ($excludesunday) {
1121 if ($jour_semaine == 0) {
1122 $nonWorkingDay =
true;
1128 if (!$nonWorkingDay) {
1130 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
1131 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
1132 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
1135 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
1138 if ($entrypublicholiday[
'month'] != $mois) {
1141 if ($entrypublicholiday[
'day'] != $jour) {
1147 $listFeries[] = $timestampStart;
1157 if (!$nonWorkingDay && !$ferie) {
1159 if (in_array(
'easter', $specialdayrule)) {
1162 $jour_paques = gmdate(
"d", $date_paques);
1163 $mois_paques = gmdate(
"m", $date_paques);
1164 if ($jour_paques == $jour && $mois_paques == $mois) {
1166 $listFeries[] = $timestampStart;
1171 if (in_array(
'eastermonday', $specialdayrule)) {
1175 $date_lundi_paques = $date_paques + (3600 * 24);
1176 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
1177 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
1178 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
1180 $listFeries[] = $timestampStart;
1187 if (in_array(
'goodfriday', $specialdayrule)) {
1192 $date_good_friday = $easter - (2 * 3600 * 24);
1193 $dom_good_friday = gmdate(
"d", $date_good_friday);
1194 $month_good_friday = gmdate(
"m", $date_good_friday);
1196 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
1198 $listFeries[] = $timestampStart;
1202 if (in_array(
'ascension', $specialdayrule)) {
1205 $date_ascension = $date_paques + (3600 * 24 * 39);
1206 $jour_ascension = gmdate(
"d", $date_ascension);
1207 $mois_ascension = gmdate(
"m", $date_ascension);
1208 if ($jour_ascension == $jour && $mois_ascension == $mois) {
1210 $listFeries[] = $timestampStart;
1215 if (in_array(
'pentecost', $specialdayrule)) {
1218 $date_pentecote = $date_paques + (3600 * 24 * 49);
1219 $jour_pentecote = gmdate(
"d", $date_pentecote);
1220 $mois_pentecote = gmdate(
"m", $date_pentecote);
1221 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1223 $listFeries[] = $timestampStart;
1228 if (in_array(
'pentecotemonday', $specialdayrule)) {
1231 $date_pentecote = $date_paques + (3600 * 24 * 50);
1232 $jour_pentecote = gmdate(
"d", $date_pentecote);
1233 $mois_pentecote = gmdate(
"m", $date_pentecote);
1234 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1236 $listFeries[] = $timestampStart;
1241 if (in_array(
'viernessanto', $specialdayrule)) {
1244 $date_viernes = $date_paques - (3600 * 24 * 2);
1245 $jour_viernes = gmdate(
"d", $date_viernes);
1246 $mois_viernes = gmdate(
"m", $date_viernes);
1247 if ($jour_viernes == $jour && $mois_viernes == $mois) {
1249 $listFeries[] = $timestampStart;
1254 if (in_array(
'fronleichnam', $specialdayrule)) {
1257 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
1258 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
1259 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
1260 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
1262 $listFeries[] = $timestampStart;
1267 if (in_array(
'genevafast', $specialdayrule)) {
1269 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
1270 $jour_1sunsept =
date(
"d", $date_1sunsept);
1271 $mois_1sunsept =
date(
"m", $date_1sunsept);
1272 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
1274 $listFeries[] = $timestampStart;
1304 if ($timestampStart <= $timestampEnd) {
1305 if ($lastday == 1) {
1310 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
1334function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $countryCodeOrId =
'', $user_id = 0)
1336 global $langs,
$mysoc, $hookmanager;
1338 if (empty($countryCodeOrId) || $countryCodeOrId < 0) {
1339 $countryCodeOrId =
$mysoc->country_code;
1342 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' countryCodeOrId='.$countryCodeOrId);
1345 if (!is_int($timestampStart) && !is_float($timestampStart)) {
1346 return 'ErrorBadParameter_num_open_day';
1348 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
1349 return 'ErrorBadParameter_num_open_day';
1354 if ($timestampStart < $timestampEnd) {
1359 $nbOpenDay = $a - $b;
1362 $halfday = (int) $halfday;
1367 $isStartDayWorking = (
num_public_holiday($timestampStart, $timestampStart, $countryCodeOrId, 1) == 0);
1369 $isEndDayWorking = (
num_public_holiday($timestampEnd, $timestampEnd, $countryCodeOrId, 1) == 0);
1372 if (($halfday == -1 || $halfday == 2) && $isStartDayWorking) {
1377 if (($halfday == 1 || $halfday == 2) &&
date(
'Y-m-d', $timestampStart) !=
date(
'Y-m-d', $timestampEnd) && $isEndDayWorking) {
1380 } elseif ($timestampStart == $timestampEnd) {
1381 $isSingleDayHoliday =
false;
1383 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId, $lastday);
1384 if ($numholidays == 1) {
1385 $isSingleDayHoliday =
true;
1388 if (!$isSingleDayHoliday) {
1389 $nbOpenDay = $lastday - 0.5 * abs((
int) $halfday);
1392 return $langs->trans(
"Error");
1398 if ($user_id > 0 && is_object($hookmanager)) {
1399 $parameters = array(
1400 'timestampStart' => $timestampStart,
1401 'timestampEnd' => $timestampEnd,
1402 'inhour' => $inhour,
1403 'lastday' => $lastday,
1404 'halfday' => $halfday,
1405 'countryCodeOrId' => $countryCodeOrId,
1406 'user_id' => $user_id,
1407 'nbOpenDay' => $nbOpenDay,
1410 $reshook = $hookmanager->executeHooks(
'numOpenDay', $parameters, $hookmanager, $action);
1411 if ($reshook > 0 && isset($hookmanager->resArray[
'nbOpenDay'])) {
1412 $nbOpenDay = $hookmanager->resArray[
'nbOpenDay'];
1417 return (
int) ($nbOpenDay * 24);
1434 $montharray = array(
1435 1 => $outputlangs->trans(
"Month01"),
1436 2 => $outputlangs->trans(
"Month02"),
1437 3 => $outputlangs->trans(
"Month03"),
1438 4 => $outputlangs->trans(
"Month04"),
1439 5 => $outputlangs->trans(
"Month05"),
1440 6 => $outputlangs->trans(
"Month06"),
1441 7 => $outputlangs->trans(
"Month07"),
1442 8 => $outputlangs->trans(
"Month08"),
1443 9 => $outputlangs->trans(
"Month09"),
1444 10 => $outputlangs->trans(
"Month10"),
1445 11 => $outputlangs->trans(
"Month11"),
1446 12 => $outputlangs->trans(
"Month12")
1449 if (!empty($short)) {
1450 $montharray = array(
1451 1 => $outputlangs->trans(
"MonthShort01"),
1452 2 => $outputlangs->trans(
"MonthShort02"),
1453 3 => $outputlangs->trans(
"MonthShort03"),
1454 4 => $outputlangs->trans(
"MonthShort04"),
1455 5 => $outputlangs->trans(
"MonthShort05"),
1456 6 => $outputlangs->trans(
"MonthShort06"),
1457 7 => $outputlangs->trans(
"MonthShort07"),
1458 8 => $outputlangs->trans(
"MonthShort08"),
1459 9 => $outputlangs->trans(
"MonthShort09"),
1460 10 => $outputlangs->trans(
"MonthShort10"),
1461 11 => $outputlangs->trans(
"MonthShort11"),
1462 12 => $outputlangs->trans(
"MonthShort12")
1478 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1480 for ($day = 1; $day < $nb_days; $day++) {
1482 $TWeek[$week_number] = $week_number;
1496 $TFirstDayOfWeek = array();
1497 foreach ($TWeek as $weekNb) {
1498 if (in_array(
'01', $TWeek) && in_array(
'52', $TWeek) && $weekNb ==
'01') {
1501 $TFirstDayOfWeek[$weekNb] =
date(
'd', strtotime($year.
'W'.$weekNb));
1503 return $TFirstDayOfWeek;
1515 $TLastDayOfWeek = array();
1516 foreach ($TWeek as $weekNb) {
1517 $TLastDayOfWeek[$weekNb] =
date(
'd', strtotime($year.
'W'.$weekNb.
'+6 days'));
1519 return $TLastDayOfWeek;
1532 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1533 $week = $date->format(
"W");
dol_get_prev_month($month, $year)
Return previous month.
listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId='', $lastday=0, $excludesaturday=-1, $excludesunday=-1, $excludefriday=-1, $excludemonday=-1)
Return the list of public holidays including Friday, Saturday and Sunday (or not) between 2 dates in ...
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_next_day($day, $month, $year)
Return next day.
dol_get_next_week($day, $week, $month, $year)
Return next week.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
getServerTimeZoneString()
Return server timezone string.
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
getLastDayOfEachWeek($TWeek, $year)
Return array of last day of weeks.
getWeekNumbersOfMonth($month, $year)
Return array of week numbers.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
getGMTEasterDatetime($year)
Return the easter day in GMT time.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='', $user_id=0)
Function to return number of working days (and text of units) between two dates (working days)
convertDurationtoHour($duration_value, $duration_unit)
Convert duration to hour.
get_tz_array()
Return an array with timezone values.
dol_get_prev_day($day, $month, $year)
Return previous day.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
getFirstDayOfEachWeek($TWeek, $year)
Return array of first day of weeks.
dol_get_next_month($month, $year)
Return next month.
getWeekNumber($day, $month, $year)
Return week number.
num_between_day($timestampStart, $timestampEnd, $lastday=0)
Function to return number of days between two dates (date must be UTC date !) Example: 2012-01-01 201...
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId='', $lastday=0, $includesaturday=-1, $includesunday=-1, $includefriday=-1, $includemonday=-1)
Return the number of non working days including Friday, Saturday and Sunday (or not) between 2 dates ...
convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
Convert hours and minutes into seconds.
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_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.
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