From b0a84654a80c190776a4bf6cb6234b1bac00d468 Mon Sep 17 00:00:00 2001 From: Tor Lindgaard Date: Thu, 18 Jan 2024 22:24:58 +0100 Subject: [PATCH] Add Norway Holidays --- src/Countries/Norway.php | 43 ++++++++++++++++ .../it_can_calculate_norwegian_holidays.snap | 50 +++++++++++++++++++ tests/Countries/NorwayTest.php | 18 +++++++ 3 files changed, 111 insertions(+) create mode 100644 src/Countries/Norway.php create mode 100644 tests/.pest/snapshots/Countries/NorwayTest/it_can_calculate_norwegian_holidays.snap create mode 100644 tests/Countries/NorwayTest.php diff --git a/src/Countries/Norway.php b/src/Countries/Norway.php new file mode 100644 index 000000000..c4d09737b --- /dev/null +++ b/src/Countries/Norway.php @@ -0,0 +1,43 @@ + '01-01', + 'Arbeidernes dag' => '05-01', + 'Grunnlovsdag' => '05-17', + 'Første juledag' => '12-25', + 'Andre juledag' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Oslo'); + + $holidays = [ + 'Skjærtorsdag' => $easter->subDays(3), + 'Langfredag' => $easter->subDays(2), + 'Første påskedag' => $easter, + 'Andre påskedag,' => $easter->addDay(), + 'Kristi Himmelfartsdag' => $easter->addDays(39), + 'Første pinsedag' => $easter->addDays(49), + 'Andre pinsedag' => $easter->addDays(50), + ]; + + return $holidays; + } +} diff --git a/tests/.pest/snapshots/Countries/NorwayTest/it_can_calculate_norwegian_holidays.snap b/tests/.pest/snapshots/Countries/NorwayTest/it_can_calculate_norwegian_holidays.snap new file mode 100644 index 000000000..d9dd9570e --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorwayTest/it_can_calculate_norwegian_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "F\u00f8rste nytt\u00e5rsdag", + "date": "2024-01-01" + }, + { + "name": "Skj\u00e6rtorsdag", + "date": "2024-03-28" + }, + { + "name": "Langfredag", + "date": "2024-03-29" + }, + { + "name": "F\u00f8rste p\u00e5skedag", + "date": "2024-03-31" + }, + { + "name": "Andre p\u00e5skedag,", + "date": "2024-04-01" + }, + { + "name": "Arbeidernes dag", + "date": "2024-05-01" + }, + { + "name": "Kristi Himmelfartsdag", + "date": "2024-05-09" + }, + { + "name": "Grunnlovsdag", + "date": "2024-05-17" + }, + { + "name": "F\u00f8rste pinsedag", + "date": "2024-05-19" + }, + { + "name": "Andre pinsedag", + "date": "2024-05-20" + }, + { + "name": "F\u00f8rste juledag", + "date": "2024-12-25" + }, + { + "name": "Andre juledag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/NorwayTest.php b/tests/Countries/NorwayTest.php new file mode 100644 index 000000000..b9a342763 --- /dev/null +++ b/tests/Countries/NorwayTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +});