PHP snippet: Norwegian holidays

Robert AndresenProgramming Leave a Comment

Here is a little function to find Norwegian holidays in PHP.

The holidays are returned in array with Unix timestamp as key and name of the day as value.

function norwegian_red_days($year)
{
	$red_days = array(); // Declare array

	// Movable days (easter)
	$easter_timestamp = easter_date($year); // Find easter as refrence for movable days

	$red_days[strtotime("-7 days", $easter_timestamp)] = "Palmesøndag";
	$red_days[strtotime("-3 days", $easter_timestamp)] = "Skjærtorsdag";
	$red_days[strtotime("-2 days", $easter_timestamp)] = "Langfredag";
	$red_days[strtotime("0 days", $easter_timestamp)] = "1. påskedag";
	$red_days[strtotime("+1 days", $easter_timestamp)] = "2. påskedag";
	$red_days[strtotime("+39 days", $easter_timestamp)] = "Kristi Himmelfartsdag";
	$red_days[strtotime("+49 days", $easter_timestamp)] = "1. Pinsedag";
	$red_days[strtotime("+50 days", $easter_timestamp)] = "2. Pinsedag";
	
	// Static red days
	$red_days[strtotime("01.01." . $year)] = "1. nyttårsdag";
	$red_days[strtotime("01.05." . $year)] = "Offentlig høytidsdag";
	$red_days[strtotime("17.05." . $year)] = "Grunnlovsdag";
	$red_days[strtotime("25.12." . $year)] = "1. juledag";
	$red_days[strtotime("26.12." . $year)] = "2. juledag";
	
	return $red_days;
}