37 -11=>
"Pacific/Midway",
38 -10=>
"Pacific/Fakaofo",
39 -9=>
"America/Anchorage",
40 -8=>
"America/Los_Angeles",
41 -7=>
"America/Dawson_Creek",
42 -6=>
"America/Chicago",
44 -4=>
"America/Anguilla",
45 -3=>
"America/Araguaina",
46 -2=>
"America/Noronha",
47 -1=>
"Atlantic/Azores",
58 10=>
"Australia/Sydney",
60 12=>
"Pacific/Auckland",
61 13=>
"Pacific/Enderbury"
74 return @date_default_timezone_get();
85 if (method_exists(
'DateTimeZone',
'getOffset')) {
91 if ($refgmtdate ==
'now') {
92 $newrefgmtdate = $yearref.
'-'.$monthref.
'-'.$dayref;
93 } elseif ($refgmtdate ==
'summer') {
94 $newrefgmtdate = $yearref.
'-08-01';
96 $newrefgmtdate = $yearref.
'-01-01';
98 $newrefgmtdate .=
'T00:00:00+00:00';
100 $localdt =
new DateTime($newrefgmtdate, $localtz);
101 $tmp = -1 * $localtz->getOffset($localdt);
107 $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
125 if ($duration_unit ==
's') {
126 return $time + ($duration_value);
128 if ($duration_value == 0) {
131 if ($duration_unit ==
'i') {
132 return $time + (60 * $duration_value);
134 if ($duration_unit ==
'h') {
135 return $time + (3600 * $duration_value);
137 if ($duration_unit ==
'w') {
138 return $time + (3600 * 24 * 7 * $duration_value);
143 if ($duration_value > 0) {
144 $deltastring .= abs($duration_value);
147 if ($duration_value < 0) {
148 $deltastring .= abs($duration_value);
151 if ($duration_unit ==
'd') {
154 if ($duration_unit ==
'm') {
157 if ($duration_unit ==
'y') {
161 $date =
new DateTime();
162 if (!empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) {
163 $date->setTimezone(
new DateTimeZone(
'UTC'));
165 $date->setTimestamp($time);
166 $interval =
new DateInterval($deltastring);
169 $date->sub($interval);
171 $date->add($interval);
174 if ($ruleforendofmonth == 1 && $duration_unit ==
'm') {
177 $timetotalmonths = (($timeyear * 12) + $timemonth);
179 $monthsexpected = ($timetotalmonths + $duration_value);
181 $newtime = $date->getTimestamp();
185 $newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
187 if ($monthsexpected < $newtimetotalmonths) {
192 $datelim =
dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
193 $datelim -= (3600 * 24);
195 $date->setTimestamp($datelim);
198 return $date->getTimestamp();
213 $iResult = ((int) $iHours * 3600) + ((int) $iMinutes * 60) + (int) $iSeconds;
243 if (empty($lengthOfDay)) {
244 $lengthOfDay = 86400;
246 if (empty($lengthOfWeek)) {
249 $nbHbyDay = $lengthOfDay / 3600;
251 if ($format ==
'all' || $format ==
'allwithouthour' || $format ==
'allhour' || $format ==
'allhourmin' || $format ==
'allhourminsec') {
252 if ((
int) $iSecond === 0) {
260 if ($iSecond >= $lengthOfDay) {
261 for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) {
263 $iSecond -= $lengthOfDay;
265 $dayTranslate = $langs->trans(
"Day");
266 if ($iSecond >= ($lengthOfDay * 2)) {
267 $dayTranslate = $langs->trans(
"Days");
271 if ($lengthOfWeek < 7) {
273 if ($sDay >= $lengthOfWeek) {
274 $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
275 $sDay = $sDay % $lengthOfWeek;
276 $weekTranslate = $langs->trans(
"DurationWeek");
278 $weekTranslate = $langs->trans(
"DurationWeeks");
280 $sTime .= $sWeek.
' '.$weekTranslate.
' ';
285 $dayTranslate = $langs->trans(
"Day");
287 $dayTranslate = $langs->trans(
"Days");
289 $sTime .= $sDay.
' '.$langs->trans(
"d").
' ';
292 if ($format ==
'all') {
293 if ($iSecond || empty($sDay)) {
296 } elseif ($format ==
'allhourminsec') {
297 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond/3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60))).
':'.sprintf(
"%02d", ((
int) ($iSecond % 60)));
298 } elseif ($format ==
'allhourmin') {
299 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond/3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600)/60)));
300 } elseif ($format ==
'allhour') {
301 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * $nbHbyDay + $sDay * $nbHbyDay + (
int) floor($iSecond/3600)));
303 } elseif ($format ==
'hour') {
305 } elseif ($format ==
'fullhour') {
306 if (!empty($iSecond)) {
307 $iSecond = $iSecond / 3600;
312 } elseif ($format ==
'min') {
314 } elseif ($format ==
'sec') {
316 } elseif ($format ==
'month') {
318 } elseif ($format ==
'year') {
335 if ($duration_unit ==
's') $result = $duration_value / 3600;
336 if ($duration_unit ==
'i') $result = $duration_value / 60;
337 if ($duration_unit ==
'h') $result = $duration_value;
338 if ($duration_unit ==
'd') $result = $duration_value * 24;
339 if ($duration_unit ==
'w') $result = $duration_value * 24 * 7;
340 if ($duration_unit ==
'm') $result = $duration_value * 730.484;
341 if ($duration_unit ==
'y') $result = $duration_value * 365 * 24;
359 function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand = 0, $gm =
false)
364 $day_date = intval($day_date);
365 $month_date = intval($month_date);
366 $year_date = intval($year_date);
368 if ($month_date > 0) {
369 if ($month_date > 12) {
372 if ($year_date > 0 && empty($day_date)) {
373 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, $month_date, $gm));
374 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
375 } elseif ($year_date > 0 && !empty($day_date)) {
376 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm));
377 $sqldate .=
"' AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
380 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$datefield.
", '%c') = '".$db->escape($month_date).
"'";
382 } elseif ($year_date > 0) {
383 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, 1, $gm));
384 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, 12, $gm)).
"'";
412 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
413 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
425 if ($syear >= 50 && $syear < 100) {
428 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
429 } 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)
430 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
431 || 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)
439 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
442 $string = preg_replace(
'/([^0-9])/i',
'', $string);
443 $tmp = $string.
'000000';
447 } elseif (empty($gm) || $gm ===
'tzserver') {
451 $date =
dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), $gm);
466 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
467 $time -= 24 * 60 * 60;
469 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
482 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
483 $time += 24 * 60 * 60;
485 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
499 $prev_year = $year - 1;
501 $prev_month = $month - 1;
504 return array(
'year' => $prev_year,
'month' => $prev_month);
518 $next_year = $year + 1;
520 $next_month = $month + 1;
523 return array(
'year' => $next_year,
'month' => $next_month);
539 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
540 $time -= 24 * 60 * 60 * 7;
542 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
558 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
559 $time += 24 * 60 * 60 * 7;
562 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
581 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
608 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
609 $datelim -= (3600 * 24);
624 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
625 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
638 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
639 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
656 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
659 $start_week = (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1);
664 $days = $start_week - $tmparray[
'wday'];
669 $seconds = $days * 24 * 60 * 60;
673 $tmpdaytms = date($tmparray[0]) - $seconds;
674 $tmpday = date(
"d", $tmpdaytms);
677 if ($tmpday > $day) {
678 $prev_month = $month - 1;
681 if ($prev_month == 0) {
683 $prev_year = $year - 1;
686 $prev_month = $month;
689 $tmpmonth = $prev_month;
690 $tmpyear = $prev_year;
693 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
694 $tmptime -= 24 * 60 * 60 * 7;
696 $prev_day = $tmparray[
'mday'];
699 if ($prev_day > $tmpday) {
700 $prev_month = $month - 1;
703 if ($prev_month == 0) {
705 $prev_year = $year - 1;
709 $week = date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
711 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);
723 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
724 $days = easter_days($year);
725 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
726 return $tmp->getTimestamp();
745 function num_public_holiday($timestampStart, $timestampEnd, $country_code =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
747 global $db, $conf, $mysoc;
752 if ((($timestampEnd - $timestampStart) % 86400) != 0) {
753 return 'Error Dates must use same hours and must be GMT dates';
756 if (empty($country_code)) {
757 $country_code = $mysoc->country_code;
759 if ($includemonday < 0) {
760 $includemonday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY : 0);
762 if ($includefriday < 0) {
763 $includefriday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY : 0);
765 if ($includesaturday < 0) {
766 $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
768 if ($includesunday < 0) {
769 $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
772 $country_id =
dol_getIdFromCode($db, $country_code,
'c_country',
'code',
'rowid');
775 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
778 $specialdayrule = array();
780 $jour = gmdate(
"d", $timestampStart);
781 $mois = gmdate(
"m", $timestampStart);
782 $annee = gmdate(
"Y", $timestampStart);
788 $sql =
"SELECT code, entity, fk_country, dayrule, year, month, day, active";
789 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
790 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".$country_id : 0).
")";
792 $resql = $db->query(
$sql);
794 $num_rows = $db->num_rows($resql);
796 while ($i < $num_rows) {
797 $obj = $db->fetch_object($resql);
799 if (!empty($obj->dayrule) && $obj->dayrule !=
'date') {
800 $specialdayrule[$obj->dayrule] = $obj->dayrule;
803 if (!empty($obj->year) && $obj->year != $annee) {
806 if ($obj->month != $mois) {
809 if ($obj->day != $jour) {
822 return 'Error sql '.$db->lasterror();
829 if (in_array(
'easter', $specialdayrule)) {
832 $jour_paques = gmdate(
"d", $date_paques);
833 $mois_paques = gmdate(
"m", $date_paques);
834 if ($jour_paques == $jour && $mois_paques == $mois) {
840 if (in_array(
'eastermonday', $specialdayrule)) {
844 $date_lundi_paques = $date_paques + (3600 * 24);
845 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
846 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
847 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
855 if (in_array(
'goodfriday', $specialdayrule)) {
860 $date_good_friday = $easter - (2 * 3600 * 24);
861 $dom_good_friday = gmdate(
"d", $date_good_friday);
862 $month_good_friday = gmdate(
"m", $date_good_friday);
864 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
869 if (in_array(
'ascension', $specialdayrule)) {
872 $date_ascension = $date_paques + (3600 * 24 * 39);
873 $jour_ascension = gmdate(
"d", $date_ascension);
874 $mois_ascension = gmdate(
"m", $date_ascension);
875 if ($jour_ascension == $jour && $mois_ascension == $mois) {
881 if (in_array(
'pentecote', $specialdayrule)) {
884 $date_pentecote = $date_paques + (3600 * 24 * 49);
885 $jour_pentecote = gmdate(
"d", $date_pentecote);
886 $mois_pentecote = gmdate(
"m", $date_pentecote);
887 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
892 if (in_array(
'pentecotemonday', $specialdayrule)) {
895 $date_pentecote = $date_paques + (3600 * 24 * 50);
896 $jour_pentecote = gmdate(
"d", $date_pentecote);
897 $mois_pentecote = gmdate(
"m", $date_pentecote);
898 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
904 if (in_array(
'viernessanto', $specialdayrule)) {
907 $date_viernes = $date_paques - (3600 * 24 * 2);
908 $jour_viernes = gmdate(
"d", $date_viernes);
909 $mois_viernes = gmdate(
"m", $date_viernes);
910 if ($jour_viernes == $jour && $mois_viernes == $mois) {
916 if (in_array(
'fronleichnam', $specialdayrule)) {
919 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
920 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
921 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
922 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
928 if (in_array(
'genevafast', $specialdayrule)) {
930 $date_1sunsept = strtotime(
'next thursday', strtotime(
'next sunday', mktime(0, 0, 0, 9, 1, $annee)));
931 $jour_1sunsept = date(
"d", $date_1sunsept);
932 $mois_1sunsept = date(
"m", $date_1sunsept);
933 if ($jour_1sunsept == $jour && $mois_1sunsept == $mois) $ferie=
true;
941 if ($includefriday || $includesaturday || $includesunday) {
942 $jour_julien = unixtojd($timestampStart);
943 $jour_semaine = jddayofweek($jour_julien, 0);
944 if ($includefriday) {
945 if ($jour_semaine == 5) {
949 if ($includesaturday) {
950 if ($jour_semaine == 6) {
954 if ($includesunday) {
955 if ($jour_semaine == 0) {
991 if ($timestampStart < $timestampEnd) {
997 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
1015 function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $country_code =
'')
1017 global $langs, $mysoc;
1019 if (empty($country_code)) {
1020 $country_code = $mysoc->country_code;
1023 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' country_code='.$country_code);
1026 if (!is_int($timestampStart) && !is_float($timestampStart)) {
1027 return 'ErrorBadParameter_num_open_day';
1029 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
1030 return 'ErrorBadParameter_num_open_day';
1034 if ($timestampStart < $timestampEnd) {
1037 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
1038 $nbOpenDay = ($numdays - $numholidays);
1039 if ($inhour == 1 && $nbOpenDay <= 3) {
1040 $nbOpenDay = ($nbOpenDay * 24);
1042 return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
1043 } elseif ($timestampStart == $timestampEnd) {
1046 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
1047 if ($numholidays == 1) {
1052 $nbOpenDay = $lastday;
1055 $nbOpenDay = ($nbOpenDay * 24);
1057 return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
1059 return $langs->trans(
"Error");
1075 $montharray = array(
1076 1 => $outputlangs->trans(
"Month01"),
1077 2 => $outputlangs->trans(
"Month02"),
1078 3 => $outputlangs->trans(
"Month03"),
1079 4 => $outputlangs->trans(
"Month04"),
1080 5 => $outputlangs->trans(
"Month05"),
1081 6 => $outputlangs->trans(
"Month06"),
1082 7 => $outputlangs->trans(
"Month07"),
1083 8 => $outputlangs->trans(
"Month08"),
1084 9 => $outputlangs->trans(
"Month09"),
1085 10 => $outputlangs->trans(
"Month10"),
1086 11 => $outputlangs->trans(
"Month11"),
1087 12 => $outputlangs->trans(
"Month12")
1090 if (!empty($short)) {
1091 $montharray = array(
1092 1 => $outputlangs->trans(
"MonthShort01"),
1093 2 => $outputlangs->trans(
"MonthShort02"),
1094 3 => $outputlangs->trans(
"MonthShort03"),
1095 4 => $outputlangs->trans(
"MonthShort04"),
1096 5 => $outputlangs->trans(
"MonthShort05"),
1097 6 => $outputlangs->trans(
"MonthShort06"),
1098 7 => $outputlangs->trans(
"MonthShort07"),
1099 8 => $outputlangs->trans(
"MonthShort08"),
1100 9 => $outputlangs->trans(
"MonthShort09"),
1101 10 => $outputlangs->trans(
"MonthShort10"),
1102 11 => $outputlangs->trans(
"MonthShort11"),
1103 12 => $outputlangs->trans(
"MonthShort12")
1118 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1120 for ($day = 1; $day < $nb_days; $day++) {
1122 $TWeek[$week_number] = $week_number;
1135 $TFirstDayOfWeek = array();
1136 foreach ($TWeek as $weekNb) {
1137 if (in_array(
'01', $TWeek) && in_array(
'52', $TWeek) && $weekNb ==
'01') {
1140 $TFirstDayOfWeek[$weekNb] = date(
'd', strtotime($year.
'W'.$weekNb));
1142 return $TFirstDayOfWeek;
1153 $TLastDayOfWeek = array();
1154 foreach ($TWeek as $weekNb) {
1155 $TLastDayOfWeek[$weekNb] = date(
'd', strtotime($year.
'W'.$weekNb.
'+6 days'));
1157 return $TLastDayOfWeek;
1169 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1170 $week = $date->format(
"W");