Skip to content
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

add indonesia holiday #66

Merged
merged 8 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/Countries/Indonesia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Calendars\ChineseCalendar;

class Indonesia extends Country
{
use ChineseCalendar;

public function countryCode(): string
{
return 'id';
}

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 = $this->easter($year);

return [
'Tahun Baru Imlek' => $this->chineseToGregorianDate('01-01', $year),
'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,38 @@
[
{
"name": "Tahun Baru",
"date": "2024-01-01"
},
{
"name": "Tahun Baru Imlek",
"date": "2024-02-10"
},
{
"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::setTestNow('2024-01-01');

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

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

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