Skip to content

Commit

Permalink
Get nearest day of holiday
Browse files Browse the repository at this point in the history
  • Loading branch information
insoutt committed Apr 9, 2024
1 parent db6122b commit febecee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
33 changes: 26 additions & 7 deletions src/Countries/Ecuador.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@ 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));
}

public function nearestDay(int $year, int $month, int $day)
{
$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;
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
Expand All @@ -37,6 +49,13 @@ protected function variableHolidays(int $year): array
'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->nearestDay($year, 12, 25),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
},
{
"name": "D\u00eda del Trabajo",
"date": "2024-05-01"
"date": "2024-05-03"
},
{
"name": "Batalla de Pichincha",
"date": "2024-05-24"
},
{
"name": "Primer Grito de la Independencia",
"date": "2024-08-10"
"date": "2024-08-09"
},
{
"name": "Independencia de Guayaquil",
"date": "2024-10-09"
"date": "2024-10-11"
},
{
"name": "D\u00eda de Los Difuntos",
"date": "2024-11-02"
"date": "2024-11-01"
},
{
"name": "Independencia de Cuenca",
"date": "2024-11-03"
"date": "2024-11-04"
},
{
"name": "Navidad",
Expand Down

0 comments on commit febecee

Please sign in to comment.