From f2d03f916ee3278bcbc94dbba543c6de78a9bc9e Mon Sep 17 00:00:00 2001 From: Peter Sowah Date: Thu, 25 Jan 2024 00:41:41 +0000 Subject: [PATCH] add Ghana holidays --- src/Countries/Ghana.php | 39 +++++++++++++++++ ...te_Ghana_date_based_regional_holidays.snap | 42 ++++++++++++++++++ ...te_Ghana_easter_based_region_holidays.snap | 42 ++++++++++++++++++ .../it_can_calculate_Ghana_holidays.snap | 42 ++++++++++++++++++ tests/Countries/GhanaTest.php | 43 +++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 src/Countries/Ghana.php create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap create mode 100644 tests/Countries/GhanaTest.php diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php new file mode 100644 index 000000000..edc3117eb --- /dev/null +++ b/src/Countries/Ghana.php @@ -0,0 +1,39 @@ + '01-01', + 'Constitution Day' => '01-07', + 'Independence Day' => '03-06', + 'May Day' => '05-01', + 'Founder\'s Day' => '08-04', + 'Kwame Nkrumah Memorial Day' => '09-21', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Accra'); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "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/GhanaTest.php b/tests/Countries/GhanaTest.php new file mode 100644 index 000000000..78f05a44b --- /dev/null +++ b/tests/Countries/GhanaTest.php @@ -0,0 +1,43 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate Ghana easter based region holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gh')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate Ghana date based regional holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gh')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +});