Skip to content

Commit

Permalink
add indonesia holiday (#66)
Browse files Browse the repository at this point in the history
* add indonesia holiday

* (fix): remove docblock

* fix(test): variable holidays

* fix(docblock): variableHolidays docblock

* refactor(variableHolidays): get easter date from the parent class

* fix(variableHolidays): easter date

* feat(holiday): add chinese new year holiday to indonesia

* fix(IndonesiaTest)
  • Loading branch information
ddouble-d authored Jan 30, 2024
1 parent 17c7849 commit 3635851
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
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();
});

0 comments on commit 3635851

Please sign in to comment.