Skip to content

Instantly share code, notes, and snippets.

@spin0us
Created May 15, 2013
Embed
What would you like to do?
Check if date (english datetime or unix timestamp) is a french holiday
if(!function_exists('isFrenchHoliday'))
{
function isFrenchHoliday($str)
{
$ts = (preg_match('/^[0-9]{10}$/', $str)) ? $str : strtotime($str);
$date = date("md", $ts);
if($date == '0101') return true; // 1er janvier
if($date == '0501') return true; // 1er mai
if($date == '0508') return true; // 8 mai
if($date == '0714') return true; // 14 juillet
if($date == '0815') return true; // 15 aout
if($date == '1101') return true; // 1er novembre
if($date == '1111') return true; // 11 novembre
if($date == '1225') return true; // 25 decembre
// Fetes religieuses
$easter = easter_date(date("Y",$ts));
if($date == date("md", $easter)) return true; // Paques
if($date == date("md", $easter + 39 * 86400)) return true; // Ascension (paques + 39 jours)
if($date == date("md", $easter + 50 * 86400)) return true; // Pentecote (paques + 50 jours)
return false;
}
}
@herradiamine

This comment has been minimized.

Copy link

@herradiamine herradiamine commented Jul 13, 2020

Je propose l'amélioration suivante:

function isFrenchHoliday($str)
{
    $ts = preg_match('/^[0-9]{10}$/', $str) ? $str : strtotime($str);
    $date = date("md", $ts);
    $easter = new Carbon(date("Y-m-d", easter_date(date("Y",$ts))));
    $hollydays = [
        '0101', // 1er janvier
        '0501', // 1er mai
        '0508', // 8 mai
        '0714', // 14 juillet
        '0815', // 15 aout
        '1101', // 1er novembre
        '1111', // 11 novembre
        '1225', // 25 decembre
        date("md", strtotime($easter->copy()->addDays(1))), // Lundi de Paques
        date("md", strtotime($easter->copy()->addDays(39))), // Ascension (paques + 39 jours)
        date("md", strtotime($easter->copy()->addDays(50))), // Pentecote (paques + 50 jours)
    ];
    return in_array($date, $hollydays);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment