generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds Peru holidays * Adds Peru holidays * Use $this->easter factory and remoce comments on allHolidays method
- Loading branch information
Showing
3 changed files
with
128 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,44 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Peru extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'pe'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Año nuevo' => '01-01', | ||
'Día del Trabajo' => '05-01', | ||
'Batalla de Arica y Día de la bandera' => '06-07', | ||
'Día de San Pedro y San Pablo' => '06-29', | ||
'Día de la Fuerza Aérea del Perú' => '07-23', | ||
'Día de la Independencia' => '07-28', | ||
'Fiestas Patrias' => '07-29', | ||
'Batalla de Junín' => '08-06', | ||
'Santa Rosa de Lima' => '08-30', | ||
'Combate de Angamos' => '10-08', | ||
'Día de Todos los Santos' => '11-01', | ||
'Inmaculada Concepción' => '12-08', | ||
'Batalla de Ayacucho' => '12-09', | ||
'Navidad' => '12-25', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = $this->easter($year); | ||
|
||
return [ | ||
'Jueves Santo' => $easter->subDays(3), | ||
'Viernes Santo' => $easter->subDays(2), | ||
]; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
tests/.pest/snapshots/Countries/PeruTest/it_can_calculate_peru_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,66 @@ | ||
[ | ||
{ | ||
"name": "A\u00f1o nuevo", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Jueves Santo", | ||
"date": "2024-03-28" | ||
}, | ||
{ | ||
"name": "Viernes Santo", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "D\u00eda del Trabajo", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Batalla de Arica y D\u00eda de la bandera", | ||
"date": "2024-06-07" | ||
}, | ||
{ | ||
"name": "D\u00eda de San Pedro y San Pablo", | ||
"date": "2024-06-29" | ||
}, | ||
{ | ||
"name": "D\u00eda de la Fuerza A\u00e9rea del Per\u00fa", | ||
"date": "2024-07-23" | ||
}, | ||
{ | ||
"name": "D\u00eda de la Independencia", | ||
"date": "2024-07-28" | ||
}, | ||
{ | ||
"name": "Fiestas Patrias", | ||
"date": "2024-07-29" | ||
}, | ||
{ | ||
"name": "Batalla de Jun\u00edn", | ||
"date": "2024-08-06" | ||
}, | ||
{ | ||
"name": "Santa Rosa de Lima", | ||
"date": "2024-08-30" | ||
}, | ||
{ | ||
"name": "Combate de Angamos", | ||
"date": "2024-10-08" | ||
}, | ||
{ | ||
"name": "D\u00eda de Todos los Santos", | ||
"date": "2024-11-01" | ||
}, | ||
{ | ||
"name": "Inmaculada Concepci\u00f3n", | ||
"date": "2024-12-08" | ||
}, | ||
{ | ||
"name": "Batalla de Ayacucho", | ||
"date": "2024-12-09" | ||
}, | ||
{ | ||
"name": "Navidad", | ||
"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 peru holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'pe')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |