Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add holidays for Ecuador #218

Merged
merged 14 commits into from
Apr 11, 2024
72 changes: 72 additions & 0 deletions src/Countries/Ecuador.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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',
], $this->variableHolidays($year));
}

public function nearestDay(int $year, int $month, int $day)

Check failure on line 21 in src/Countries/Ecuador.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Ecuador::nearestDay() has no return type specified.
{
$date = CarbonImmutable::createFromDate($year, $month, $day);

if($date->is('Tuesday') || $date->is('Saturday')) {
return $date->subDay();
}

if($date->is('Sunday')) {
return $date->addDay();
}

if($date->is('Wednesday') || $date->is('Thursday')) {
return $date->next(CarbonImmutable::FRIDAY);
}

return $date;
}

public function getChristmasHoliday(int $year)

Check failure on line 40 in src/Countries/Ecuador.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Ecuador::getChristmasHoliday() has no return type specified.
{
$date = CarbonImmutable::createFromDate($year, 12, 25);

if($year === 2022) {
insoutt marked this conversation as resolved.
Show resolved Hide resolved
Nielsvanpach marked this conversation as resolved.
Show resolved Hide resolved
return $date->addDay();
}

return $date;
}

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

return [
'Viernes Santo' => $easter->subDays(2),
'Lunes de Carnaval' => $carnivalMonday,
'Martes de Carnaval' => $carnivalTuesday,
'Día del Trabajo' => $this->nearestDay($year, 5, 1),
'Batalla de Pichincha' => $this->nearestDay($year, 5, 24),
'Primer Grito de la Independencia' => $this->nearestDay($year, 8, 10),
'Independencia de Guayaquil' => $this->nearestDay($year, 10, 9),
'Día de Los Difuntos' => $this->nearestDay($year, 11, 2),
'Independencia de Cuenca' => $this->nearestDay($year, 11, 3),
'Navidad' => $this->getChristmasHoliday($year),
];
}
}
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-03"
},
{
"name": "Batalla de Pichincha",
"date": "2024-05-24"
},
{
"name": "Primer Grito de la Independencia",
"date": "2024-08-09"
},
{
"name": "Independencia de Guayaquil",
"date": "2024-10-11"
},
{
"name": "D\u00eda de Los Difuntos",
"date": "2024-11-01"
},
{
"name": "Independencia de Cuenca",
"date": "2024-11-04"
},
{
"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 () {
insoutt marked this conversation as resolved.
Show resolved Hide resolved
CarbonImmutable::setTestNow('2024-01-01');

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

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

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