generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
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 #25 from kndrckjvr/add_philippine_holiday
add Philippine national holidays
- Loading branch information
Showing
3 changed files
with
102 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,41 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Philippines extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'ph'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'New Year\'s Day' => '01-01', | ||
'Araw ng Kagitingan' => '04-09', | ||
'Labor Day' => '05-01', | ||
'Independence Day' => '06-12', | ||
'Bonifacio Day' => '11-27', | ||
'Christmas Day' => '12-25', | ||
'Rizal Day' => '12-30', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, string|CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$nationalHeroes = new CarbonImmutable("last monday of august {$year}"); | ||
|
||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Asia/Manila'); | ||
|
||
return [ | ||
'Maundy Thursday' => $easter->subDays(3), | ||
'Good Friday' => $easter->subDays(2), | ||
'National Heroes Day' => $nationalHeroes, | ||
]; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_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,42 @@ | ||
[ | ||
{ | ||
"name": "New Year's Day", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Maundy Thursday", | ||
"date": "2024-03-28" | ||
}, | ||
{ | ||
"name": "Good Friday", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "Araw ng Kagitingan", | ||
"date": "2024-04-09" | ||
}, | ||
{ | ||
"name": "Labor Day", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Independence Day", | ||
"date": "2024-06-12" | ||
}, | ||
{ | ||
"name": "National Heroes Day", | ||
"date": "2024-08-26" | ||
}, | ||
{ | ||
"name": "Bonifacio Day", | ||
"date": "2024-11-27" | ||
}, | ||
{ | ||
"name": "Christmas Day", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Rizal Day", | ||
"date": "2024-12-30" | ||
} | ||
] |
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,19 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate philippine holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'ph')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
|
||
}); |