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.
Merge pull request #126 from Crawford30/feat/add_uganda_holidays
Added Uganda Public Holidays and Unit Tests
- Loading branch information
Showing
3 changed files
with
124 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,56 @@ | ||
<?php | ||
/** | ||
* Date 19-Jan-2024 | ||
* | ||
* @author Joel Crawford Email: <[email protected]> Github: <https://github.com/Crawford30> LinkedIn: <https://www.linkedin.com/in/Crawford30> | ||
*/ | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Uganda extends Country | ||
{ | ||
|
||
public function countryCode(): string | ||
{ | ||
return 'ug'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function allHolidays(int $year): array | ||
{ | ||
|
||
/** | ||
* 'New Year' => '01-01', Format:: Month-Date | ||
*/ | ||
return array_merge([ | ||
"New Year's Day" => "01-01", | ||
"NRM Liberation Day" => "01-26", | ||
"Archbishop Janani Luwum Day" => "02-16", | ||
"International Women's Day" => "03-08", | ||
"Labour Day" => "05-01", | ||
"Martyrs' Day" => "06-03", | ||
"National Hereos Day" => "06-09", | ||
"Independence Day" => "10-09", | ||
"Christmas Day" => "12-25", | ||
"Boxing Day" => "12-26", | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** | ||
* @param int $year | ||
* | ||
* @return array<string, CarbonImmutable> | ||
*/ | ||
private function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); | ||
return [ | ||
"Good Friday" => $easter->subDays(2), | ||
"Easter Monday" => $easter->addDay(), | ||
]; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_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,50 @@ | ||
[ | ||
{ | ||
"name": "New Year's Day", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "NRM Liberation Day", | ||
"date": "2024-01-26" | ||
}, | ||
{ | ||
"name": "Archbishop Janani Luwum Day", | ||
"date": "2024-02-16" | ||
}, | ||
{ | ||
"name": "International Women's Day", | ||
"date": "2024-03-08" | ||
}, | ||
{ | ||
"name": "Good Friday", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "Easter Monday", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Labour Day", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Martyrs' Day", | ||
"date": "2024-06-03" | ||
}, | ||
{ | ||
"name": "National Hereos Day", | ||
"date": "2024-06-09" | ||
}, | ||
{ | ||
"name": "Independence Day", | ||
"date": "2024-10-09" | ||
}, | ||
{ | ||
"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 ugandan holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'ug')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |