Class PHP de gestion des jours fériés en France
Cette class PHP permet de gérer l’affichage et le calcul des dates des jours fériés en France. Elle inclue les dates des fêtes religieuses ainsi que les dates fixes des événements laïques.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
<?php 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")); } } |
Source sur GitHub Gist : https://gist.github.com/PierreLebedel/f8019f8ecdd9daa697161b1837c649fc
Source originale : https://phpsources.net/code/php/date-heure/641_jours-feries-en-france