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.

<?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