Skip to content

Commit

Permalink
Add Peru holidays (#54)
Browse files Browse the repository at this point in the history
* Adds Peru holidays

* Adds Peru holidays

* Use $this->easter factory and remoce comments on allHolidays method
  • Loading branch information
dlopez525 authored Jan 23, 2024
1 parent 1b7ef83 commit d04ca04
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Countries/Peru.php
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),
];
}
}
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"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/PeruTest.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 peru holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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

0 comments on commit d04ca04

Please sign in to comment.