Created
October 18, 2019 10:12
-
-
Save PierreLebedel/f8019f8ecdd9daa697161b1837c649fc to your computer and use it in GitHub Desktop.
Calcul et affichage des jours fériés en France
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Jours fériés en France | |
* Source : https://phpsources.net/code/php/date-heure/641_jours-feries-en-france | |
*/ | |
class FrenchHolidays { | |
public static function isHoliday($day=false, $alsacemoselle=false){ | |
if(!$day) $day = date('Y-m-d'); | |
// Validation de la date | |
$dt = DateTime::createFromFormat('Y-m-d', $day); | |
if(!$dt || $dt->format('Y-m-d')!=$day){ | |
trigger_error('Date invalide', E_USER_WARNING); | |
return false; | |
} | |
$year = date("Y", strtotime($day)); | |
$days = self::getDays($year, $alsacemoselle); | |
if(in_array($day, $days)) return true; | |
return false; | |
} | |
public static function getDaysAndNames($year=false, $alsacemoselle=false){ | |
if(!$year) $year = date('Y'); | |
if(!is_numeric($year)){ | |
trigger_error('Année invalide', E_USER_WARNING); | |
return false; | |
} | |
// Etape 1 : religion (écrasé par les date laïques) | |
$days = array( | |
self::dimanchePaques($year) => "Pâques", | |
self::lundiPaques($year) => "Lundi de Pâques", | |
self::jeudiAscension($year) => "Jeudi de l'Ascension", | |
self::lundiPentecote($year) => "Lundi de Pentecôte", | |
$year.'-08-15' => "Assomption", | |
$year.'-11-01' => "La Toussaint", | |
$year.'-12-25' => "Noël", | |
); | |
// Etape 1 bis : dates religieuses supplémentaires Alsace-Moselle | |
if($alsacemoselle){ | |
$days = array_merge($days, array( | |
$year.'-12-26' => "Saint-Etienne", | |
self::vendrediSaint($year) => "Vendredi Saint" | |
)); | |
} | |
// Etape 2 : dates laïques | |
$days = array_merge($days, array( | |
$year.'-01-01' => "Jour de l'an", | |
$year.'-05-01' => "Fête du travail", | |
$year.'-05-08' => "Victoire des Alliés", | |
$year.'-07-14' => "Fête nationale", | |
$year.'-11-11' => "Armistice", | |
)); | |
ksort($days); | |
return $days; | |
} | |
public static function getDays($year=false, $alsacemoselle=false){ | |
$daysnames = self::getDaysAndNames($year, $alsacemoselle); | |
return (is_array($daysnames)) ? array_keys($daysnames) : false; | |
} | |
/////// | |
private static function dimanchePaques($year){ | |
return date("Y-m-d", easter_date($year)); | |
} | |
private static function vendrediSaint($year){ | |
$dimanche_paques = self::dimanchePaques($year); | |
return date("Y-m-d", strtotime("$dimanche_paques -2 days")); | |
} | |
private static function lundiPaques($year){ | |
$dimanche_paques = self::dimanchePaques($year); | |
return date("Y-m-d", strtotime("$dimanche_paques +1 day")); | |
} | |
private static function jeudiAscension($year){ | |
$dimanche_paques = self::dimanchePaques($year); | |
return date("Y-m-d", strtotime("$dimanche_paques +39 days")); | |
} | |
private static function lundiPentecote($year){ | |
$dimanche_paques = self::dimanchePaques($year); | |
return date("Y-m-d", strtotime("$dimanche_paques +50 days")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment