generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
3 changed files
with
96 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,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), | ||
]; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_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,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" | ||
} | ||
] |
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,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(); | ||
}); |