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_value == 0) {
128 if ($duration_unit ==
'i') {
129 return $time + (60 * $duration_value);
131 if ($duration_unit ==
'h') {
132 return $time + (3600 * $duration_value);
134 if ($duration_unit ==
'w') {
135 return $time + (3600 * 24 * 7 * $duration_value);
140 if ($duration_value > 0) {
141 $deltastring .= abs($duration_value);
144 if ($duration_value < 0) {
145 $deltastring .= abs($duration_value);
148 if ($duration_unit ==
'd') {
151 if ($duration_unit ==
'm') {
154 if ($duration_unit ==
'y') {
158 $date =
new DateTime();
159 if (!empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) {
160 $date->setTimezone(
new DateTimeZone(
'UTC'));
162 $date->setTimestamp($time);
163 $interval =
new DateInterval($deltastring);
166 $date->sub($interval);
168 $date->add($interval);
171 if ($ruleforendofmonth == 1 && $duration_unit ==
'm') {
174 $timetotalmonths = (($timeyear * 12) + $timemonth);
176 $monthsexpected = ($timetotalmonths + $duration_value);
178 $newtime = $date->getTimestamp();
182 $newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
184 if ($monthsexpected < $newtimetotalmonths) {
189 $datelim =
dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
190 $datelim -= (3600 * 24);
192 $date->setTimestamp($datelim);
195 return $date->getTimestamp();
210 $iResult = ($iHours * 3600) + ($iMinutes * 60) + $iSeconds;
240 if (empty($lengthOfDay)) {
241 $lengthOfDay = 86400;
243 if (empty($lengthOfWeek)) {
247 if ($format ==
'all' || $format ==
'allwithouthour' || $format ==
'allhour' || $format ==
'allhourmin' || $format ==
'allhourminsec') {
248 if ((
int) $iSecond === 0) {
256 if ($iSecond >= $lengthOfDay) {
257 for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) {
259 $iSecond -= $lengthOfDay;
261 $dayTranslate = $langs->trans(
"Day");
262 if ($iSecond >= ($lengthOfDay * 2)) {
263 $dayTranslate = $langs->trans(
"Days");
267 if ($lengthOfWeek < 7) {
269 if ($sDay >= $lengthOfWeek) {
270 $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
271 $sDay = $sDay % $lengthOfWeek;
272 $weekTranslate = $langs->trans(
"DurationWeek");
274 $weekTranslate = $langs->trans(
"DurationWeeks");
276 $sTime .= $sWeek.
' '.$weekTranslate.
' ';
281 $dayTranslate = $langs->trans(
"Day");
283 $dayTranslate = $langs->trans(
"Days");
285 $sTime .= $sDay.
' '.strtolower(
dol_substr($dayTranslate, 0, 1)).
'. ';
288 if ($format ==
'all') {
289 if ($iSecond || empty($sDay)) {
292 } elseif ($format ==
'allhourminsec') {
293 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * 24 + $sDay * 24 + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60))).
':'.sprintf(
"%02d", ((
int) ($iSecond % 60)));
294 } elseif ($format ==
'allhourmin') {
295 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * 24 + $sDay * 24 + (
int) floor($iSecond / 3600))).
':'.sprintf(
"%02d", ((
int) floor(($iSecond % 3600) / 60)));
296 } elseif ($format ==
'allhour') {
297 return sprintf(
"%02d", ($sWeek * $lengthOfWeek * 24 + $sDay * 24 + (
int) floor($iSecond / 3600)));
299 } elseif ($format ==
'hour') {
301 } elseif ($format ==
'fullhour') {
302 if (!empty($iSecond)) {
303 $iSecond = $iSecond / 3600;
308 } elseif ($format ==
'min') {
310 } elseif ($format ==
'sec') {
312 } elseif ($format ==
'month') {
314 } elseif ($format ==
'year') {
334 function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand = 0, $gm =
false)
339 $day_date = intval($day_date);
340 $month_date = intval($month_date);
341 $year_date = intval($year_date);
343 if ($month_date > 0) {
344 if ($month_date > 12) {
347 if ($year_date > 0 && empty($day_date)) {
348 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, $month_date, $gm));
349 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, $month_date, $gm)).
"'";
350 } elseif ($year_date > 0 && !empty($day_date)) {
351 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month_date, $day_date, $year_date, $gm));
352 $sqldate .=
"' AND '".$db->idate(
dol_mktime(23, 59, 59, $month_date, $day_date, $year_date, $gm)).
"'";
355 $sqldate .= ($excludefirstand ?
"" :
" AND ").
" date_format( ".$datefield.
", '%c') = '".$db->escape($month_date).
"'";
357 } elseif ($year_date > 0) {
358 $sqldate .= ($excludefirstand ?
"" :
" AND ").$datefield.
" BETWEEN '".$db->idate(
dol_get_first_day($year_date, 1, $gm));
359 $sqldate .=
"' AND '".$db->idate(
dol_get_last_day($year_date, 12, $gm)).
"'";
387 if (preg_match(
'/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) {
388 dol_syslog(
"dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
400 if ($syear >= 50 && $syear < 100) {
403 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
404 } 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)
405 || preg_match(
'/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)
406 || 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)
414 $string = sprintf(
"%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
417 $string = preg_replace(
'/([^0-9])/i',
'', $string);
418 $tmp = $string.
'000000';
422 } elseif (empty($gm) || $gm ===
'tzserver') {
426 $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);
441 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
442 $time -= 24 * 60 * 60;
444 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
457 $time =
dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
458 $time += 24 * 60 * 60;
460 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
474 $prev_year = $year - 1;
476 $prev_month = $month - 1;
479 return array(
'year' => $prev_year,
'month' => $prev_month);
493 $next_year = $year + 1;
495 $next_month = $month + 1;
498 return array(
'year' => $next_year,
'month' => $next_month);
514 $time =
dol_mktime(12, 0, 0, $month, $tmparray[
'first_day'], $year, 1, 0);
515 $time -= 24 * 60 * 60 * 7;
517 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
533 $time =
dol_mktime(12, 0, 0, $tmparray[
'first_month'], $tmparray[
'first_day'], $tmparray[
'first_year'], 1, 0);
534 $time += 24 * 60 * 60 * 7;
537 return array(
'year' => $tmparray[
'year'],
'month' => $tmparray[
'mon'],
'day' => $tmparray[
'mday']);
556 return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
583 $datelim =
dol_mktime(23, 59, 59, $month, 1, $year, $gm);
584 $datelim -= (3600 * 24);
599 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
600 return dol_mktime(23, 59, 59, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
613 $tmparray =
dol_getdate($date,
false, ($gm ==
'gmt' ?
'gmt' :
''));
614 return dol_mktime(0, 0, 0, $tmparray[
'mon'], $tmparray[
'mday'], $tmparray[
'year'], $gm);
631 $date =
dol_mktime(0, 0, 0, $month, $day, $year, $gm);
634 $start_week = (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1);
639 $days = $start_week - $tmparray[
'wday'];
644 $seconds = $days * 24 * 60 * 60;
648 $tmpdaytms = date($tmparray[0]) - $seconds;
649 $tmpday = date(
"d", $tmpdaytms);
652 if ($tmpday > $day) {
653 $prev_month = $month - 1;
656 if ($prev_month == 0) {
658 $prev_year = $year - 1;
661 $prev_month = $month;
664 $tmpmonth = $prev_month;
665 $tmpyear = $prev_year;
668 $tmptime =
dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
669 $tmptime -= 24 * 60 * 60 * 7;
671 $prev_day = $tmparray[
'mday'];
674 if ($prev_day > $tmpday) {
675 $prev_month = $month - 1;
678 if ($prev_month == 0) {
680 $prev_year = $year - 1;
684 $week = date(
"W",
dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
686 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);
698 $base =
new DateTime(
"$year-03-21",
new DateTimeZone(
"UTC"));
699 $days = easter_days($year);
700 $tmp = $base->add(
new DateInterval(
"P{$days}D"));
701 return $tmp->getTimestamp();
720 function num_public_holiday($timestampStart, $timestampEnd, $country_code =
'', $lastday = 0, $includesaturday = -1, $includesunday = -1, $includefriday = -1, $includemonday = -1)
722 global $db, $conf, $mysoc;
727 if ((($timestampEnd - $timestampStart) % 86400) != 0) {
728 return 'Error Dates must use same hours and must be GMT dates';
731 if (empty($country_code)) {
732 $country_code = $mysoc->country_code;
734 if ($includemonday < 0) {
735 $includemonday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY : 0);
737 if ($includefriday < 0) {
738 $includefriday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY : 0);
740 if ($includesaturday < 0) {
741 $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
743 if ($includesunday < 0) {
744 $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
747 $country_id =
dol_getIdFromCode($db, $country_code,
'c_country',
'code',
'rowid');
750 while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
753 $specialdayrule = array();
755 $jour = gmdate(
"d", $timestampStart);
756 $mois = gmdate(
"m", $timestampStart);
757 $annee = gmdate(
"Y", $timestampStart);
763 $sql =
"SELECT code, entity, fk_country, dayrule, year, month, day, active";
764 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday";
765 $sql .=
" WHERE active = 1 and fk_country IN (0".($country_id > 0 ?
", ".$country_id : 0).
")";
767 $resql = $db->query($sql);
769 $num_rows = $db->num_rows(
$resql);
771 while ($i < $num_rows) {
772 $obj = $db->fetch_object(
$resql);
774 if (!empty($obj->dayrule) && $obj->dayrule !=
'date') {
775 $specialdayrule[$obj->dayrule] = $obj->dayrule;
778 if (!empty($obj->year) && $obj->year != $annee) {
781 if ($obj->month != $mois) {
784 if ($obj->day != $jour) {
797 return 'Error sql '.$db->lasterror();
804 if (in_array(
'easter', $specialdayrule)) {
807 $jour_paques = gmdate(
"d", $date_paques);
808 $mois_paques = gmdate(
"m", $date_paques);
809 if ($jour_paques == $jour && $mois_paques == $mois) {
815 if (in_array(
'eastermonday', $specialdayrule)) {
819 $date_lundi_paques = $date_paques + (3600 * 24);
820 $jour_lundi_paques = gmdate(
"d", $date_lundi_paques);
821 $mois_lundi_paques = gmdate(
"m", $date_lundi_paques);
822 if ($jour_lundi_paques == $jour && $mois_lundi_paques == $mois) {
830 if (in_array(
'goodfriday', $specialdayrule)) {
835 $date_good_friday = $easter - (2 * 3600 * 24);
836 $dom_good_friday = gmdate(
"d", $date_good_friday);
837 $month_good_friday = gmdate(
"m", $date_good_friday);
839 if ($dom_good_friday == $jour && $month_good_friday == $mois) {
844 if (in_array(
'ascension', $specialdayrule)) {
847 $date_ascension = $date_paques + (3600 * 24 * 39);
848 $jour_ascension = gmdate(
"d", $date_ascension);
849 $mois_ascension = gmdate(
"m", $date_ascension);
850 if ($jour_ascension == $jour && $mois_ascension == $mois) {
856 if (in_array(
'pentecote', $specialdayrule)) {
859 $date_pentecote = $date_paques + (3600 * 24 * 49);
860 $jour_pentecote = gmdate(
"d", $date_pentecote);
861 $mois_pentecote = gmdate(
"m", $date_pentecote);
862 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
867 if (in_array(
'pentecotemonday', $specialdayrule)) {
870 $date_pentecote = $date_paques + (3600 * 24 * 50);
871 $jour_pentecote = gmdate(
"d", $date_pentecote);
872 $mois_pentecote = gmdate(
"m", $date_pentecote);
873 if ($jour_pentecote == $jour && $mois_pentecote == $mois) {
879 if (in_array(
'viernessanto', $specialdayrule)) {
882 $date_viernes = $date_paques - (3600 * 24 * 2);
883 $jour_viernes = gmdate(
"d", $date_viernes);
884 $mois_viernes = gmdate(
"m", $date_viernes);
885 if ($jour_viernes == $jour && $mois_viernes == $mois) {
891 if (in_array(
'fronleichnam', $specialdayrule)) {
894 $date_fronleichnam = $date_paques + (3600 * 24 * 60);
895 $jour_fronleichnam = gmdate(
"d", $date_fronleichnam);
896 $mois_fronleichnam = gmdate(
"m", $date_fronleichnam);
897 if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) {
907 if ($includefriday || $includesaturday || $includesunday) {
908 $jour_julien = unixtojd($timestampStart);
909 $jour_semaine = jddayofweek($jour_julien, 0);
910 if ($includefriday) {
911 if ($jour_semaine == 5) {
915 if ($includesaturday) {
916 if ($jour_semaine == 6) {
920 if ($includesunday) {
921 if ($jour_semaine == 0) {
957 if ($timestampStart < $timestampEnd) {
963 $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
981 function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $country_code =
'')
983 global $langs, $mysoc;
985 if (empty($country_code)) {
986 $country_code = $mysoc->country_code;
989 dol_syslog(
'num_open_day timestampStart='.$timestampStart.
' timestampEnd='.$timestampEnd.
' bit='.$lastday.
' country_code='.$country_code);
992 if (!is_int($timestampStart) && !is_float($timestampStart)) {
993 return 'ErrorBadParameter_num_open_day';
995 if (!is_int($timestampEnd) && !is_float($timestampEnd)) {
996 return 'ErrorBadParameter_num_open_day';
1000 if ($timestampStart < $timestampEnd) {
1003 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
1004 $nbOpenDay = ($numdays - $numholidays);
1005 if ($inhour == 1 && $nbOpenDay <= 3) {
1006 $nbOpenDay = ($nbOpenDay * 24);
1008 return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
1009 } elseif ($timestampStart == $timestampEnd) {
1012 $numholidays =
num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
1013 if ($numholidays == 1) {
1018 $nbOpenDay = $lastday;
1021 $nbOpenDay = ($nbOpenDay * 24);
1023 return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
1025 return $langs->trans(
"Error");
1041 $montharray = array(
1042 1 => $outputlangs->trans(
"Month01"),
1043 2 => $outputlangs->trans(
"Month02"),
1044 3 => $outputlangs->trans(
"Month03"),
1045 4 => $outputlangs->trans(
"Month04"),
1046 5 => $outputlangs->trans(
"Month05"),
1047 6 => $outputlangs->trans(
"Month06"),
1048 7 => $outputlangs->trans(
"Month07"),
1049 8 => $outputlangs->trans(
"Month08"),
1050 9 => $outputlangs->trans(
"Month09"),
1051 10 => $outputlangs->trans(
"Month10"),
1052 11 => $outputlangs->trans(
"Month11"),
1053 12 => $outputlangs->trans(
"Month12")
1056 if (!empty($short)) {
1057 $montharray = array(
1058 1 => $outputlangs->trans(
"MonthShort01"),
1059 2 => $outputlangs->trans(
"MonthShort02"),
1060 3 => $outputlangs->trans(
"MonthShort03"),
1061 4 => $outputlangs->trans(
"MonthShort04"),
1062 5 => $outputlangs->trans(
"MonthShort05"),
1063 6 => $outputlangs->trans(
"MonthShort06"),
1064 7 => $outputlangs->trans(
"MonthShort07"),
1065 8 => $outputlangs->trans(
"MonthShort08"),
1066 9 => $outputlangs->trans(
"MonthShort09"),
1067 10 => $outputlangs->trans(
"MonthShort10"),
1068 11 => $outputlangs->trans(
"MonthShort11"),
1069 12 => $outputlangs->trans(
"MonthShort12")
1084 $nb_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
1086 for ($day = 1; $day < $nb_days; $day++) {
1088 $TWeek[$week_number] = $week_number;
1101 $TFirstDayOfWeek = array();
1102 foreach ($TWeek as $weekNb) {
1103 if (in_array(
'01', $TWeek) && in_array(
'52', $TWeek) && $weekNb ==
'01') {
1106 $TFirstDayOfWeek[$weekNb] = date(
'd', strtotime($year.
'W'.$weekNb));
1108 return $TFirstDayOfWeek;
1119 $TLastDayOfWeek = array();
1120 foreach ($TWeek as $weekNb) {
1121 $TLastDayOfWeek[$weekNb] = date(
'd', strtotime($year.
'W'.$weekNb.
'+6 days'));
1123 return $TLastDayOfWeek;
1135 $date =
new DateTime($year.
'-'.$month.
'-'.$day);
1136 $week = $date->format(
"W");