Merge pull request #17121 from 0x00FE/add-friday-holiday

NEW Add support for Friday as a holiday
This commit is contained in:
Laurent Destailleur 2021-04-10 15:30:57 +02:00 committed by GitHub
commit 8526ca5304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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 Friday, 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 $includesaturday Include saturday 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 $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 * @param int $includefriday Include friday 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, $includesaturday = -1, $includesunday = -1, $includefriday = -1)
{ {
global $db, $conf, $mysoc; global $db, $conf, $mysoc;
@ -685,12 +686,14 @@ 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 : 0);
}
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);
} }
if ($includesunday < 0) { if ($includesunday < 0) {
$includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1); $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
} }
$country_id = dol_getIdFromCode($db, $country_code, 'c_country', 'code', 'rowid'); $country_id = dol_getIdFromCode($db, $country_code, 'c_country', 'code', 'rowid');
@ -851,17 +854,22 @@ function num_public_holiday($timestampStart, $timestampEnd, $country_code = '',
} }
//print "ferie=".$ferie."\n"; //print "ferie=".$ferie."\n";
// If we have to include saturday and sunday // If we have to include Friday, 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;
} }