From 46778620206c2a21c5ef6c655bfd5f31fba2bb03 Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:01:19 +0000 Subject: [PATCH 1/5] Adding Full Mexican Holidays --- src/Countries/Mexico.php | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/Countries/Mexico.php diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php new file mode 100644 index 000000000..c2339775b --- /dev/null +++ b/src/Countries/Mexico.php @@ -0,0 +1,87 @@ + */ + protected function allHolidays(int $year): array + { + + $natalicioBenitoJuarez = new CarbonImmutable(sprintf("third monday of march %s", $year)); + $promulgacionConstitucion = new CarbonImmutable(sprintf("first monday of february %s", $year)); + $revolucionMexicana = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-11-20")->setTimezone('America/Mexico_City'); + + if ($revolucionMexicana->isSunday()) { + $revolucionMexicana = $revolucionMexicana->next('monday'); + } + + $mandatory = [ + 'Año nuevo' => '01-01', + 'Aniversario de la promulgación de la Constitución de 1917' => $promulgacionConstitucion->format('m-d'), + 'Natalicio de Benito Juárez' => $natalicioBenitoJuarez->format('m-d'), + 'Día del Trabajo' => '05-01', + 'Día de la Independencia' => '09-15', + 'Revolución Mexicana' => $revolucionMexicana->format('m-d'), + 'Navidad' => '12-25', + ]; + + if ($this->transmisionPoderEjecutivoFederal($year)) { + $mandatory[ + "Transmisión del Poder Ejecutivo Federal" + ] = $this->transmisionPoderEjecutivoFederal($year); + } + + return array_merge($mandatory, $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + + $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); + + return [ + + 'Día de la Candelaria' => '02-02', + 'Día de la Bandera' => '02-24', + 'Día del Niño' => '04-30', + 'Día de la Madre' => '04-30', + 'Día del Padre' => $fathersDay, + 'Día de la Raza' => '10-12', + 'Día de Muertos' => '11-02', + 'Virgen de Guadalupe' => '12-12', + ]; + } + + + protected function transmisionPoderEjecutivoFederal($year) + { + $period = new CarbonPeriod(); + $period->setDateClass(CarbonImmutable::class); + $period + ->every("6 years") + ->since(sprintf("%s-10-01", 2024)) + ->until(sprintf("%s-10-01 00:00:00", Carbon::now()->addYears(6)->year)); + + $period->addFilter(function ($date) use ($year) { + return $date->year === $year; + }); + + $availableDates = $period->toArray(); + + if (count($availableDates)) { + return $availableDates[0]->format("m-d"); + } + return false; + } +} From effb2f321239200491164848c2c58ec3b8f86e45 Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:06:15 +0000 Subject: [PATCH 2/5] Add Test --- tests/Countries/MexicoTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/Countries/MexicoTest.php diff --git a/tests/Countries/MexicoTest.php b/tests/Countries/MexicoTest.php new file mode 100644 index 000000000..ac89542a8 --- /dev/null +++ b/tests/Countries/MexicoTest.php @@ -0,0 +1,19 @@ +Meget(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 7dcd3d2826c4077ef766799ba665eb762928978b Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:10:30 +0000 Subject: [PATCH 3/5] update test description and remove typo, --- .vscode/settings.json | 5 ++++ src/Countries/Mexico.php | 54 +++++++++++++++++----------------- tests/Countries/MexicoTest.php | 4 +-- 3 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..b242572ef --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] +} \ No newline at end of file diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index c2339775b..9c85f5231 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -15,6 +15,24 @@ public function countryCode(): string /** @return array */ protected function allHolidays(int $year): array + { + return array_merge([ + 'Año nuevo' => '01-01', + 'Día de la Candelaria' => '02-02', + 'Día de la Bandera' => '02-24', + 'Día del Niño' => '04-30', + 'Día de la Madre' => '04-30', + 'Día del Trabajo' => '05-01', + 'Día de la Independencia' => '09-15', + 'Día de la Raza' => '10-12', + 'Día de Muertos' => '11-02', + 'Virgen de Guadalupe' => '12-12', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array { $natalicioBenitoJuarez = new CarbonImmutable(sprintf("third monday of march %s", $year)); @@ -25,46 +43,28 @@ protected function allHolidays(int $year): array $revolucionMexicana = $revolucionMexicana->next('monday'); } - $mandatory = [ - 'Año nuevo' => '01-01', + $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); + + + $days = [ 'Aniversario de la promulgación de la Constitución de 1917' => $promulgacionConstitucion->format('m-d'), 'Natalicio de Benito Juárez' => $natalicioBenitoJuarez->format('m-d'), - 'Día del Trabajo' => '05-01', - 'Día de la Independencia' => '09-15', 'Revolución Mexicana' => $revolucionMexicana->format('m-d'), - 'Navidad' => '12-25', + 'Día del Padre' => $fathersDay->format('m-d'), + ]; if ($this->transmisionPoderEjecutivoFederal($year)) { - $mandatory[ + $days[ "Transmisión del Poder Ejecutivo Federal" ] = $this->transmisionPoderEjecutivoFederal($year); } - return array_merge($mandatory, $this->variableHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - - $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); - - return [ - - 'Día de la Candelaria' => '02-02', - 'Día de la Bandera' => '02-24', - 'Día del Niño' => '04-30', - 'Día de la Madre' => '04-30', - 'Día del Padre' => $fathersDay, - 'Día de la Raza' => '10-12', - 'Día de Muertos' => '11-02', - 'Virgen de Guadalupe' => '12-12', - ]; + return $days; } - protected function transmisionPoderEjecutivoFederal($year) + protected function transmisionPoderEjecutivoFederal($year): bool|string { $period = new CarbonPeriod(); $period->setDateClass(CarbonImmutable::class); diff --git a/tests/Countries/MexicoTest.php b/tests/Countries/MexicoTest.php index ac89542a8..cb2876aeb 100644 --- a/tests/Countries/MexicoTest.php +++ b/tests/Countries/MexicoTest.php @@ -1,11 +1,11 @@ -Meget(); From dfc9eb1606f095bb8ded80bdfa15ca590b910d3c Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:12:54 +0000 Subject: [PATCH 4/5] remove vscode folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ff8bfd7e5..96b3d690a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .php_cs .php_cs.cache .phpunit.cache +.vscode build composer.lock coverage From e3a14de1c99e90c049c432c1efa7c4b1d4f010ad Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 11:13:31 -0600 Subject: [PATCH 5/5] Delete .vscode directory --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b242572ef..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "githubPullRequests.ignoredPullRequestBranches": [ - "main" - ] -} \ No newline at end of file