Skip to content

Commit

Permalink
add indonesia holiday
Browse files Browse the repository at this point in the history
  • Loading branch information
ddouble-d committed Jan 21, 2024
1 parent 60b73ed commit 64db68d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Countries/Indonesia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Indonesia extends Country
{
public function countryCode(): string
{
return 'id';
}

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
'Tahun Baru' => '01-01',
'Hari Buruh Internasional' => '05-01',
'Hari Lahir Pancasila' => '06-01',
'Hari Kemerdekaan' => '08-17',
'Hari Raya Natal' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Asia/Jakarta');

return [
'Jumat Agung' => $easter->subDays(2),
'Hari Paskah' => $easter,
'Kenaikan Yesus Kristus' => $easter->addDays(39),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"name": "Tahun Baru",
"date": "2024-01-01"
},
{
"name": "Jumat Agung",
"date": "2024-03-29"
},
{
"name": "Hari Paskah",
"date": "2024-03-31"
},
{
"name": "Hari Buruh Internasional",
"date": "2024-05-01"
},
{
"name": "Kenaikan Yesus Kristus",
"date": "2024-05-09"
},
{
"name": "Hari Lahir Pancasila",
"date": "2024-06-01"
},
{
"name": "Hari Kemerdekaan",
"date": "2024-08-17"
},
{
"name": "Hari Raya Natal",
"date": "2024-12-25"
},
]
18 changes: 18 additions & 0 deletions tests/Countries/IndonesiaTest.php
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 Indonesia holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'id')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();
});

0 comments on commit 64db68d

Please sign in to comment.