Add support for Friday as a holiday and some comment alignment fixes

This commit is contained in:
Ahmad Hadeed 2021-04-05 19:57:33 +03:00
parent 2da5d8838d
commit 235725b528

View File

@ -658,20 +658,21 @@ function getGMTEasterDatetime($year)
} }
/** /**
* Return the number of non working days including saturday and sunday (or not) between 2 dates in timestamp. * Return the number of non working days including saturday and sunday (or not) between 2 dates in timestamp.
* Dates must be UTC with hour, min, sec to 0. * Dates must be UTC with hour, min, sec to 0.
* Called by function num_open_day() * Called by function num_open_day()
* *
* @param int $timestampStart Timestamp start (UTC with hour, min, sec = 0) * @param int $timestampStart Timestamp start (UTC with hour, min, sec = 0)
* @param int $timestampEnd Timestamp end (UTC with hour, min, sec = 0) * @param int $timestampEnd Timestamp end (UTC with hour, min, sec = 0)
* @param string $country_code Country code * @param string $country_code Country code
* @param int $lastday Last day is included, 0: no, 1:yes * @param int $lastday Last day is included, 0: no, 1:yes
* @param int $includesaturday Include saturday as non working day (-1=use setup, 0=no, 1=yes) * @param int $includefriday Include friday as non working day (-1=use setup, 0=no, 1=yes)
* @param int $includesunday Include sunday as non working day (-1=use setup, 0=no, 1=yes) * @param int $includesaturday Include saturday as non working day (-1=use setup, 0=no, 1=yes)
* @return int|string Number of non working days or error message string if error * @param int $includesunday Include sunday as non working day (-1=use setup, 0=no, 1=yes)
* @return int|string Number of non working days or error message string if error
* @see num_between_day(), num_open_day() * @see num_between_day(), num_open_day()
*/ */
function num_public_holiday($timestampStart, $timestampEnd, $country_code = '', $lastday = 0, $includesaturday = -1, $includesunday = -1) function num_public_holiday($timestampStart, $timestampEnd, $country_code = '', $lastday = 0, $includefriday = -1, $includesaturday = -1, $includesunday = -1)
{ {
global $db, $conf, $mysoc; global $db, $conf, $mysoc;
@ -685,7 +686,9 @@ function num_public_holiday($timestampStart, $timestampEnd, $country_code = '',
if (empty($country_code)) { if (empty($country_code)) {
$country_code = $mysoc->country_code; $country_code = $mysoc->country_code;
} }
if ($includefriday < 0) {
$includefriday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY : 1);
}
if ($includesaturday < 0) { if ($includesaturday < 0) {
$includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1); $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
} }
@ -838,15 +841,20 @@ function num_public_holiday($timestampStart, $timestampEnd, $country_code = '',
// If we have to include saturday and sunday // If we have to include saturday and sunday
if (!$ferie) { if (!$ferie) {
if ($includesaturday || $includesunday) { if ($includefriday || $includesaturday || $includesunday) {
$jour_julien = unixtojd($timestampStart); $jour_julien = unixtojd($timestampStart);
$jour_semaine = jddayofweek($jour_julien, 0); $jour_semaine = jddayofweek($jour_julien, 0);
if ($includesaturday) { //Saturday (6) and Sunday (0) if ($includefriday) { //Friday (5), Saturday (6) and Sunday (0)
if ($jour_semaine == 5) {
$ferie = true;
}
}
if ($includesaturday) { //Friday (5), Saturday (6) and Sunday (0)
if ($jour_semaine == 6) { if ($jour_semaine == 6) {
$ferie = true; $ferie = true;
} }
} }
if ($includesunday) { //Saturday (6) and Sunday (0) if ($includesunday) { //Friday (5), Saturday (6) and Sunday (0)
if ($jour_semaine == 0) { if ($jour_semaine == 0) {
$ferie = true; $ferie = true;
} }