Skip to content

Commit

Permalink
add philippine's regular holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
kndrckjvr committed Jan 17, 2024
1 parent 9927780 commit 83790dc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Countries/Philippines.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Carbon\Carbon;

class Philippines extends Country
{
public function countryCode(): string
{
return 'ph';
}

/** @return array<string, string|CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
'Araw ng Kagitingan' => '04-10',
'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, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$nationalHeroes = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-08-31");

$nationalHeroes = $nationalHeroes->previous(Carbon::MONDAY);

$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Asia/Manila');

return [
'Maundy Thursday' => $easter->subDays(3),
'Good Friday' => $easter->subDays(2),
'National Heroes Day' => $nationalHeroes,
];
}
}
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-29"
},
{
"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-30"
},
{
"name": "Christmas Day",
"date": "2024-12-25"
},
{
"name": "Rizal Day",
"date": "2024-12-30"
}
]
19 changes: 19 additions & 0 deletions tests/Countries/PhilippinesTest.php
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();

});

0 comments on commit 83790dc

Please sign in to comment.