Skip to content

Commit

Permalink
Add El Salvador Holidays (#93)
Browse files Browse the repository at this point in the history
* add El Salvador holidays

* fix styling
  • Loading branch information
vlltr authored Jan 24, 2024
1 parent 8648337 commit a47637e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Countries/ElSalvador.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class ElSalvador extends Country
{

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

protected function allHolidays(int $year): array
{
return array_merge([
'Año Nuevo' => '01-01',
'Día del Trabajo' => '05-01',
'Día de la Madre' => '05-10',
'Día del Padre' => '06-17',
'Fiesta Divino Salvador del Mundo' => '08-06',
'Día de la Independencia' => '09-15',
'Día de Los Difuntos' => '11-02',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('America/El_Salvador');

return [
'Jueves Santo' => $easter->subDays(3),
'Viernes Santo' => $easter->subDays(2),
'Sábado de Gloria' => $easter->subDays(1),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "A\u00f1o Nuevo",
"date": "2024-01-01"
},
{
"name": "Jueves Santo",
"date": "2024-03-27"
},
{
"name": "Viernes Santo",
"date": "2024-03-28"
},
{
"name": "S\u00e1bado de Gloria",
"date": "2024-03-29"
},
{
"name": "D\u00eda del Trabajo",
"date": "2024-05-01"
},
{
"name": "D\u00eda de la Madre",
"date": "2024-05-10"
},
{
"name": "D\u00eda del Padre",
"date": "2024-06-17"
},
{
"name": "Fiesta Divino Salvador del Mundo",
"date": "2024-08-06"
},
{
"name": "D\u00eda de la Independencia",
"date": "2024-09-15"
},
{
"name": "D\u00eda de Los Difuntos",
"date": "2024-11-02"
},
{
"name": "Navidad",
"date": "2024-12-25"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/ElSalvadorTest.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 el salvador holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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

0 comments on commit a47637e

Please sign in to comment.