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);
394 $sql_datefield =
$db->sanitize($datefield);
396 if ($month_date > 0) {
397 if ($month_date > 12) {
400 if ($year_date > 0 && empty($day_date)) {
401 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".
$db->idate(
dol_get_first_day($year_date, $month_date, $gm)).
"'";
402 $sqldate .=
" AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
403 } elseif ($year_date > 0 && !empty($day_date)) {
404 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".
$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm)).
"'";
405 $sqldate .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
408 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$sql_datefield.
", '%c') = '".
$db->escape((
string) $month_date).
"'";
410 } elseif ($year_date > 0) {
411 $sqldate .= ($excludefirstand ?
"" :
" AND ").$sql_datefield.
" BETWEEN '".
$db->idate(
dol_get_first_day($year_date, 1, $gm)).
"'";
440 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
441 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
444 $sday = (int) $reg[1];
445 $smonth = (int) $reg[2];
446 $syear = (int) $reg[3];
447 $shour = (int) $reg[4];
448 $smin = (int) $reg[5];
449 $ssec = (int) $reg[6];
453 if ($syear >= 50 && $syear < 100) {
456 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
457 } 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)
458 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
459 || 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)
461 $syear = (int) $reg[1];
462 $smonth = (int) $reg[2];
463 $sday = (int) $reg[3];
464 $shour = (int) $reg[4];
465 $smin = (int) $reg[5];
466 $ssec = (int) $reg[6];
467 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
470 $string = preg_replace(
'/([^0-9])/i',
'', $string);
471 $tmp = $string.
'000000';
475 } elseif (empty($gm) || $gm ===
'tzserver') {
479 $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);
495 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
496 $time -= 24 * 60 * 60;
498 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
511 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
512 $time += 24 * 60 * 60;
514 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
528 $prev_year = $year - 1;
530 $prev_month = $month - 1;
533 return array(
'year' => $prev_year,
'month' => $prev_month);
547 $next_year = $year + 1;
549 $next_month = $month + 1;
552 return array(
'year' => $next_year,
'month' => $next_month);
568 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
569 $time -= 24 * 60 * 60 * 7;
571 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
587 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
588 $time += 24 * 60 * 60 * 7;
591 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
610 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
637 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
638 $datelim -= (3600 * 24);
653 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
654 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
667 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
668 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
683 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
691 $days = $start_week - $tmparray[
'wday'];
696 $seconds = $days * 24 * 60 * 60;
700 $tmpdaytms = (int)
date((
string) $tmparray[
'0']) - $seconds;
701 $tmpday = idate(
"d", $tmpdaytms);
704 if ($tmpday > $day) {
705 $prev_month = $month - 1;
708 if ($prev_month == 0) {
710 $prev_year = $year - 1;
713 $prev_month = $month;
716 $tmpmonth = $prev_month;
717 $tmpyear = $prev_year;
720 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
721 $tmptime -= 24 * 60 * 60 * 7;
723 $prev_day = $tmparray[
'mday'];
726 if ($prev_day > $tmpday) {
727 $prev_month = $month - 1;
730 if ($prev_month == 0) {
732 $prev_year = $year - 1;
736 $week =
date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
738 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);
750 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
751 $days = easter_days($year);
752 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
753 return $tmp->getTimestamp();
772function num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
779 if (($timestampEnd - $timestampStart) % 86400 != 0) {
780 return 'Error Dates must use same hours and must be GMT dates';
783 if (empty($countryCodeOrId)) {
784 $countryCodeOrId =
$mysoc->country_code;
786 if ($includemonday < 0) {
787 $includemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
789 if ($includefriday < 0) {
790 $includefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
792 if ($includesaturday < 0) {
793 $includesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
795 if ($includesunday < 0) {
796 $includesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
799 if (is_numeric($countryCodeOrId)) {
800 $country_id = $countryCodeOrId;
805 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id])) {
807 $tmpArrayOfPublicHolidays = array();
808 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
809 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
810 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".((int) $country_id) : 0).
")";
811 $sql .=
" AND entity IN (0," .getEntity(
'holiday') .
")";
813 $resql =
$db->query($sql);
815 $num_rows =
$db->num_rows($resql);
817 while ($i < $num_rows) {
818 $obj =
$db->fetch_object($resql);
819 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
824 return 'Error sql '.$db->lasterror();
828 $conf->cache[
'arrayOfActivePublicHolidays_'.$country_id] = $tmpArrayOfPublicHolidays;
831 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_'.$country_id];
834 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
837 $specialdayrule = array();
839 $jour = (int) gmdate(
"d", $timestampStart);
840 $mois = (int) gmdate(
"m", $timestampStart);
841 $annee = (int) gmdate(
"Y", $timestampStart);
842 $jour_semaine = (int) gmdate(
"w", $timestampStart);
845 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
846 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
847 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
850 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
853 if ($entrypublicholiday[
'month'] != $mois) {
856 if ($entrypublicholiday[
'day'] != $jour) {
872 if (in_array(
'easter', $specialdayrule)) {
875 $jour_paques = gmdate(
"d", $date_paques);
876 $mois_paques = gmdate(
"m", $date_paques);
877 if ($jour_paques == $jour && $mois_paques == $mois) {
883 if (in_array(
'eastermonday', $specialdayrule)) {
887 $date_lundi_paques = $date_paques + (3600 * 24);
888 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
889 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
890 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
898 if (in_array(
'goodfriday', $specialdayrule)) {
903 $date_good_friday = $easter - (2 * 3600 * 24);
904 $dom_good_friday = gmdate(
"d", $date_good_friday);
905 $month_good_friday = gmdate(
"m", $date_good_friday);
907 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
912 if (in_array(
'ascension', $specialdayrule)) {
915 $date_ascension = $date_paques + (3600 * 24 * 39);
916 $jour_ascension = gmdate(
"d", $date_ascension);
917 $mois_ascension = gmdate(
"m", $date_ascension);
918 if ($jour_ascension == $jour && $mois_ascension == $mois) {
924 if (in_array(
'pentecost', $specialdayrule)) {
927 $date_pentecote = $date_paques + (3600 * 24 * 49);
928 $jour_pentecote = gmdate(
"d", $date_pentecote);
929 $mois_pentecote = gmdate(
"m", $date_pentecote);
930 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
935 if (in_array(
'pentecotemonday', $specialdayrule)) {
938 $date_pentecote = $date_paques + (3600 * 24 * 50);
939 $jour_pentecote = gmdate(
"d", $date_pentecote);
940 $mois_pentecote = gmdate(
"m", $date_pentecote);
941 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
947 if (in_array(
'viernessanto', $specialdayrule)) {
950 $date_viernes = $date_paques - (3600 * 24 * 2);
951 $jour_viernes = gmdate(
"d", $date_viernes);
952 $mois_viernes = gmdate(
"m", $date_viernes);
953 if ($jour_viernes == $jour && $mois_viernes == $mois) {
959 if (in_array(
'fronleichnam', $specialdayrule)) {
962 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
963 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
964 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
965 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
971 if (in_array(
'genevafast', $specialdayrule)) {
973 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
974 $jour_1sunsept =
date(
"d", $date_1sunsept);
975 $mois_1sunsept =
date(
"m", $date_1sunsept);
976 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
986 if ($includefriday || $includesaturday || $includesunday || $includemonday) {
988 if ($includefriday && $jour_semaine == 5) {
991 if ($includesaturday && $jour_semaine == 6) {
994 if ($includesunday && $jour_semaine == 0) {
997 if ($includemonday && $jour_semaine == 1) {
1014 $timestampStart += 86400;
1040function listPublicHoliday($timestampStart, $timestampEnd, $countryCodeOrId =
'', $lastday = 0, $excludesaturday = -1, $excludesunday = -1, $excludefriday = -1, $excludemonday = -1)
1045 if (($timestampEnd - $timestampStart) % 86400 != 0) {
1046 return 'Error Dates must use same hours and must be GMT dates';
1049 if (empty($countryCodeOrId)) {
1050 $countryCodeOrId =
$mysoc->country_code;
1052 if ($excludemonday < 0) {
1053 $excludemonday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', 0);
1055 if ($excludefriday < 0) {
1056 $excludefriday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', 0);
1058 if ($excludesaturday < 0) {
1059 $excludesaturday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1061 if ($excludesunday < 0) {
1062 $excludesunday =
getDolGlobalInt(
'MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1065 if (is_numeric($countryCodeOrId)) {
1066 $country_id = $countryCodeOrId;
1071 if (empty(
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id])) {
1073 $tmpArrayOfPublicHolidays = array();
1074 $sql =
"SELECT id, code, entity, fk_country, dayrule, year, month, day, active";
1075 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_hrm_public_holiday";
1076 $sql .=
" WHERE active = 1 and fk_country IN (0" . ($country_id > 0 ?
", " . ((int) $country_id) : 0) .
")";
1077 $sql .=
" AND entity IN (0," .
getEntity(
'holiday') .
")";
1079 $resql =
$db->query($sql);
1081 $num_rows =
$db->num_rows($resql);
1083 while ($i < $num_rows) {
1084 $obj =
$db->fetch_object($resql);
1085 $tmpArrayOfPublicHolidays[$obj->id] = array(
'dayrule' => $obj->dayrule,
'year' => $obj->year,
'month' => $obj->month,
'day' => $obj->day);
1090 return 'Error sql ' .
$db->lasterror();
1094 $conf->cache[
'arrayOfActivePublicHolidays_' . $country_id] = $tmpArrayOfPublicHolidays;
1097 $arrayOfPublicHolidays =
$conf->cache[
'arrayOfActivePublicHolidays_' . $country_id];
1100 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
1102 $nonWorkingDay =
false;
1104 $specialdayrule = array();
1106 $jour = (int) gmdate(
"d", $timestampStart);
1107 $mois = (int) gmdate(
"m", $timestampStart);
1108 $annee = (int) gmdate(
"Y", $timestampStart);
1111 if ($excludefriday || $excludesaturday || $excludesunday) {
1112 $jour_julien = unixtojd($timestampStart);
1113 $jour_semaine = jddayofweek($jour_julien, 0);
1114 if ($excludefriday) {
1115 if ($jour_semaine == 5) {
1116 $nonWorkingDay =
true;
1119 if ($excludesaturday) {
1120 if ($jour_semaine == 6) {
1121 $nonWorkingDay =
true;
1124 if ($excludesunday) {
1125 if ($jour_semaine == 0) {
1126 $nonWorkingDay =
true;
1132 if (!$nonWorkingDay) {
1134 foreach ($arrayOfPublicHolidays as $entrypublicholiday) {
1135 if (!empty($entrypublicholiday[
'dayrule']) && $entrypublicholiday[
'dayrule'] !=
'date') {
1136 $specialdayrule[$entrypublicholiday[
'dayrule']] = $entrypublicholiday[
'dayrule'];
1139 if (!empty($entrypublicholiday[
'year']) && $entrypublicholiday[
'year'] != $annee) {
1142 if ($entrypublicholiday[
'month'] != $mois) {
1145 if ($entrypublicholiday[
'day'] != $jour) {
1151 $listFeries[] = $timestampStart;
1161 if (!$nonWorkingDay && !$ferie) {
1163 if (in_array(
'easter', $specialdayrule)) {
1166 $jour_paques = gmdate(
"d", $date_paques);
1167 $mois_paques = gmdate(
"m", $date_paques);
1168 if ($jour_paques == $jour && $mois_paques == $mois) {
1170 $listFeries[] = $timestampStart;
1175 if (in_array(
'eastermonday', $specialdayrule)) {
1179 $date_lundi_paques = $date_paques + (3600 * 24);
1180 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
1181 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
1182 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
1184 $listFeries[] = $timestampStart;
1191 if (in_array(
'goodfriday', $specialdayrule)) {
1196 $date_good_friday = $easter - (2 * 3600 * 24);
1197 $dom_good_friday = gmdate(
"d", $date_good_friday);
1198 $month_good_friday = gmdate(
"m", $date_good_friday);
1200 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
1202 $listFeries[] = $timestampStart;
1206 if (in_array(
'ascension', $specialdayrule)) {
1209 $date_ascension = $date_paques + (3600 * 24 * 39);
1210 $jour_ascension = gmdate(
"d", $date_ascension);
1211 $mois_ascension = gmdate(
"m", $date_ascension);
1212 if ($jour_ascension == $jour && $mois_ascension == $mois) {
1214 $listFeries[] = $timestampStart;
1219 if (in_array(
'pentecost', $specialdayrule)) {
1222 $date_pentecote = $date_paques + (3600 * 24 * 49);
1223 $jour_pentecote = gmdate(
"d", $date_pentecote);
1224 $mois_pentecote = gmdate(
"m", $date_pentecote);
1225 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
1227 $listFeries[] = $timestampStart;
1232 if (in_array(
'pentecotemonday', $specialdayrule)) {
1235 $date_pentecote = $date_paques + (3600 * 24 * 50);
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(
'viernessanto', $specialdayrule)) {
1248 $date_viernes = $date_paques - (3600 * 24 * 2);
1249 $jour_viernes = gmdate(
"d", $date_viernes);
1250 $mois_viernes = gmdate(
"m", $date_viernes);
1251 if ($jour_viernes == $jour && $mois_viernes == $mois) {
1253 $listFeries[] = $timestampStart;
1258 if (in_array(
'fronleichnam', $specialdayrule)) {
1261 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
1262 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
1263 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
1264 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
1266 $listFeries[] = $timestampStart;
1271 if (in_array(
'genevafast', $specialdayrule)) {
1273 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
1274 $jour_1sunsept =
date(
"d", $date_1sunsept);
1275 $mois_1sunsept =
date(
"m", $date_1sunsept);
1276 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) {
1278 $listFeries[] = $timestampStart;
1308 if ($timestampStart <= $timestampEnd) {
1309 if ($lastday == 1) {
1314 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
1338function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $countryCodeOrId =
'', $user_id = 0)
1340 global $langs,
$mysoc, $hookmanager;
1342 if (empty($countryCodeOrId) || $countryCodeOrId < 0) {
1343 $countryCodeOrId =
$mysoc->country_code;
1346 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' countryCodeOrId='.$countryCodeOrId);
1349 if (!is_int($timestampStart) && !is_float($timestampStart)) {
1350 return 'ErrorBadParameter_num_open_day';
1352 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
1353 return 'ErrorBadParameter_num_open_day';
1358 if ($timestampStart < $timestampEnd) {
1363 $nbOpenDay = $a - $b;
1366 $halfday = (int) $halfday;
1371 $isStartDayWorking = (
num_public_holiday($timestampStart, $timestampStart, $countryCodeOrId, 1) == 0);
1373 $isEndDayWorking = (
num_public_holiday($timestampEnd, $timestampEnd, $countryCodeOrId, 1) == 0);
1376 if (($halfday == -1 || $halfday == 2) && $isStartDayWorking) {
1381 if (($halfday == 1 || $halfday == 2) &&
date(
'Y-m-d', $timestampStart) !=
date(
'Y-m-d', $timestampEnd) && $isEndDayWorking) {
1384 } elseif ($timestampStart == $timestampEnd) {
1385 $isSingleDayHoliday =
false;
1387 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $countryCodeOrId, $lastday);
1388 if ($numholidays == 1) {
1389 $isSingleDayHoliday =
true;
1392 if (!$isSingleDayHoliday) {
1393 $nbOpenDay = $lastday - 0.5 * abs((
int) $halfday);
1396 return $langs->trans(
"Error");
1402 if ($user_id > 0 && is_object($hookmanager)) {
1403 $parameters = array(
1404 'timestampStart' => $timestampStart,
1405 'timestampEnd' => $timestampEnd,
1406 'inhour' => $inhour,
1407 'lastday' => $lastday,
1408 'halfday' => $halfday,
1409 'countryCodeOrId' => $countryCodeOrId,
1410 'user_id' => $user_id,
1411 'nbOpenDay' => $nbOpenDay,
1414 $reshook = $hookmanager->executeHooks(
'numOpenDay', $parameters, $hookmanager, $action);
1415 if ($reshook > 0 && isset($hookmanager->resArray[
'nbOpenDay'])) {
1416 $nbOpenDay = $hookmanager->resArray[
'nbOpenDay'];
1421 return (
int) ($nbOpenDay * 24);
1438 $montharray = array(
1439 1 => $outputlangs->trans(
"Month01"),
1440 2 => $outputlangs->trans(
"Month02"),
1441 3 => $outputlangs->trans(
"Month03"),
1442 4 => $outputlangs->trans(
"Month04"),
1443 5 => $outputlangs->trans(
"Month05"),
1444 6 => $outputlangs->trans(
"Month06"),
1445 7 => $outputlangs->trans(
"Month07"),
1446 8 => $outputlangs->trans(
"Month08"),
1447 9 => $outputlangs->trans(
"Month09"),
1448 10 => $outputlangs->trans(
"Month10"),
1449 11 => $outputlangs->trans(
"Month11"),
1450 12 => $outputlangs->trans(
"Month12")
1453 if (!empty($short)) {
1454 $montharray = array(
1455 1 => $outputlangs->trans(
"MonthShort01"),
1456 2 => $outputlangs->trans(
"MonthShort02"),
1457 3 => $outputlangs->trans(
"MonthShort03"),
1458 4 => $outputlangs->trans(
"MonthShort04"),
1459 5 => $outputlangs->trans(
"MonthShort05"),
1460 6 => $outputlangs->trans(
"MonthShort06"),
1461 7 => $outputlangs->trans(
"MonthShort07"),
1462 8 => $outputlangs->trans(
"MonthShort08"),
1463 9 => $outputlangs->trans(
"MonthShort09"),
1464 10 => $outputlangs->trans(
"MonthShort10"),
1465 11 => $outputlangs->trans(
"MonthShort11"),
1466 12 => $outputlangs->trans(
"MonthShort12")
1482 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1484 for ($day = 1; $day <= $nb_days; $day++) {
1486 $TWeek[$week_number] = $week_number;
1500 $TFirstDayOfWeek = array();
1504 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1505 foreach ($TWeek as $weekNb) {
1507 if ($startwithweeksofpreviousyear) {
1508 if ((
int) $weekNb >= 52) {
1509 $yeartouse = $year - 1;
1511 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1512 $yeartouse = $year + 1;
1514 $TFirstDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb));
1516 return $TFirstDayOfWeek;
1528 $TLastDayOfWeek = array();
1530 $startwithweeksofpreviousyear = ((int) reset($TWeek) >= 52 && in_array(
'01', $TWeek));
1531 foreach ($TWeek as $weekNb) {
1533 if ($startwithweeksofpreviousyear) {
1534 if ((
int) $weekNb >= 52) {
1535 $yeartouse = $year - 1;
1537 } elseif ($weekNb ==
'01' && in_array(
'52', $TWeek)) {
1538 $yeartouse = $year + 1;
1540 $TLastDayOfWeek[$weekNb] =
date(
'd', strtotime($yeartouse.
'W'.$weekNb.
'+6 days'));
1542 return $TLastDayOfWeek;
1555 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1556 $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