Skip to content

Commit

Permalink
Enhanced holiday dates in Ghana (#80)
Browse files Browse the repository at this point in the history
* Added holidays for `Ghana`

* fix timezone when creating farmers day

* Updated holidays that falls within weekend to be observed on the next monday

* Fix return types

* pr suggestions implemented

* removed unwanted timezone in params

* removed timezone

* Updated test

* removed test files

* Add back test files

* Added return types to methods
  • Loading branch information
Ikpeba4ll authored Feb 8, 2024
1 parent fb625e2 commit 0ab3409
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 19 deletions.
91 changes: 81 additions & 10 deletions src/Countries/Ghana.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,99 @@ 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;

Check failure on line 38 in src/Countries/Ghana.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Ghana::christmasDay() should return Carbon\CarbonImmutable but returns Carbon\CarbonInterface.
}

/** @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;

Check failure on line 54 in src/Countries/Ghana.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Ghana::boxingDay() should return Carbon\CarbonImmutable but returns Carbon\CarbonInterface.
}

/**
* 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;

Check failure on line 71 in src/Countries/Ghana.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Ghana::getHoliday() should return Carbon\CarbonImmutable but returns Carbon\CarbonInterface.
}

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<string, CarbonImmutable> */
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' => "",
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
{
"name": "Constitution Day",
"date": "2024-01-07"
"date": "2024-01-08"
},
{
"name": "Independence Day",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
{
"name": "Constitution Day",
"date": "2024-01-07"
"date": "2024-01-08"
},
{
"name": "Independence Day",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
{
"name": "Constitution Day",
"date": "2024-01-07"
"date": "2024-01-08"
},
{
"name": "Independence Day",
Expand All @@ -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",
Expand Down

0 comments on commit 0ab3409

Please sign in to comment.