diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 03342516c..505677c36 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -11,18 +11,81 @@ public function countryCode(): string return 'gh'; } + /** + * Return carbon date for christmas + * + * @return CarbonImmutable + */ + protected function getChristmasDay(int $year) + { + return new CarbonImmutable($year . '-12-25'); + } + + /** @return CarbonImmutable */ + protected function christmasDay(int $year): CarbonImmutable + { + $christmasDay = $this->getChristmasDay($year); + + if ($christmasDay->isSaturday()) { + + $christmasDay = $christmasDay->next('monday'); + } + + if ($christmasDay->isSunday()) { + $christmasDay = $christmasDay->next('tuesday'); + } + + return $christmasDay; + } + + /** @return CarbonImmutable */ + protected function boxingDay(int $year): CarbonImmutable + { + $christmasDay = $this->getChristmasDay($year); + $boxingDay = new CarbonImmutable($year . '-12-26'); + + if ($christmasDay->isFriday()) { + $boxingDay = $boxingDay->next('monday'); + } + if ($christmasDay->isSaturday()) { + $boxingDay = $boxingDay->next('tuesday'); + } + + return $boxingDay; + } + + /** + * Get holiday + * + * For example: If a holiday falls on a weekend, the new day to be observed is the next monday + * @return CarbonImmutable + */ + protected function getHoliday(int $year, string $monthAndDay): CarbonImmutable + { + $newYearsDay = new CarbonImmutable($year . '-' . $monthAndDay); + + if ($newYearsDay->isWeekend()) { + $newYearsDay = $newYearsDay->next('monday'); + } + + return $newYearsDay; + } + protected function allHolidays(int $year): array { - return array_merge([ - 'New Year\'s Day' => '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)); + return array_merge( + [ + 'New Year\'s Day' => $this->getHoliday($year, '01-01'), + 'Constitution Day' => $this->getHoliday($year, '01-07'), + 'Independence Day' => $this->getHoliday($year, '03-06'), + 'May Day' => $this->getHoliday($year, '05-01'), + 'Founder\'s Day' => $this->getHoliday($year, '08-04'), + 'Kwame Nkrumah Memorial Day' => $this->getHoliday($year, '09-21'), + 'Christmas Day' => $this->christmasDay($year), + 'Boxing Day' => $this->boxingDay($year), + ], + $this->variableHolidays($year) + ); } /** @return array */ @@ -30,9 +93,17 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); + $farmersDay = new CarbonImmutable('first friday of December ' . $year); + return [ + 'Farmers Day' => $farmersDay, 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), + + // NB: *** There are no fixed dates for the Eid-Ul-Fitr and Eid-Ul-Adha because they are movable feasts. + // The dates for their observation are provided by the Office of the Chief Imam in the course of the year. + // 'Eid-Ul-Fitr' => "", + // 'Eid-Ul-Adha' => "", ]; } } 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 index 3d29c9e8f..b5d9a6c72 100644 --- 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 @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", 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 index 3d29c9e8f..b5d9a6c72 100644 --- 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 @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", 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 index 3d29c9e8f..b5d9a6c72 100644 --- a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day",