Skip to content

Commit

Permalink
feat(Mexico.php): considering transition of executive in Mexico. Usin…
Browse files Browse the repository at this point in the history
…g only CarbonInmutable
  • Loading branch information
dantes4ur committed Jan 18, 2024
1 parent 54ea0e4 commit ae3a621
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
44 changes: 35 additions & 9 deletions src/Countries/Mexico.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spatie\Holidays\Countries;

use Carbon\Carbon;
use Carbon\CarbonImmutable;

class Mexico extends Country
Expand All @@ -17,26 +16,53 @@ protected function allHolidays(int $year): array
{
return array_merge([
'Año Nuevo' => '01-01',
'Natalicio de Benito Juárez' => '04-18',
'Día Internacional de los Trabajadores' => '05-01',
'Jornada Electoral General' => '06-02',
'Día de Independencia' => '09-16',
'Cambio de Gobierno' => '10-01',
'Día de la Revolución' => '11-18',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
/** @phpstan-ignore-next-line */
$constitutionDay = Carbon::createFromFormat("d/m/Y", "01/02/" . $year)
->firstOfMonth(1)
$constitutionDay = (new CarbonImmutable("first monday of february $year")) // 5 of february
->setTimezone('America/Mexico_City');

return [
'Día de la Constitución' => CarbonImmutable::createFromMutable($constitutionDay) // It's the first monday of february
$benitoJuarezBirth = (new CarbonImmutable("third monday of March $year")) // 21 of march
->setTimezone('America/Mexico_City');

$revolutionDay = (new CarbonImmutable("third monday of november $year")) // 20 of november
->setTimezone('America/Mexico_City');

/** @var CarbonImmutable|false $executiveChange */
$executiveChange = $this->governmentChangeDate();

$known_days = [
'Día de la Constitución' => $constitutionDay, // It's the first monday of february
'Natalicio de Benito Juárez' => $benitoJuarezBirth,
'Día de la Revolución' => $revolutionDay,
];

return array_merge(
$known_days,
$executiveChange ? ['Cambio de Gobierno' => $executiveChange] : []
);
}

protected function governmentChangeDate(): CarbonImmutable|false
{
$baseYear = 1946; // The first occurrence with president Miguel Aleman Valdes
$currentYear = CarbonImmutable::now()->year; // Get the current year

// Check if the current year is a transmission year
if (($currentYear - $baseYear) % 6 == 0) {
/** @phpstan-ignore-next-line */
return CarbonImmutable::create($currentYear, 10, 1) // October 1st of the transmission year
->setTimezone('America/Mexico_City');

}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@
},
{
"name": "Natalicio de Benito Ju\u00e1rez",
"date": "2024-04-18"
"date": "2024-03-17"
},
{
"name": "D\u00eda Internacional de los Trabajadores",
"date": "2024-05-01"
},
{
"name": "Jornada Electoral General",
"date": "2024-06-02"
},
{
"name": "D\u00eda de Independencia",
"date": "2024-09-16"
},
{
"name": "Cambio de Gobierno",
"date": "2024-10-01"
"date": "2024-09-30"
},
{
"name": "D\u00eda de la Revoluci\u00f3n",
"date": "2024-11-18"
"date": "2024-11-17"
},
{
"name": "Navidad",
Expand Down

0 comments on commit ae3a621

Please sign in to comment.