generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
Added support for holidays in Nigeria #10
Merged
Nielsvanpach
merged 6 commits into
spatie:main
from
cybernerdie:feature/nigeria-holidays
Jan 31, 2024
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be0d90f
Added support for holidays in Nigeria
cybernerdie 2776015
fix name of the test case
cybernerdie a6c84ca
remove children's day from list of official holiday
cybernerdie 5475437
Merge branch 'main' of https://github.com/cybernerdie/holidays into f…
cybernerdie d816bd9
fix code styling issues
cybernerdie 1a97ba5
Update src/Countries/Nigeria.php
Nielsvanpach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,39 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Nigeria extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'ng'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'New Year\'s Day' => "01-01", | ||
'Worker\'s Day' => "05-01", | ||
'Children\'s Day' => "05-27", | ||
'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 = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Africa/Lagos'); | ||
Nielsvanpach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return [ | ||
'Good Friday' => $easter->subDay(2), | ||
'Easter Monday' => $easter->addDay(1), | ||
]; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
[ | ||
{ | ||
"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": "Children's Day", | ||
"date": "2024-05-27" | ||
}, | ||
{ | ||
"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(); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an official public holiday? I don't find it here: https://publicholidays.africa/nigeria/2024-dates/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's not regarded as an official holiday, i'll remove it @Nielsvanpach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There also seem to be official Muslim holidays on the list. I'm not aware of the rules in Nigeria on this? Is this a public holiday for everyone in the whole country?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The muslim holidays are for everyone but the exact calculation of these holidays involves the sighting of the moon, and it can vary depending on different interpretations within the Islamic community. @Nielsvanpach