Skip to content

Instantly share code, notes, and snippets.

@samy
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samy/49fc81862c98e30fd503 to your computer and use it in GitHub Desktop.
Save samy/49fc81862c98e30fd503 to your computer and use it in GitHub Desktop.
Calcul jours ouvrés sans WE et JF
$PLV_JOURS_FERIES = array(
'01/01/2014', '21/04/2014', '01/05/2014', '08/05/2014', '29/05/2014', '09/06/2014', '14/07/2014', '15/08/2014', '01/11/2014', '11/11/2014', '25/12/2014',
'01/01/2015', '06/04/2015', '01/05/2015', '08/05/2015', '14/05/2015', '25/05/2015', '14/07/2015', '15/08/2015', '01/11/2015', '11/11/2015', '25/12/2015',
'01/01/2016', '28/03/2016', '01/05/2016', '08/05/2016', '16/05/2016', '14/07/2016', '15/08/2016', '01/11/2016', '11/11/2016', '25/12/2016',
'01/01/2017', '15/04/2017', '01/05/2017', '08/05/2017', '25/05/2017', '04/06/2017', '14/07/2017', '15/08/2017', '01/11/2017', '11/11/2017', '25/12/2017',
'01/01/2018', '02/04/2018', '01/05/2018', '08/05/2018', '10/05/2018', '21/05/2018', '14/07/2018', '15/08/2018', '01/11/2018', '11/11/2018', '25/12/2018',
);
public static function addOpenedDays(DateTime $date, $delay)
{
global $PLV_JOURS_FERIES;
/* Si on est un samedi, on rajoute un jour et on boucle */
if ((int)$date->format('w') == 6) {
$date->add(new DateInterval('P1D'));
return Product::addOpenedDays($date, $delay);
}
/* Si on est un dimanche, on rajoute un jour et on boucle */
if ((int)$date->format('w') == 0) {
$date->add(new DateInterval('P1D'));
return Product::addOpenedDays($date, $delay);
}
/* Si on est un jour férié, on rajoute un jour et on boucle */
if (in_array($date->format('d/m/Y'), $PLV_JOURS_FERIES)) {
$date->add(new DateInterval('P1D'));
return Product::addOpenedDays($date, $delay);
}
if ($delay <= 0)
$delay =0;
else {
$delay -= 1;
$date->add(new DateInterval('P1D'));
}
/* S'il ne reste plus de jour à ajouter, on sort de la boucle */
if (((int)$delay === 0) && ((int)$date->format('w') != 6) && ((int)$date->format('w') != 0) && (!in_array($date->format('d/m/Y'), $PLV_JOURS_FERIES)))
return $date;
else
/* Sinon on repasse une fois dans la boucle */
return Product::addOpenedDays($date, $delay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment