From 9a07e99fd211cb6198e1aeb28ac8d366ac67b5f5 Mon Sep 17 00:00:00 2001 From: Kyrian Obikwelu Date: Tue, 23 Jan 2024 12:30:28 +0100 Subject: [PATCH 1/2] Add Nigerian Holidays --- src/Countries/Nigeria.php | 45 +++++++++++++++++++ .../it_can_calculate_nigerian_holidays.snap | 34 ++++++++++++++ tests/Countries/NigeriaTest.php | 18 ++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/Countries/Nigeria.php create mode 100644 tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap create mode 100644 tests/Countries/NigeriaTest.php diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php new file mode 100644 index 000000000..e2a49ff1c --- /dev/null +++ b/src/Countries/Nigeria.php @@ -0,0 +1,45 @@ + '01-01', + 'Workers Day' => '05-01', + 'Democracy Day' => '06-12', + 'Independence Day' => '10-01', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + // Holidays like Eid al-Fitr and Eid al-Adha are based on the Islamic calendar + // which is determined by the sighting of the moon. This makes it impossible + // to calculate these holidays in advance. + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap new file mode 100644 index 000000000..d53c1b6b0 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Workers Day", + "date": "2024-05-01" + }, + { + "name": "Democracy Day", + "date": "2024-06-12" + }, + { + "name": "Independence Day", + "date": "2024-10-01" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/NigeriaTest.php b/tests/Countries/NigeriaTest.php new file mode 100644 index 000000000..6a1b83244 --- /dev/null +++ b/tests/Countries/NigeriaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 0d2f100eebd5f70bf53ee3c53b43e5afe163c229 Mon Sep 17 00:00:00 2001 From: Kyrian Obikwelu Date: Tue, 23 Jan 2024 12:36:22 +0100 Subject: [PATCH 2/2] Added historical data for democracy day --- src/Countries/Nigeria.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php index e2a49ff1c..2dd55081e 100644 --- a/src/Countries/Nigeria.php +++ b/src/Countries/Nigeria.php @@ -21,7 +21,6 @@ protected function allHolidays(int $year): array return array_merge([ 'New Year' => '01-01', 'Workers Day' => '05-01', - 'Democracy Day' => '06-12', 'Independence Day' => '10-01', 'Christmas Day' => '12-25', 'Boxing Day' => '12-26', @@ -33,11 +32,16 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); + $democracyDay = $year > 2018 + ? new CarbonImmutable("$year-06-12", 'Africa/Lagos') + : new CarbonImmutable("$year-05-29", 'Africa/Lagos'); + // Holidays like Eid al-Fitr and Eid al-Adha are based on the Islamic calendar // which is determined by the sighting of the moon. This makes it impossible // to calculate these holidays in advance. return [ + 'Democracy Day' => $democracyDay, 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), ];