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

Add public holidays for Ghana #175

Merged
merged 6 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions src/Countries/Ghana.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Ghana extends Country
{

public function countryCode(): string
{
return 'gh';
}

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<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = $this->easter($year);

return [
'Good Friday' => $easter->subDays(2),
'Easter Monday' => $easter->addDay(),
];
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
]
43 changes: 43 additions & 0 deletions tests/Countries/GhanaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Countries\France;
use Spatie\Holidays\Holidays;

it('can calculate Ghana 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 easter based region holidays', function () {
petersowah marked this conversation as resolved.
Show resolved Hide resolved
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 () {
petersowah marked this conversation as resolved.
Show resolved Hide resolved
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'gh')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();
});