generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for holidays in Nigeria (#10)
* Added support for holidays in Nigeria * fix name of the test case * remove children's day from list of official holiday * fix code styling issues * Update src/Countries/Nigeria.php --------- Co-authored-by: Niels Vanpachtenbeke <[email protected]>
- Loading branch information
1 parent
0ee271a
commit e30a34d
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Nigeria extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'ng'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'New Year\'s Day' => "01-01", | ||
'Worker\'s Day' => "05-01", | ||
'Democracy Day' => "06-12", | ||
'Independence Day' => "10-01", | ||
'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(), | ||
]; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"name": "New Year's Day", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Good Friday", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "Easter Monday", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Worker's Day", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Democracy Day", | ||
"date": "2024-06-12" | ||
}, | ||
{ | ||
"name": "Independence Day", | ||
"date": "2024-10-01" | ||
}, | ||
{ | ||
"name": "Christmas Day", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Boxing Day", | ||
"date": "2024-12-26" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate nigerian holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'ng')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |