What are some common pitfalls when using date functions in PHP for calculating flexible holidays like Easter?

One common pitfall when using date functions in PHP for calculating flexible holidays like Easter is not taking into account the different methods used to calculate the date of Easter (e.g., the Western vs. Orthodox Easter). To solve this issue, you can use a library or algorithm that accurately calculates the date of Easter based on the desired method.

function calculateEasterDate($year) {
    $a = $year % 19;
    $b = floor($year / 100);
    $c = $year % 100;
    $d = floor($b / 4);
    $e = $b % 4;
    $f = floor(($b + 8) / 25);
    $g = floor(($b - $f + 1) / 3);
    $h = (19 * $a + $b - $d - $g + 15) % 30;
    $i = floor($c / 4);
    $k = $c % 4;
    $l = (32 + 2 * $e + 2 * $i - $h - $k) % 7;
    $m = floor(($a + 11 * $h + 22 * $l) / 451);
    $month = floor(($h + $l - 7 * $m + 114) / 31);
    $day = (($h + $l - 7 * $m + 114) % 31) + 1;
    
    return mktime(0, 0, 0, $month, $day, $year);
}

$year = date('Y');
$easterDate = calculateEasterDate($year);
echo "Easter in " . $year . " falls on: " . date('F j, Y', $easterDate);