Y-m-d date => holiday key, in date order. */ public static function forYear(int $year): array { $easter = self::easterSunday($year); $midsummerEve = new DateTimeImmutable(sprintf('%04d-06-19', $year)); while ($midsummerEve->format('N') !== '5') { $midsummerEve = $midsummerEve->add(new DateInterval('P1D')); } $holidays = [ sprintf('%04d-01-01', $year) => 'new_years_day', sprintf('%04d-01-06', $year) => 'epiphany', $easter->sub(new DateInterval('P2D'))->format('Y-m-d') => 'good_friday', $easter->add(new DateInterval('P1D'))->format('Y-m-d') => 'easter_monday', sprintf('%04d-05-01', $year) => 'may_day', $easter->add(new DateInterval('P39D'))->format('Y-m-d') => 'ascension_day', $midsummerEve->format('Y-m-d') => 'midsummer_eve', sprintf('%04d-12-06', $year) => 'independence_day', sprintf('%04d-12-24', $year) => 'christmas_eve', sprintf('%04d-12-25', $year) => 'christmas_day', sprintf('%04d-12-26', $year) => 'st_stephens_day', ]; ksort($holidays); return $holidays; } /** * Easter Sunday by the anonymous Gregorian algorithm (Meeus/Jones/Butcher). */ public static function easterSunday(int $year): DateTimeImmutable { $a = $year % 19; $b = intdiv($year, 100); $c = $year % 100; $d = intdiv($b, 4); $e = $b % 4; $f = intdiv($b + 8, 25); $g = intdiv($b - $f + 1, 3); $h = (19 * $a + $b - $d - $g + 15) % 30; $i = intdiv($c, 4); $k = $c % 4; $l = (32 + 2 * $e + 2 * $i - $h - $k) % 7; $m = intdiv($a + 11 * $h + 22 * $l, 451); $month = intdiv($h + $l - 7 * $m + 114, 31); $day = (($h + $l - 7 * $m + 114) % 31) + 1; return new DateTimeImmutable(sprintf('%04d-%02d-%02d', $year, $month, $day)); } }