Skip to content

Commit

Permalink
Add holidays for Ecuador
Browse files Browse the repository at this point in the history
  • Loading branch information
insoutt committed Apr 9, 2024
1 parent 773fc67 commit db6122b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Countries/Ecuador.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Ecuador extends Country
{
public function countryCode(): string
{
return 'ec';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Año Nuevo' => '01-01',
'Día del Trabajo' => '05-01',
'Batalla de Pichincha' => '05-24',
'Primer Grito de la Independencia' => '08-10',
'Independencia de Guayaquil' => '10-09',
'Día de Los Difuntos' => '11-02',
'Independencia de Cuenca' => '11-03',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = $this->easter($year);
$ashWednesday = $easter->subDays(46);
$carnivalMonday = $ashWednesday->subDays(2);
$carnivalTuesday = $ashWednesday->subDay();

return [
'Viernes Santo' => $easter->subDays(2),
'Lunes de Carnaval' => $carnivalMonday,
'Martes de Carnaval' => $carnivalTuesday,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "A\u00f1o Nuevo",
"date": "2024-01-01"
},
{
"name": "Lunes de Carnaval",
"date": "2024-02-12"
},
{
"name": "Martes de Carnaval",
"date": "2024-02-13"
},
{
"name": "Viernes Santo",
"date": "2024-03-29"
},
{
"name": "D\u00eda del Trabajo",
"date": "2024-05-01"
},
{
"name": "Batalla de Pichincha",
"date": "2024-05-24"
},
{
"name": "Primer Grito de la Independencia",
"date": "2024-08-10"
},
{
"name": "Independencia de Guayaquil",
"date": "2024-10-09"
},
{
"name": "D\u00eda de Los Difuntos",
"date": "2024-11-02"
},
{
"name": "Independencia de Cuenca",
"date": "2024-11-03"
},
{
"name": "Navidad",
"date": "2024-12-25"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/EcuadorTest.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 ecuador holidays', function () {
CarbonImmutable::setTestNow('2024-01-01');

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

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

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

0 comments on commit db6122b

Please sign in to comment.