From be0d90f7acf59aec3d9e1c4fbff3d25876cb9340 Mon Sep 17 00:00:00 2001 From: Joshua Paul Date: Wed, 17 Jan 2024 15:34:01 +0100 Subject: [PATCH 1/5] Added support for holidays in Nigeria --- src/Countries/Nigeria.php | 39 +++++++++++++++++++ .../it_can_calculate_austrian_holidays.snap | 38 ++++++++++++++++++ tests/Countries/NigeriaTest.php | 18 +++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/Countries/Nigeria.php create mode 100644 tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_austrian_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..7de01dce0 --- /dev/null +++ b/src/Countries/Nigeria.php @@ -0,0 +1,39 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'New Year\'s Day' => "01-01", + 'Worker\'s Day' => "05-01", + 'Children\'s Day' => "05-27", + '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 = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Lagos'); + + return [ + 'Good Friday' => $easter->subDay(2), + 'Easter Monday' => $easter->addDay(1), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_austrian_holidays.snap b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_austrian_holidays.snap new file mode 100644 index 000000000..cd3cc13bb --- /dev/null +++ b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_austrian_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Worker's Day", + "date": "2024-05-01" + }, + { + "name": "Children's Day", + "date": "2024-05-27" + }, + { + "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..99eff5a11 --- /dev/null +++ b/tests/Countries/NigeriaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 27760158dafffae8c68383fc645096bb4165834c Mon Sep 17 00:00:00 2001 From: Joshua Paul Date: Wed, 17 Jan 2024 15:40:15 +0100 Subject: [PATCH 2/5] fix name of the test case --- ...an_holidays.snap => it_can_calculate_nigerian_holidays.snap} | 0 tests/Countries/NigeriaTest.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/.pest/snapshots/Countries/NigeriaTest/{it_can_calculate_austrian_holidays.snap => it_can_calculate_nigerian_holidays.snap} (100%) diff --git a/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_austrian_holidays.snap b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap similarity index 100% rename from tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_austrian_holidays.snap rename to tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap diff --git a/tests/Countries/NigeriaTest.php b/tests/Countries/NigeriaTest.php index 99eff5a11..8fdb2a32a 100644 --- a/tests/Countries/NigeriaTest.php +++ b/tests/Countries/NigeriaTest.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate austrian holidays', function () { +it('can calculate nigerian holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); $holidays = Holidays::for(country: 'ng')->get(); From a6c84ca8da7007b8d6cc6cd743eee64326a605c9 Mon Sep 17 00:00:00 2001 From: Joshua Paul Date: Wed, 17 Jan 2024 15:45:52 +0100 Subject: [PATCH 3/5] remove children's day from list of official holiday --- src/Countries/Nigeria.php | 1 - .../NigeriaTest/it_can_calculate_nigerian_holidays.snap | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php index 7de01dce0..8730d9336 100644 --- a/src/Countries/Nigeria.php +++ b/src/Countries/Nigeria.php @@ -17,7 +17,6 @@ protected function allHolidays(int $year): array return array_merge([ 'New Year\'s Day' => "01-01", 'Worker\'s Day' => "05-01", - 'Children\'s Day' => "05-27", 'Democracy Day' => "06-12", 'Independence Day' => "10-01", 'Christmas Day' => "12-25", 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 index cd3cc13bb..ee5d39b48 100644 --- a/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap +++ b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap @@ -15,10 +15,6 @@ "name": "Worker's Day", "date": "2024-05-01" }, - { - "name": "Children's Day", - "date": "2024-05-27" - }, { "name": "Democracy Day", "date": "2024-06-12" From d816bd96dff0c9369906058845a9a4f758e97ea3 Mon Sep 17 00:00:00 2001 From: Joshua Paul Date: Thu, 18 Jan 2024 12:35:13 +0100 Subject: [PATCH 4/5] fix code styling issues --- src/Countries/Nigeria.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php index 8730d9336..d476195f6 100644 --- a/src/Countries/Nigeria.php +++ b/src/Countries/Nigeria.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'ng'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -31,8 +30,8 @@ protected function variableHolidays(int $year): array ->setTimezone('Africa/Lagos'); return [ - 'Good Friday' => $easter->subDay(2), - 'Easter Monday' => $easter->addDay(1), + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), ]; } } From 1a97ba52d80f420161328dae8435fa8ac5a9a3bb Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:29:14 +0100 Subject: [PATCH 5/5] Update src/Countries/Nigeria.php --- src/Countries/Nigeria.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php index d476195f6..21ead05d6 100644 --- a/src/Countries/Nigeria.php +++ b/src/Countries/Nigeria.php @@ -26,8 +26,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Africa/Lagos'); + $easter = $this->easter($year); return [ 'Good Friday' => $easter->subDays(2),