Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced holiday dates in Ghana #80

Merged
merged 20 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 78 additions & 10 deletions src/Countries/Ghana.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,96 @@
return 'gh';
}

/**
* Return carbon date for christmas
*
* @return CarbonImmutable
*/
protected function getChristmasDay(int $year)
{
return new CarbonImmutable($year . '-12-25');
}

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 37 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.
}

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 52 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
*/
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 68 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the holiday is on 7th which is sunday so we observed it on 8th,

},
{
"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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the holiday is on 7th which is sunday so we observed it on 8th,

},
{
"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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the holiday is on 7th which is sunday so we observed it on 8th,

},
{
"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
Loading