From 288a7f92e3f45213c7a2baa5567d412df6c6e316 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 15:47:45 +0100 Subject: [PATCH 01/71] Create France.php --- src/Countries/France.php | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Countries/France.php diff --git a/src/Countries/France.php b/src/Countries/France.php new file mode 100644 index 000000000..3c7a488e5 --- /dev/null +++ b/src/Countries/France.php @@ -0,0 +1,41 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Jour de l\'An' => '01-01', + 'Fête du Travail' => '05-01', + 'Victoire 1945' => '05-08' + 'Fête Nationale' => '07-14', + 'Assomption' => '08-15', + 'Toussaint' => '11-01', + 'Armistice 1918' => '11-11', + 'Noël' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Brussels'); + + return [ + 'Lundi de Pâques' => $easter->addDay(), + 'Ascension' => $easter->addDays(39), + 'Lundi de Pentecôte' => $easter->addDays(50), + ]; + } +} From b64a2419eb613c795e0fedf12b234633e6520ced Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 15:49:49 +0100 Subject: [PATCH 02/71] Create FranceTest.php --- tests/Countries/FranceTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/Countries/FranceTest.php diff --git a/tests/Countries/FranceTest.php b/tests/Countries/FranceTest.php new file mode 100644 index 000000000..6b69bbf22 --- /dev/null +++ b/tests/Countries/FranceTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From fa67eacd4f84405e2e94f7b55a9d2b3156498a21 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 15:55:02 +0100 Subject: [PATCH 03/71] Fix France.php --- src/Countries/France.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 3c7a488e5..632552f4b 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -17,7 +17,7 @@ protected function allHolidays(int $year): array return array_merge([ 'Jour de l\'An' => '01-01', 'Fête du Travail' => '05-01', - 'Victoire 1945' => '05-08' + 'Victoire 1945' => '05-08', 'Fête Nationale' => '07-14', 'Assomption' => '08-15', 'Toussaint' => '11-01', From 35afd9e0c092962d45d653ba0986b9e3630e60e7 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 16:01:43 +0100 Subject: [PATCH 04/71] Create it_can_calculate_french_holidays.snap --- .../it_can_calculate_french_holidays.snap | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap new file mode 100644 index 000000000..aef1f0eaf --- /dev/null +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Jour de l'An", + "date": "2024-01-01" + }, + { + "name": "Lundi de Pâques", + "date": "2024-04-01" + }, + { + "name": "Fête du Travail", + "date": "2024-05-01" + }, + { + "name": "Victoire 1945", + "date": "2024-05-08" + }, + { + "name": "Ascension", + "date": "2024-05-09" + }, + { + "name": "Lundi de Pentecôte", + "date": "2024-05-20" + }, + { + "name": "Fête Nationale", + "date": "2024-07-14" + }, + { + "name": "Assomption", + "date": "2024-08-15" + }, + { + "name": "Toussaint", + "date": "2024-11-01" + }, + { + "name": "Armistice 1918", + "date": "2024-11-11" + }, + { + "name": "Noël", + "date": "2024-12-25" + } +] From d542fafd60b8e3f6960e8ebc6cad14f1ce89ac01 Mon Sep 17 00:00:00 2001 From: Loup Date: Wed, 17 Jan 2024 16:09:40 +0100 Subject: [PATCH 05/71] tests --- .../FranceTest/it_can_calculate_french_holidays.snap | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap index aef1f0eaf..f89d17309 100644 --- a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap @@ -4,11 +4,11 @@ "date": "2024-01-01" }, { - "name": "Lundi de Pâques", + "name": "Lundi de P\u00e2ques", "date": "2024-04-01" }, { - "name": "Fête du Travail", + "name": "F\u00eate du Travail", "date": "2024-05-01" }, { @@ -20,11 +20,11 @@ "date": "2024-05-09" }, { - "name": "Lundi de Pentecôte", + "name": "Lundi de Pentec\u00f4te", "date": "2024-05-20" }, { - "name": "Fête Nationale", + "name": "F\u00eate Nationale", "date": "2024-07-14" }, { @@ -40,7 +40,7 @@ "date": "2024-11-11" }, { - "name": "Noël", + "name": "No\u00ebl", "date": "2024-12-25" } -] +] \ No newline at end of file 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 06/71] 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 07/71] 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 08/71] 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 09/71] 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 10/71] 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 From f853f9826e8cee64b898f989f9a7d70d6ecffaf9 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 19:02:22 +0100 Subject: [PATCH 11/71] Update src/Countries/France.php Co-authored-by: Hugo Alliaume --- src/Countries/France.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 632552f4b..3b1813b49 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + ->setTimezone('Europe/Paris'); return [ 'Lundi de Pâques' => $easter->addDay(), From a0666fbd7f52648d25941bd9ad303c0c7cc70279 Mon Sep 17 00:00:00 2001 From: Javier Emmanuel Mercedes Date: Wed, 17 Jan 2024 21:00:39 -0400 Subject: [PATCH 12/71] Added Dominican Republic holidays --- src/Countries/DominicanRepublic.php | 42 ++++++++++++++++ ...calculate_dominican_republic_holidays.snap | 50 +++++++++++++++++++ tests/Countries/DominicanRepublicTest.php | 19 +++++++ 3 files changed, 111 insertions(+) create mode 100644 src/Countries/DominicanRepublic.php create mode 100644 tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap create mode 100644 tests/Countries/DominicanRepublicTest.php diff --git a/src/Countries/DominicanRepublic.php b/src/Countries/DominicanRepublic.php new file mode 100644 index 000000000..98cb24a77 --- /dev/null +++ b/src/Countries/DominicanRepublic.php @@ -0,0 +1,42 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Año Nuevo' => '01-01', + 'Día de la Altagracia' => '01-21', + 'Día de Duarte' => '01-26', + 'Día de la Independencia' => '02-27', + 'Día del Trabajo' => '05-01', + 'Día de la Restauración' => '08-16', + 'Día de las Mercedes' => '09-24', + 'Día de la Constitución' => '11-06', + 'Día de la Virgen de la Altagracia' => '12-08', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Santo_Domingo'); + + return [ + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap b/tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap new file mode 100644 index 000000000..163490da2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda de la Altagracia", + "date": "2024-01-21" + }, + { + "name": "D\u00eda de Duarte", + "date": "2024-01-26" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-02-27" + }, + { + "name": "Jueves Santo", + "date": "2024-03-28" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de la Restauraci\u00f3n", + "date": "2024-08-16" + }, + { + "name": "D\u00eda de las Mercedes", + "date": "2024-09-24" + }, + { + "name": "D\u00eda de la Constituci\u00f3n", + "date": "2024-11-06" + }, + { + "name": "D\u00eda de la Virgen de la Altagracia", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/DominicanRepublicTest.php b/tests/Countries/DominicanRepublicTest.php new file mode 100644 index 000000000..7a388eda6 --- /dev/null +++ b/tests/Countries/DominicanRepublicTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + From f9aba7a3e071ad0012e71100b0a0875808194ec7 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Thu, 18 Jan 2024 14:04:47 +0100 Subject: [PATCH 13/71] Removed typehint from France::allHolidays() --- src/Countries/France.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 3b1813b49..1aadad484 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'fr'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 431db955e8f77e87d414e42f11e9d59cf3b6f5f9 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Thu, 18 Jan 2024 16:52:47 +0100 Subject: [PATCH 14/71] make tests faster --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 14315473c..ee8a13ead 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] php: [8.3, 8.2, 8.1] stability: [prefer-lowest, prefer-stable] From 47c40bfd3344e91a5e23c93e7aae92c35f833870 Mon Sep 17 00:00:00 2001 From: Javier Emmanuel Mercedes Date: Thu, 18 Jan 2024 11:59:02 -0400 Subject: [PATCH 15/71] Removed lines --- src/Countries/DominicanRepublic.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Countries/DominicanRepublic.php b/src/Countries/DominicanRepublic.php index 98cb24a77..ea9659846 100644 --- a/src/Countries/DominicanRepublic.php +++ b/src/Countries/DominicanRepublic.php @@ -10,8 +10,6 @@ public function countryCode(): string { return 'do'; } - - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -27,8 +25,6 @@ protected function allHolidays(int $year): array 'Navidad' => '12-25', ], $this->variableHolidays($year)); } - - /** @return array */ protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) From 1c865ad771b07b1a31153965a48e5dc4889212ca Mon Sep 17 00:00:00 2001 From: Javier Emmanuel Mercedes Date: Thu, 18 Jan 2024 12:02:56 -0400 Subject: [PATCH 16/71] Added comments for phpstan --- src/Countries/DominicanRepublic.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Countries/DominicanRepublic.php b/src/Countries/DominicanRepublic.php index ea9659846..98cb24a77 100644 --- a/src/Countries/DominicanRepublic.php +++ b/src/Countries/DominicanRepublic.php @@ -10,6 +10,8 @@ public function countryCode(): string { return 'do'; } + + /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -25,6 +27,8 @@ protected function allHolidays(int $year): array 'Navidad' => '12-25', ], $this->variableHolidays($year)); } + + /** @return array */ protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) From b41eda234eab20e27b6c0c8765142f60887caa77 Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 11:28:56 -0600 Subject: [PATCH 17/71] Adding Nicaragua Holidays Avoid PHPStorm insert final newline into snap, failing the test match string. --- .editorconfig | 3 ++ src/Countries/Nicaragua.php | 40 ++++++++++++++++++ .../it_can_calculate_nicaragua_holidays.snap | 42 +++++++++++++++++++ tests/Countries/NicaraguaTest.php | 18 ++++++++ 4 files changed, 103 insertions(+) create mode 100644 src/Countries/Nicaragua.php create mode 100644 tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap create mode 100644 tests/Countries/NicaraguaTest.php diff --git a/.editorconfig b/.editorconfig index a7c44ddb1..6f7c0773a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,6 @@ trim_trailing_whitespace = false [*.{yml,yaml}] indent_size = 2 + +[*.snap] +insert_final_newline = false \ No newline at end of file diff --git a/src/Countries/Nicaragua.php b/src/Countries/Nicaragua.php new file mode 100644 index 000000000..d185b59b6 --- /dev/null +++ b/src/Countries/Nicaragua.php @@ -0,0 +1,40 @@ + '01-01', + 'Día internacional de los trabajadores' => '05-01', + 'Día de las madres' => '05-30', + 'Aniversario de la revolución' => '07-19', + 'Aniversario de la batalla de san jacinto' => '09-14', + 'Aniversario de la independencia' => '09-15', + 'Día de la inmaculada concepción' => '12-08', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Managua'); + + + return [ + 'Jueves santo' => $easter->subDays(3)->format('m-d'), + 'Viernes santo' => $easter->subDays(2)->format('m-d'), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap new file mode 100644 index 000000000..b92235be0 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "A\u00f1o nuevo", + "date": "2024-01-01" + }, + { + "name": "Jueves santo", + "date": "2024-03-28" + }, + { + "name": "Viernes santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda internacional de los trabajadores", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de las madres", + "date": "2024-05-30" + }, + { + "name": "Aniversario de la revoluci\u00f3n", + "date": "2024-07-19" + }, + { + "name": "Aniversario de la batalla de san jacinto", + "date": "2024-09-14" + }, + { + "name": "Aniversario de la independencia", + "date": "2024-09-15" + }, + { + "name": "D\u00eda de la inmaculada concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/NicaraguaTest.php b/tests/Countries/NicaraguaTest.php new file mode 100644 index 000000000..840a0609a --- /dev/null +++ b/tests/Countries/NicaraguaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 31b95cf5dcc84617c69c883caf8a19e72d6166a9 Mon Sep 17 00:00:00 2001 From: Loup Date: Thu, 18 Jan 2024 18:39:03 +0100 Subject: [PATCH 18/71] Added region-specific ISO 3166-2 codes --- src/Countries/France.php | 42 ++++++++++++++- ...e_french_date_based_regional_holidays.snap | 50 +++++++++++++++++ ...e_french_easter_based_region_holidays.snap | 54 +++++++++++++++++++ tests/Countries/FranceTest.php | 25 +++++++++ 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap diff --git a/src/Countries/France.php b/src/Countries/France.php index 1aadad484..977e26a10 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -6,6 +6,11 @@ class France extends Country { + protected function __construct( + protected ?string $region = null, + ) { + } + public function countryCode(): string { return 'fr'; @@ -22,7 +27,9 @@ protected function allHolidays(int $year): array 'Toussaint' => '11-01', 'Armistice 1918' => '11-11', 'Noël' => '12-25', - ], $this->variableHolidays($year)); + ], + $this->variableHolidays($year), + $this->regionHolidays()); } /** @return array */ @@ -31,10 +38,41 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Europe/Paris'); - return [ + $holidays = [ 'Lundi de Pâques' => $easter->addDay(), 'Ascension' => $easter->addDays(39), 'Lundi de Pentecôte' => $easter->addDays(50), ]; + + if (in_array($this->region, ['FR-57', 'FR-67', 'FR-68'])) { + $holidays['Vendredi Saint'] = $easter->subDays(2); + } + + return $holidays; + } + + protected function regionHolidays(): array + { + switch ($this->region) { + case 'FR-57': + case 'FR-67': + case 'FR-68': + return ['Saint-Étienne' => '12-26']; + case 'FR-971': + case 'FR-MF': + return ['Abolition de l\'esclavage' => '05-27']; + case 'FR-972': + return ['Abolition de l\'esclavage' => '05-22']; + case 'FR-973': + return ['Abolition de l\'esclavage' => '06-10']; + case 'FR-974': + return ['Abolition de l\'esclavage' => '12-20']; + case 'FR-976': + return ['Abolition de l\'esclavage' => '04-27']; + case 'FR-BL': + return ['Abolition de l\'esclavage' => '10-09']; + } + + return []; } } diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap new file mode 100644 index 000000000..5256f894b --- /dev/null +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Jour de l'An", + "date": "2024-01-01" + }, + { + "name": "Lundi de P\u00e2ques", + "date": "2024-04-01" + }, + { + "name": "F\u00eate du Travail", + "date": "2024-05-01" + }, + { + "name": "Victoire 1945", + "date": "2024-05-08" + }, + { + "name": "Ascension", + "date": "2024-05-09" + }, + { + "name": "Lundi de Pentec\u00f4te", + "date": "2024-05-20" + }, + { + "name": "F\u00eate Nationale", + "date": "2024-07-14" + }, + { + "name": "Assomption", + "date": "2024-08-15" + }, + { + "name": "Abolition de l'esclavage", + "date": "2024-10-09" + }, + { + "name": "Toussaint", + "date": "2024-11-01" + }, + { + "name": "Armistice 1918", + "date": "2024-11-11" + }, + { + "name": "No\u00ebl", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap new file mode 100644 index 000000000..4dd52f185 --- /dev/null +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Jour de l'An", + "date": "2024-01-01" + }, + { + "name": "Vendredi Saint", + "date": "2024-03-29" + }, + { + "name": "Lundi de P\u00e2ques", + "date": "2024-04-01" + }, + { + "name": "F\u00eate du Travail", + "date": "2024-05-01" + }, + { + "name": "Victoire 1945", + "date": "2024-05-08" + }, + { + "name": "Ascension", + "date": "2024-05-09" + }, + { + "name": "Lundi de Pentec\u00f4te", + "date": "2024-05-20" + }, + { + "name": "F\u00eate Nationale", + "date": "2024-07-14" + }, + { + "name": "Assomption", + "date": "2024-08-15" + }, + { + "name": "Toussaint", + "date": "2024-11-01" + }, + { + "name": "Armistice 1918", + "date": "2024-11-11" + }, + { + "name": "No\u00ebl", + "date": "2024-12-25" + }, + { + "name": "Saint-\u00c9tienne", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/FranceTest.php b/tests/Countries/FranceTest.php index 6b69bbf22..e70d919be 100644 --- a/tests/Countries/FranceTest.php +++ b/tests/Countries/FranceTest.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; +use Spatie\Holidays\Countries\France; it('can calculate french holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); @@ -16,3 +17,27 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('can calculate french easter based region holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(France::make('FR-57'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate french date based regional holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(France::make('FR-BL'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From ce172db8090357423d6625b20ac78ffe00c091a9 Mon Sep 17 00:00:00 2001 From: Loup Date: Thu, 18 Jan 2024 18:57:23 +0100 Subject: [PATCH 19/71] Added regionHolidays return value type --- src/Countries/France.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Countries/France.php b/src/Countries/France.php index 977e26a10..449d13f57 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -51,6 +51,7 @@ protected function variableHolidays(int $year): array return $holidays; } + /** @return array */ protected function regionHolidays(): array { switch ($this->region) { From 65b8200314f387fea4b4c06dd30db4ca9307a052 Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 11:59:30 -0600 Subject: [PATCH 20/71] fixing return for phpstan --- src/Countries/Nicaragua.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Countries/Nicaragua.php b/src/Countries/Nicaragua.php index d185b59b6..8614270b6 100644 --- a/src/Countries/Nicaragua.php +++ b/src/Countries/Nicaragua.php @@ -31,10 +31,9 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('America/Managua'); - return [ - 'Jueves santo' => $easter->subDays(3)->format('m-d'), - 'Viernes santo' => $easter->subDays(2)->format('m-d'), + 'Jueves santo' => $easter->subDays(3), + 'Viernes santo' => $easter->subDays(2), ]; } } From 2759f974942f361170dbdc12e0ec6d11bd0ea8da Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 13:35:35 -0600 Subject: [PATCH 21/71] match utc time --- .../NicaraguaTest/it_can_calculate_nicaragua_holidays.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap index b92235be0..572176fc8 100644 --- a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap +++ b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap @@ -5,11 +5,11 @@ }, { "name": "Jueves santo", - "date": "2024-03-28" + "date": "2024-03-27" }, { "name": "Viernes santo", - "date": "2024-03-29" + "date": "2024-03-28" }, { "name": "D\u00eda internacional de los trabajadores", From b9400b872ea60f3a78f0e7138c3dc88c05ba8d19 Mon Sep 17 00:00:00 2001 From: Julio Fagundes Date: Thu, 18 Jan 2024 16:41:23 -0300 Subject: [PATCH 22/71] Update Brazil.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added "Dia Nacional de Zumbi e da Consciência Negra" --- src/Countries/Brazil.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index 19b9af7a0..a05dbbf44 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -23,6 +23,7 @@ protected function allHolidays(int $year): array 'Nossa Senhora Aparecida' => '10-12', 'Finados' => '11-02', 'Proclamação da República' => '11-15', + 'Dia Nacional de Zumbi e da Consciência Negra' => '11-20', 'Natal' => '12-25', ], $this->variableHolidays($year)); } From 5a696ad0f0238f4a7dcbf9b1bfcaa78f1ad4a4ad Mon Sep 17 00:00:00 2001 From: kndrckjvr Date: Thu, 18 Jan 2024 01:01:00 +0800 Subject: [PATCH 23/71] add philippine's regular holidays * removed comments --- src/Countries/Philippines.php | 41 ++++++++++++++++++ .../it_can_calculate_philippine_holidays.snap | 42 +++++++++++++++++++ tests/Countries/PhilippinesTest.php | 19 +++++++++ 3 files changed, 102 insertions(+) create mode 100644 src/Countries/Philippines.php create mode 100644 tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap create mode 100644 tests/Countries/PhilippinesTest.php diff --git a/src/Countries/Philippines.php b/src/Countries/Philippines.php new file mode 100644 index 000000000..dd4cf848e --- /dev/null +++ b/src/Countries/Philippines.php @@ -0,0 +1,41 @@ + '01-01', + 'Araw ng Kagitingan' => '04-09', + 'Labor Day' => '05-01', + 'Independence Day' => '06-12', + 'Bonifacio Day' => '11-27', + 'Christmas Day' => '12-25', + 'Rizal Day' => '12-30', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $nationalHeroes = new CarbonImmutable("last monday of august {$year}"); + + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Asia/Manila'); + + return [ + 'Maundy Thursday' => $easter->subDays(3), + 'Good Friday' => $easter->subDays(2), + 'National Heroes Day' => $nationalHeroes, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap b/tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap new file mode 100644 index 000000000..0859fcf5e --- /dev/null +++ b/tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Maundy Thursday", + "date": "2024-03-28" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Araw ng Kagitingan", + "date": "2024-04-09" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Independence Day", + "date": "2024-06-12" + }, + { + "name": "National Heroes Day", + "date": "2024-08-26" + }, + { + "name": "Bonifacio Day", + "date": "2024-11-27" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Rizal Day", + "date": "2024-12-30" + } +] \ No newline at end of file diff --git a/tests/Countries/PhilippinesTest.php b/tests/Countries/PhilippinesTest.php new file mode 100644 index 000000000..4fd997173 --- /dev/null +++ b/tests/Countries/PhilippinesTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 02c180cf96d03be8d906b087bab467561b42d019 Mon Sep 17 00:00:00 2001 From: object505 Date: Fri, 19 Jan 2024 07:02:20 +0100 Subject: [PATCH 24/71] Add Macedonian holidays --- src/Countries/NorthMacedonia.php | 48 +++++++++++++++++++ .../it_can_calculate_macedonian_holidays.snap | 42 ++++++++++++++++ tests/Countries/NorthMacedoniaTest.php | 18 +++++++ 3 files changed, 108 insertions(+) create mode 100644 src/Countries/NorthMacedonia.php create mode 100644 tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap create mode 100644 tests/Countries/NorthMacedoniaTest.php diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php new file mode 100644 index 000000000..0ab6f07a1 --- /dev/null +++ b/src/Countries/NorthMacedonia.php @@ -0,0 +1,48 @@ + '01-01', + 'Божик, првиот ден на Божик според православниот календар' => '01-07', + 'Ден на трудот' => '05-01', + 'Св. Кирил и Методиј - Ден на сесловенските просветители' => '05-24', + 'Ден на Републиката' => '08-02', + 'Ден на независноста' => '09-08', + 'Ден на народното востание' => '10-11', + 'Ден на македонската револуционерна борба' => '10-23', + 'Св. Климент Охридски' => '12-08', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp($this->ortodoxEaster($year)) + ->setTimezone('Europe/Skopje'); + + return [ + 'Велигден, вториот ден на Велигден според православниот календар' => $easter->addDay(), + ]; + } + + protected function ortodoxEaster(int $year) + { + $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); + $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; + + return strtotime("+$daysDifference days", $timestamp); + } +} diff --git a/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap b/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap new file mode 100644 index 000000000..dfc694191 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "\u041d\u043e\u0432\u0430 \u0433\u043e\u0434\u0438\u043d\u0430", + "date": "2024-01-01" + }, + { + "name": "\u0411\u043e\u0436\u0438\u043a, \u043f\u0440\u0432\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0411\u043e\u0436\u0438\u043a \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440", + "date": "2024-01-07" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u0442\u0440\u0443\u0434\u043e\u0442", + "date": "2024-05-01" + }, + { + "name": "\u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d, \u0432\u0442\u043e\u0440\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440", + "date": "2024-05-06" + }, + { + "name": "\u0421\u0432. \u041a\u0438\u0440\u0438\u043b \u0438 \u041c\u0435\u0442\u043e\u0434\u0438\u0458 - \u0414\u0435\u043d \u043d\u0430 \u0441\u0435\u0441\u043b\u043e\u0432\u0435\u043d\u0441\u043a\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u0432\u0435\u0442\u0438\u0442\u0435\u043b\u0438", + "date": "2024-05-24" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u0420\u0435\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430", + "date": "2024-08-02" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u043d\u043e\u0441\u0442\u0430", + "date": "2024-09-08" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0430\u0440\u043e\u0434\u043d\u043e\u0442\u043e \u0432\u043e\u0441\u0442\u0430\u043d\u0438\u0435", + "date": "2024-10-11" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0430\u0442\u0430 \u0440\u0435\u0432\u043e\u043b\u0443\u0446\u0438\u043e\u043d\u0435\u0440\u043d\u0430 \u0431\u043e\u0440\u0431\u0430", + "date": "2024-10-23" + }, + { + "name": "\u0421\u0432. \u041a\u043b\u0438\u043c\u0435\u043d\u0442 \u041e\u0445\u0440\u0438\u0434\u0441\u043a\u0438", + "date": "2024-12-08" + } +] \ No newline at end of file diff --git a/tests/Countries/NorthMacedoniaTest.php b/tests/Countries/NorthMacedoniaTest.php new file mode 100644 index 000000000..b68507ff4 --- /dev/null +++ b/tests/Countries/NorthMacedoniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 97306d23c7f9904dae8b09eba70d7731bb516c0b Mon Sep 17 00:00:00 2001 From: Ricardo Martos Date: Fri, 19 Jan 2024 11:49:25 +0100 Subject: [PATCH 25/71] Add Venezuela country class and test This commit adds the `Venezuela` class to handle holidays in Venezuela. The class includes a method to calculate all fixed holidays and another method to calculate variable holidays based on Easter. Additionally, a test is added to ensure that the calculation of Venezuelan holidays is correct. --- src/Countries/Venezuela.php | 43 ++++++++++++++ .../it_can_calculate_venezuelan_holidays.snap | 58 +++++++++++++++++++ tests/Countries/VenezuelaTest.php | 18 ++++++ 3 files changed, 119 insertions(+) create mode 100644 src/Countries/Venezuela.php create mode 100644 tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap create mode 100644 tests/Countries/VenezuelaTest.php diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php new file mode 100644 index 000000000..804415069 --- /dev/null +++ b/src/Countries/Venezuela.php @@ -0,0 +1,43 @@ + '01-01', + 'Declaración de la Independencia' => '04-19', + 'Día del Trabajador' => '05-01', + 'Aniversario de la Batalla de Carabobo' => '06-24', + 'Día de la Independencia' => '07-05', + 'Natalicio de Simón Bolívar' => '07-24', + 'Día de la Resistencia Indígena' => '10-12', + 'Víspera de Navidad' => '12-24', + 'Navidad' => '12-25', + 'Día de Fin de Año' => '12-31', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)); + + return [ + 'Lunes de Carnaval' => $easter->subDays(47), + 'Martes de Carnaval' => $easter->subDays(46), + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap new file mode 100644 index 000000000..1c867bd69 --- /dev/null +++ b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "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": "Jueves Santo", + "date": "2024-03-27" + }, + { + "name": "Viernes Santo", + "date": "2024-03-28" + }, + { + "name": "Declaraci\u00f3n de la Independencia", + "date": "2024-04-19" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Aniversario de la Batalla de Carabobo", + "date": "2024-06-24" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-07-05" + }, + { + "name": "Natalicio de Sim\u00f3n Bol\u00edvar", + "date": "2024-07-24" + }, + { + "name": "D\u00eda de la Resistencia Ind\u00edgena", + "date": "2024-10-12" + }, + { + "name": "V\u00edspera de Navidad", + "date": "2024-12-24" + }, + { + "name": "Navidad", + "date": "2024-12-25" + }, + { + "name": "D\u00eda de Fin de A\u00f1o", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/Countries/VenezuelaTest.php b/tests/Countries/VenezuelaTest.php new file mode 100644 index 000000000..5b2cf5ea2 --- /dev/null +++ b/tests/Countries/VenezuelaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 3fc176f87d76fbbc2c9eca238ded0d8ff29a85af Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:12:30 +0100 Subject: [PATCH 26/71] Create pull_request_template.md --- .github/pull_request_template.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..fa520eceb --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,8 @@ +# Contributing a new country ? + +* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same country? + +1. Create a new class in the Countries directory. It should extend the Country class. +2. Add a test for the new country in the tests directory. +3. Run the tests so a snapshot gets created. +4. Verify the result in the newly created snapshot is correct. From bfeb53e07323824e1861b7f339469453c3c01322 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:14:24 +0100 Subject: [PATCH 27/71] Update pull_request_template.md --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index fa520eceb..9fb40912d 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,6 @@ # Contributing a new country ? -* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same country? +* [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/spatie/holidays/pulls) for the same country? 1. Create a new class in the Countries directory. It should extend the Country class. 2. Add a test for the new country in the tests directory. From 59d8ac1063dd5f8672006f513fd8a1e2a25e771a Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 12:22:16 +0000 Subject: [PATCH 28/71] Fix styling --- src/Countries/France.php | 4 ++-- tests/Countries/FranceTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 449d13f57..c948556f7 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -28,8 +28,8 @@ protected function allHolidays(int $year): array 'Armistice 1918' => '11-11', 'Noël' => '12-25', ], - $this->variableHolidays($year), - $this->regionHolidays()); + $this->variableHolidays($year), + $this->regionHolidays()); } /** @return array */ diff --git a/tests/Countries/FranceTest.php b/tests/Countries/FranceTest.php index e70d919be..358f8b1c0 100644 --- a/tests/Countries/FranceTest.php +++ b/tests/Countries/FranceTest.php @@ -3,8 +3,8 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Holidays; use Spatie\Holidays\Countries\France; +use Spatie\Holidays\Holidays; it('can calculate french holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); From 3435229acae9b41b413293c29b55ffef6ea9e45a Mon Sep 17 00:00:00 2001 From: vrerabek Date: Fri, 19 Jan 2024 13:23:20 +0100 Subject: [PATCH 29/71] Add Czech holidays (#22) * add: czech holidays * add: czechia test * remove: docblock --------- Co-authored-by: Vojtech Rerabek --- src/Countries/Czechia.php | 42 +++++++++++++++ .../it_can_calculate_czech_holidays.snap | 54 +++++++++++++++++++ tests/Countries/CzechiaTest.php | 18 +++++++ 3 files changed, 114 insertions(+) create mode 100644 src/Countries/Czechia.php create mode 100644 tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap create mode 100644 tests/Countries/CzechiaTest.php diff --git a/src/Countries/Czechia.php b/src/Countries/Czechia.php new file mode 100644 index 000000000..f0cce6f00 --- /dev/null +++ b/src/Countries/Czechia.php @@ -0,0 +1,42 @@ + '01-01', + 'Svátek práce' => '05-01', + 'Den vítězství' => '05-08', + 'Den slovanských věrozvěstů Cyrila a Metoděje' => '07-05', + 'Den upálení mistra Jana Husa' => '07-06', + 'Den české státnosti' => '09-28', + 'Den vzniku samostatného československého státu' => '10-28', + 'Den boje za svobodu a demokracii a Mezinárodní den studentstva' => '11-17', + 'Štědrý den' => '12-24', + '1. svátek vánoční' => '12-25', + '2. svátek vánoční' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Prague'); + + return [ + 'Velikonoční pondělí' => $easter->addDay(), + 'Velký pátek' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap b/tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap new file mode 100644 index 000000000..9e3ba56a8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Den obnovy samostatn\u00e9ho \u010desk\u00e9ho st\u00e1tu", + "date": "2024-01-01" + }, + { + "name": "Velk\u00fd p\u00e1tek", + "date": "2024-03-29" + }, + { + "name": "Velikono\u010dn\u00ed pond\u011bl\u00ed", + "date": "2024-04-01" + }, + { + "name": "Sv\u00e1tek pr\u00e1ce", + "date": "2024-05-01" + }, + { + "name": "Den v\u00edt\u011bzstv\u00ed", + "date": "2024-05-08" + }, + { + "name": "Den slovansk\u00fdch v\u011brozv\u011bst\u016f Cyrila a Metod\u011bje", + "date": "2024-07-05" + }, + { + "name": "Den up\u00e1len\u00ed mistra Jana Husa", + "date": "2024-07-06" + }, + { + "name": "Den \u010desk\u00e9 st\u00e1tnosti", + "date": "2024-09-28" + }, + { + "name": "Den vzniku samostatn\u00e9ho \u010deskoslovensk\u00e9ho st\u00e1tu", + "date": "2024-10-28" + }, + { + "name": "Den boje za svobodu a demokracii a Mezin\u00e1rodn\u00ed den studentstva", + "date": "2024-11-17" + }, + { + "name": "\u0160t\u011bdr\u00fd den", + "date": "2024-12-24" + }, + { + "name": "1. sv\u00e1tek v\u00e1no\u010dn\u00ed", + "date": "2024-12-25" + }, + { + "name": "2. sv\u00e1tek v\u00e1no\u010dn\u00ed", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/CzechiaTest.php b/tests/Countries/CzechiaTest.php new file mode 100644 index 000000000..a23bac978 --- /dev/null +++ b/tests/Countries/CzechiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); \ No newline at end of file From d3c6ad40b2d8740f36d6ca33ac0c0e0065c6e98d Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 12:23:46 +0000 Subject: [PATCH 30/71] Fix styling --- tests/Countries/CzechiaTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Countries/CzechiaTest.php b/tests/Countries/CzechiaTest.php index a23bac978..0a7ece2fa 100644 --- a/tests/Countries/CzechiaTest.php +++ b/tests/Countries/CzechiaTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); \ No newline at end of file +}); From b56fa3f616c0d807f9226d160ba08bd12abb4927 Mon Sep 17 00:00:00 2001 From: object505 Date: Fri, 19 Jan 2024 13:43:10 +0100 Subject: [PATCH 31/71] Added return type --- src/Countries/NorthMacedonia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 0ab6f07a1..81da2e27c 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -38,7 +38,7 @@ protected function variableHolidays(int $year): array ]; } - protected function ortodoxEaster(int $year) + protected function ortodoxEaster(int $year): bool|int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; From 0d5a8b1f0434fe23f218a6c34006ef5d7513e460 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 13:53:38 +0100 Subject: [PATCH 32/71] activate brazil --- src/Countries/Brazil.php | 2 -- tests/Countries/BrazilTest.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index a05dbbf44..e861e8872 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -13,8 +13,6 @@ public function countryCode(): string protected function allHolidays(int $year): array { - throw new \Exception('Not implemented yet.'); - return array_merge([ 'Dia de Ano Novo' => '01-01', 'Dia de Tiradentes' => '04-21', diff --git a/tests/Countries/BrazilTest.php b/tests/Countries/BrazilTest.php index a91509ffb..91be74d40 100644 --- a/tests/Countries/BrazilTest.php +++ b/tests/Countries/BrazilTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -})->skip('Still an issue'); +}); From fa1c9cdb842141e3662a9ee98cce0b0e5318812b Mon Sep 17 00:00:00 2001 From: Joel Crawford Date: Fri, 19 Jan 2024 13:49:45 +0300 Subject: [PATCH 33/71] Added Uganda holidays and Tests --- src/Countries/Uganda.php | 56 +++++++++++++++++++ .../it_can_calculate_ugandan_holidays.snap | 50 +++++++++++++++++ tests/Countries/UgandaTest.php | 18 ++++++ 3 files changed, 124 insertions(+) create mode 100644 src/Countries/Uganda.php create mode 100644 tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap create mode 100644 tests/Countries/UgandaTest.php diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php new file mode 100644 index 000000000..023d20b79 --- /dev/null +++ b/src/Countries/Uganda.php @@ -0,0 +1,56 @@ + Github: LinkedIn: + */ + +namespace Spatie\Holidays\Countries; + +use Carbon\CarbonImmutable; + +class Uganda extends Country +{ + + public function countryCode(): string + { + return 'ug'; + } + + /** + * @inheritDoc + */ + protected function allHolidays(int $year): array + { + + /** + * 'New Year' => '01-01', Format:: Month-Date + */ + return array_merge([ + 'New Year' => '01-01', + 'NRM Liberation Day' => '01-26', + 'Archbishop Janani Luwum Day' => '02-16', + 'International Womens Day' => '03-08', + 'Labour Day' => '05-01', + 'Martyrs Day' => '06-03', + 'National Hereos Day' => '06-09', + 'Independence Day' => '10-09', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + /** + * @param int $year + * + * @return array + */ + private function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + return [ + "Good Friday" => $easter->subDays(2), + "Easter Monday" => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap new file mode 100644 index 000000000..35276c507 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "New Year", + "date": "2024-01-01" + }, + { + "name": "NRM Liberation Day", + "date": "2024-01-26" + }, + { + "name": "Archbishop Janani Luwum Day", + "date": "2024-02-16" + }, + { + "name": "International Womens Day", + "date": "2024-03-08" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Martyrs Day", + "date": "2024-06-03" + }, + { + "name": "National Hereos Day", + "date": "2024-06-09" + }, + { + "name": "Independence Day", + "date": "2024-10-09" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/UgandaTest.php b/tests/Countries/UgandaTest.php new file mode 100644 index 000000000..82ab1f7f6 --- /dev/null +++ b/tests/Countries/UgandaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 770958caad55cad9affd368fff609a45e467871b Mon Sep 17 00:00:00 2001 From: Joel Crawford Date: Fri, 19 Jan 2024 15:55:55 +0300 Subject: [PATCH 34/71] Fixed::Name having ' on it --- src/Countries/Uganda.php | 20 +++++++++---------- .../it_can_calculate_ugandan_holidays.snap | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 023d20b79..635b1b296 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -27,16 +27,16 @@ protected function allHolidays(int $year): array * 'New Year' => '01-01', Format:: Month-Date */ return array_merge([ - 'New Year' => '01-01', - 'NRM Liberation Day' => '01-26', - 'Archbishop Janani Luwum Day' => '02-16', - 'International Womens Day' => '03-08', - 'Labour Day' => '05-01', - 'Martyrs Day' => '06-03', - 'National Hereos Day' => '06-09', - 'Independence Day' => '10-09', - 'Christmas Day' => '12-25', - 'Boxing Day' => '12-26', + "New Year's Day" => "01-01", + "NRM Liberation Day" => "01-26", + "Archbishop Janani Luwum Day" => "02-16", + "International Women's Day" => "03-08", + "Labour Day" => "05-01", + "Martyrs' Day" => "06-03", + "National Hereos Day" => "06-09", + "Independence Day" => "10-09", + "Christmas Day" => "12-25", + "Boxing Day" => "12-26", ], $this->variableHolidays($year)); } diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap index 35276c507..ff3733180 100644 --- a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap @@ -1,6 +1,6 @@ [ { - "name": "New Year", + "name": "New Year's Day", "date": "2024-01-01" }, { @@ -12,7 +12,7 @@ "date": "2024-02-16" }, { - "name": "International Womens Day", + "name": "International Women's Day", "date": "2024-03-08" }, { @@ -28,7 +28,7 @@ "date": "2024-05-01" }, { - "name": "Martyrs Day", + "name": "Martyrs' Day", "date": "2024-06-03" }, { From 175ce21f1f7b2cee767a74bdcf09ba97ae3d754c Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:18:39 +0100 Subject: [PATCH 35/71] calculate correct easter date --- src/Countries/Andorra.php | 3 +-- src/Countries/Austria.php | 3 +-- src/Countries/Belgium.php | 3 +-- src/Countries/Brazil.php | 2 +- src/Countries/Country.php | 7 +++++++ src/Countries/Czechia.php | 3 +-- src/Countries/Denmark.php | 3 +-- src/Countries/France.php | 3 +-- src/Countries/Hungary.php | 3 +-- src/Countries/Italy.php | 3 +-- src/Countries/Netherlands.php | 3 +-- src/Countries/Portugal.php | 3 +-- src/Countries/Zambia.php | 3 +-- .../BrazilTest/it_can_calculate_brazil_holidays.snap | 4 ++++ 14 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Countries/Andorra.php b/src/Countries/Andorra.php index 51615e690..89ce91c80 100644 --- a/src/Countries/Andorra.php +++ b/src/Countries/Andorra.php @@ -30,8 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + $easter = $this->easter($year); return [ 'Divendres Sant' => $easter->subDays(2), diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index 73fb61285..5041c401d 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -34,8 +34,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Vienna'); + $easter = $this->easter($year); return [ 'Ostermontag' => $easter->addDay(), diff --git a/src/Countries/Belgium.php b/src/Countries/Belgium.php index af52b6810..8710daf74 100644 --- a/src/Countries/Belgium.php +++ b/src/Countries/Belgium.php @@ -27,8 +27,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + $easter = $this->easter($year); return [ 'Paasmaandag' => $easter->addDay(), diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index e861e8872..d2be75a23 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -29,7 +29,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('America/Sao_Paulo'); + $easter = $this->easter($year); return [ 'Carnaval' => $easter->subDays(47), diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 8b75b8dfd..2c5547021 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -40,6 +40,13 @@ public static function make(): static return new static(...func_get_args()); } + protected function easter(string $year): CarbonImmutable + { + $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21"); + + return $easter->addDays(easter_days($year)); + } + public static function find(string $countryCode): ?Country { $countryCode = strtolower($countryCode); diff --git a/src/Countries/Czechia.php b/src/Countries/Czechia.php index f0cce6f00..c4aff4200 100644 --- a/src/Countries/Czechia.php +++ b/src/Countries/Czechia.php @@ -31,8 +31,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Prague'); + $easter = $this->easter($year); return [ 'Velikonoční pondělí' => $easter->addDay(), diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 66d2113a6..ee68d1d74 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -24,8 +24,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Copenhagen'); + $easter = $this->easter($year); $holidays = [ 'Påskedag' => $easter->addDay(), diff --git a/src/Countries/France.php b/src/Countries/France.php index c948556f7..c0272aabb 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -35,8 +35,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Paris'); + $easter = $this->easter($year); $holidays = [ 'Lundi de Pâques' => $easter->addDay(), diff --git a/src/Countries/Hungary.php b/src/Countries/Hungary.php index 15a46e997..9658c3809 100644 --- a/src/Countries/Hungary.php +++ b/src/Countries/Hungary.php @@ -28,8 +28,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + $easter = $this->easter($year); return [ 'Nagypéntek' => $easter->subDays(2), diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php index 169533aeb..e4f53b092 100644 --- a/src/Countries/Italy.php +++ b/src/Countries/Italy.php @@ -30,8 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Rome'); + $easter = $this->easter($year); return [ 'Lunedì di Pasqua' => $easter->addDay(), diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index b694c25cc..91abc9bd1 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -30,8 +30,7 @@ protected function variableHolidays(int $year): array $koningsDag = $koningsDag->subDay(); } - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Amsterdam'); + $easter = $this->easter($year); return [ 'Koningsdag' => $koningsDag, diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 4525591d9..98c09b0a3 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -30,8 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Lisbon'); + $easter = $this->easter($year); return [ 'Páscoa' => $easter, diff --git a/src/Countries/Zambia.php b/src/Countries/Zambia.php index 14112e6ea..c8802a90f 100644 --- a/src/Countries/Zambia.php +++ b/src/Countries/Zambia.php @@ -33,8 +33,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Africa/Lusaka'); + $easter = $this->easter($year); return [ 'Good Friday' => $easter->subDays(2), diff --git a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap index 5be3e640f..eeaf05a79 100644 --- a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap +++ b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap @@ -39,6 +39,10 @@ "name": "Proclama\u00e7\u00e3o da Rep\u00fablica", "date": "2024-11-15" }, + { + "name": "Dia Nacional de Zumbi e da Consci\u00eancia Negra", + "date": "2024-11-20" + }, { "name": "Natal", "date": "2024-12-25" From a7cf77b5bd0df48a05d9e7cea1becab057f5ae44 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:21:46 +0000 Subject: [PATCH 36/71] Fix styling --- src/Countries/Uganda.php | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 635b1b296..8673698d9 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -11,46 +11,44 @@ class Uganda extends Country { - public function countryCode(): string { return 'ug'; } /** - * @inheritDoc + * {@inheritDoc} */ protected function allHolidays(int $year): array { - /** - * 'New Year' => '01-01', Format:: Month-Date - */ + /** + * 'New Year' => '01-01', Format:: Month-Date + */ return array_merge([ - "New Year's Day" => "01-01", - "NRM Liberation Day" => "01-26", - "Archbishop Janani Luwum Day" => "02-16", - "International Women's Day" => "03-08", - "Labour Day" => "05-01", - "Martyrs' Day" => "06-03", - "National Hereos Day" => "06-09", - "Independence Day" => "10-09", - "Christmas Day" => "12-25", - "Boxing Day" => "12-26", + "New Year's Day" => '01-01', + 'NRM Liberation Day' => '01-26', + 'Archbishop Janani Luwum Day' => '02-16', + "International Women's Day" => '03-08', + 'Labour Day' => '05-01', + "Martyrs' Day" => '06-03', + 'National Hereos Day' => '06-09', + 'Independence Day' => '10-09', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', ], $this->variableHolidays($year)); } /** - * @param int $year - * * @return array */ private function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + return [ - "Good Friday" => $easter->subDays(2), - "Easter Monday" => $easter->addDay(), + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), ]; } } From bb5af7796a0ef3df64b1c5c415767be2f8d9ee02 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:22:22 +0000 Subject: [PATCH 37/71] Fix styling --- src/Countries/Venezuela.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php index 804415069..bda60ac97 100644 --- a/src/Countries/Venezuela.php +++ b/src/Countries/Venezuela.php @@ -2,7 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\Carbon; use Carbon\CarbonImmutable; class Venezuela extends Country From ee7e06c860b143d3cbd01405bd29e5a6068c2d01 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:22:47 +0000 Subject: [PATCH 38/71] Fix styling --- src/Countries/NorthMacedonia.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 81da2e27c..0d4a447ff 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -6,7 +6,6 @@ class NorthMacedonia extends Country { - public function countryCode(): string { return 'mk'; @@ -41,7 +40,7 @@ protected function variableHolidays(int $year): array protected function ortodoxEaster(int $year): bool|int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); - $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; + $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; return strtotime("+$daysDifference days", $timestamp); } From 57cc97876f6b112caedc7d1aab6361898cce3519 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:27:08 +0000 Subject: [PATCH 39/71] Fix styling --- src/Countries/Mexico.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 9c85f5231..db745960d 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -35,16 +35,15 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { - $natalicioBenitoJuarez = new CarbonImmutable(sprintf("third monday of march %s", $year)); - $promulgacionConstitucion = new CarbonImmutable(sprintf("first monday of february %s", $year)); + $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'); } - $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); - + $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'), @@ -56,22 +55,21 @@ protected function variableHolidays(int $year): array if ($this->transmisionPoderEjecutivoFederal($year)) { $days[ - "Transmisión del Poder Ejecutivo Federal" + 'Transmisión del Poder Ejecutivo Federal' ] = $this->transmisionPoderEjecutivoFederal($year); } return $days; } - protected function transmisionPoderEjecutivoFederal($year): bool|string { $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)); + ->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; @@ -80,8 +78,9 @@ protected function transmisionPoderEjecutivoFederal($year): bool|string $availableDates = $period->toArray(); if (count($availableDates)) { - return $availableDates[0]->format("m-d"); + return $availableDates[0]->format('m-d'); } + return false; } } From 7aa889b13da34ac68f09c55803278ff76e99af51 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:31:46 +0100 Subject: [PATCH 40/71] wip --- src/Countries/Nicaragua.php | 3 +-- src/Countries/NorthMacedonia.php | 4 ++-- src/Countries/Philippines.php | 3 +-- src/Countries/Uganda.php | 12 ------------ src/Countries/Venezuela.php | 2 +- 5 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/Countries/Nicaragua.php b/src/Countries/Nicaragua.php index 8614270b6..32837f3cb 100644 --- a/src/Countries/Nicaragua.php +++ b/src/Countries/Nicaragua.php @@ -28,8 +28,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('America/Managua'); + $easter = $this->easter($year); return [ 'Jueves santo' => $easter->subDays(3), diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 0d4a447ff..4ae2e25b2 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -29,7 +29,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp($this->ortodoxEaster($year)) + $easter = CarbonImmutable::createFromTimestamp($this->orthodoxEaster($year)) ->setTimezone('Europe/Skopje'); return [ @@ -37,7 +37,7 @@ protected function variableHolidays(int $year): array ]; } - protected function ortodoxEaster(int $year): bool|int + protected function orthodoxEaster(int $year): bool|int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; diff --git a/src/Countries/Philippines.php b/src/Countries/Philippines.php index dd4cf848e..c4d193e82 100644 --- a/src/Countries/Philippines.php +++ b/src/Countries/Philippines.php @@ -29,8 +29,7 @@ protected function variableHolidays(int $year): array { $nationalHeroes = new CarbonImmutable("last monday of august {$year}"); - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Asia/Manila'); + $easter = $this->easter($year); return [ 'Maundy Thursday' => $easter->subDays(3), diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 8673698d9..90a0af5bf 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -1,9 +1,4 @@ Github: LinkedIn: - */ namespace Spatie\Holidays\Countries; @@ -16,15 +11,8 @@ public function countryCode(): string return 'ug'; } - /** - * {@inheritDoc} - */ protected function allHolidays(int $year): array { - - /** - * 'New Year' => '01-01', Format:: Month-Date - */ return array_merge([ "New Year's Day" => '01-01', 'NRM Liberation Day' => '01-26', diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php index bda60ac97..01edb601f 100644 --- a/src/Countries/Venezuela.php +++ b/src/Countries/Venezuela.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)); + $easter = $this->easter($year); return [ 'Lunes de Carnaval' => $easter->subDays(47), From a16832ec12f3376d4cc4c29b18d696f88cc7919c Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:39:13 +0100 Subject: [PATCH 41/71] fix test --- src/Countries/Mexico.php | 2 +- .../it_can_calculate_mexico_holidays.snap | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index db745960d..78effd740 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -6,7 +6,7 @@ use Carbon\CarbonImmutable; use Carbon\CarbonPeriod; -class Netherlands extends Country +class Mexico extends Country { public function countryCode(): string { diff --git a/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap b/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap new file mode 100644 index 000000000..ecafb2e00 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap @@ -0,0 +1,66 @@ +[ + { + "name": "A\u00f1o nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda de la Candelaria", + "date": "2024-02-02" + }, + { + "name": "Aniversario de la promulgaci\u00f3n de la Constituci\u00f3n de 1917", + "date": "2024-02-05" + }, + { + "name": "D\u00eda de la Bandera", + "date": "2024-02-24" + }, + { + "name": "Natalicio de Benito Ju\u00e1rez", + "date": "2024-03-18" + }, + { + "name": "D\u00eda del Ni\u00f1o", + "date": "2024-04-30" + }, + { + "name": "D\u00eda de la Madre", + "date": "2024-04-30" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "D\u00eda del Padre", + "date": "2024-06-16" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-09-15" + }, + { + "name": "Transmisi\u00f3n del Poder Ejecutivo Federal", + "date": "2024-10-01" + }, + { + "name": "D\u00eda de la Raza", + "date": "2024-10-12" + }, + { + "name": "D\u00eda de Muertos", + "date": "2024-11-02" + }, + { + "name": "Revoluci\u00f3n Mexicana", + "date": "2024-11-19" + }, + { + "name": "Virgen de Guadalupe", + "date": "2024-12-12" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file From 6f213c1fd9dc9556c8a375ee36b12aced6d975a1 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:45:44 +0100 Subject: [PATCH 42/71] wip --- src/Countries/Country.php | 3 ++- src/Countries/Venezuela.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 2c5547021..9416ca65e 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -42,7 +42,8 @@ public static function make(): static protected function easter(string $year): CarbonImmutable { - $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21"); + $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21") + ->startOfDay(); return $easter->addDays(easter_days($year)); } diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php index 01edb601f..10082f44d 100644 --- a/src/Countries/Venezuela.php +++ b/src/Countries/Venezuela.php @@ -33,8 +33,8 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); return [ - 'Lunes de Carnaval' => $easter->subDays(47), - 'Martes de Carnaval' => $easter->subDays(46), + 'Lunes de Carnaval' => $easter->subDays(48), + 'Martes de Carnaval' => $easter->subDays(42), 'Jueves Santo' => $easter->subDays(3), 'Viernes Santo' => $easter->subDays(2), ]; From 376ffa0038bf2087ba016473ab65af47eaaab407 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:46:12 +0000 Subject: [PATCH 43/71] Fix styling --- src/Countries/Country.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 9416ca65e..82d5d8827 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -43,7 +43,7 @@ public static function make(): static protected function easter(string $year): CarbonImmutable { $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21") - ->startOfDay(); + ->startOfDay(); return $easter->addDays(easter_days($year)); } From 90b1c713899f1e754d21467cd054b97efd8df946 Mon Sep 17 00:00:00 2001 From: Marc Hanlon Date: Fri, 19 Jan 2024 14:27:22 +0000 Subject: [PATCH 44/71] Add support for Irish public holidays (#44) * Add support for Irish public holidays * Add logic that St Brigid's only started from 2023 * Add tests for St Brigid's Day St Brigids Day is a new holiday in 2023 and it is variable so adding tests around the logic * Apply PSR12 formatting --- src/Countries/Ireland.php | 54 +++++++++++++++++++ .../it_can_calculate_irish_holidays.snap | 42 +++++++++++++++ tests/Countries/IrelandTest.php | 29 ++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/Countries/Ireland.php create mode 100644 tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap create mode 100644 tests/Countries/IrelandTest.php diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php new file mode 100644 index 000000000..a75428ce4 --- /dev/null +++ b/src/Countries/Ireland.php @@ -0,0 +1,54 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'New Year\'s Day' => '01-01', + 'Saint Patrick\'s Day' => '03-17', + 'Christmas Day' => '12-25', + 'Saint Stephen\'s Day' => '12-26' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Europe/Dublin'); + $mayHoliday = new CarbonImmutable("first monday of May $year", 'Europe/Dublin'); + $juneHoliday = new CarbonImmutable("first monday of June $year", 'Europe/Dublin'); + $augHoliday = new CarbonImmutable("first monday of August $year", 'Europe/Dublin'); + $octHoliday = new CarbonImmutable("last monday of October $year", 'Europe/Dublin'); + + $variableHolidays = [ + 'Easter Monday' => $easter->addDays(1), + 'May Public Holiday' => $mayHoliday, + 'June Public Holiday' => $juneHoliday, + 'August Public Holiday' => $augHoliday, + 'October Public Holiday' => $octHoliday + ]; + + // In 2023, Ireland added a new public holiday for St Brigid's day. + // It is the First Monday in February, or 1 February if the date falls on a Friday + if ($year >= 2023) { + $stBrigidsDay = new CarbonImmutable("$year-02-01", 'Europe/Dublin'); + if (!$stBrigidsDay->isFriday()) { + $stBrigidsDay = new CarbonImmutable("first monday of February $year", 'Europe/Dublin'); + } + $variableHolidays['St Brigid\'s Day'] = $stBrigidsDay; + } + + return $variableHolidays; + } +} diff --git a/tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap b/tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap new file mode 100644 index 000000000..5d241806a --- /dev/null +++ b/tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "St Brigid's Day", + "date": "2024-02-05" + }, + { + "name": "Saint Patrick's Day", + "date": "2024-03-17" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Public Holiday", + "date": "2024-05-06" + }, + { + "name": "June Public Holiday", + "date": "2024-06-03" + }, + { + "name": "August Public Holiday", + "date": "2024-08-05" + }, + { + "name": "October Public Holiday", + "date": "2024-10-28" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Saint Stephen's Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/IrelandTest.php b/tests/Countries/IrelandTest.php new file mode 100644 index 000000000..6ed63548f --- /dev/null +++ b/tests/Countries/IrelandTest.php @@ -0,0 +1,29 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate St Bridid\'s day in Ireland', function () { + // In 2022, there was no St Brigid's Day + expect(Holidays::for(country: 'ie')->isHoliday('2022-02-07'))->toBe(false); + + // In 2023, it was on Monday 6th Feb + expect(Holidays::for(country: 'ie')->isHoliday('2023-02-06'))->toBe(true); + + // In 2030, it will fall on Friday 1st Feb + expect(Holidays::for(country: 'ie')->isHoliday('2030-02-01'))->toBe(true); +}); From 6ac1047b03bc284e9b15e56db1803d6717505a1a Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 14:27:41 +0000 Subject: [PATCH 45/71] Fix styling --- src/Countries/Ireland.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index a75428ce4..6d3c53b1e 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -18,7 +18,7 @@ protected function allHolidays(int $year): array 'New Year\'s Day' => '01-01', 'Saint Patrick\'s Day' => '03-17', 'Christmas Day' => '12-25', - 'Saint Stephen\'s Day' => '12-26' + 'Saint Stephen\'s Day' => '12-26', ], $this->variableHolidays($year)); } @@ -36,14 +36,14 @@ protected function variableHolidays(int $year): array 'May Public Holiday' => $mayHoliday, 'June Public Holiday' => $juneHoliday, 'August Public Holiday' => $augHoliday, - 'October Public Holiday' => $octHoliday + 'October Public Holiday' => $octHoliday, ]; // In 2023, Ireland added a new public holiday for St Brigid's day. // It is the First Monday in February, or 1 February if the date falls on a Friday if ($year >= 2023) { $stBrigidsDay = new CarbonImmutable("$year-02-01", 'Europe/Dublin'); - if (!$stBrigidsDay->isFriday()) { + if (! $stBrigidsDay->isFriday()) { $stBrigidsDay = new CarbonImmutable("first monday of February $year", 'Europe/Dublin'); } $variableHolidays['St Brigid\'s Day'] = $stBrigidsDay; From 74fc042d6c669cd347e7b74aa76395f0d9a4892b Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:53:46 +0100 Subject: [PATCH 46/71] use better easter calculation for Ireland --- src/Countries/Ireland.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 6d3c53b1e..527cd487e 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'ie'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -25,7 +24,8 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Europe/Dublin'); + $easter = $this->easter($year); + $mayHoliday = new CarbonImmutable("first monday of May $year", 'Europe/Dublin'); $juneHoliday = new CarbonImmutable("first monday of June $year", 'Europe/Dublin'); $augHoliday = new CarbonImmutable("first monday of August $year", 'Europe/Dublin'); From e5364ec239802c54b4d9041b806cc24f80298509 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:56:50 +0100 Subject: [PATCH 47/71] use correct dates for nicaragua and venezuela --- .../NicaraguaTest/it_can_calculate_nicaragua_holidays.snap | 4 ++-- .../VenezuelaTest/it_can_calculate_venezuelan_holidays.snap | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap index 572176fc8..b92235be0 100644 --- a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap +++ b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap @@ -5,11 +5,11 @@ }, { "name": "Jueves santo", - "date": "2024-03-27" + "date": "2024-03-28" }, { "name": "Viernes santo", - "date": "2024-03-28" + "date": "2024-03-29" }, { "name": "D\u00eda internacional de los trabajadores", diff --git a/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap index 1c867bd69..dd3850a4b 100644 --- a/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap +++ b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap @@ -9,15 +9,15 @@ }, { "name": "Martes de Carnaval", - "date": "2024-02-13" + "date": "2024-02-18" }, { "name": "Jueves Santo", - "date": "2024-03-27" + "date": "2024-03-28" }, { "name": "Viernes Santo", - "date": "2024-03-28" + "date": "2024-03-29" }, { "name": "Declaraci\u00f3n de la Independencia", From 92cb7bc7133853b6b6ad58ac899e057721406aff Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:13:19 +0100 Subject: [PATCH 48/71] cleanup --- src/Countries/Austria.php | 5 ----- src/Countries/Country.php | 2 +- src/Countries/Mexico.php | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index 5041c401d..36ddb41b2 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -6,11 +6,6 @@ class Austria extends Country { - protected function __construct( - public ?string $region = null - ) { - } - public function countryCode(): string { return 'at'; diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 82d5d8827..1c74eb6e1 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -40,7 +40,7 @@ public static function make(): static return new static(...func_get_args()); } - protected function easter(string $year): CarbonImmutable + protected function easter(int $year): CarbonImmutable { $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21") ->startOfDay(); diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 78effd740..21b25f104 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -13,7 +13,6 @@ public function countryCode(): string return 'mx'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 6871df527478210c386da0f8cdb73954f39c0d67 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:15:06 +0100 Subject: [PATCH 49/71] move to baseline --- phpstan-baseline.neon | 21 ++++++++++++++++++--- src/Countries/NorthMacedonia.php | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 51b9330fc..7de51241d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,12 +1,12 @@ parameters: ignoreErrors: - - message: "#^Unreachable statement \\- code above always terminates\\.$#" + message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 - path: src/Countries/Brazil.php + path: src/Countries/Country.php - - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" + message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 path: src/Countries/Country.php @@ -20,6 +20,21 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Cannot call method setTimezone\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 1 + path: src/Countries/Mexico.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:transmisionPoderEjecutivoFederal\\(\\) has parameter \\$year with no type specified\\.$#" + count: 1 + path: src/Countries/Mexico.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" + count: 1 + path: src/Countries/Mexico.php + - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 4ae2e25b2..9865e3c3c 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -37,11 +37,11 @@ protected function variableHolidays(int $year): array ]; } - protected function orthodoxEaster(int $year): bool|int + protected function orthodoxEaster(int $year): int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - return strtotime("+$daysDifference days", $timestamp); + return (int) strtotime("+$daysDifference days", $timestamp); } } From 872e6d15d9f3795031e93b70c6a473f2d78fbc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frano=20Bara=C4=87?= Date: Fri, 19 Jan 2024 16:19:42 +0100 Subject: [PATCH 50/71] Add support for Croatian public holidays (#45) * adds croatian holidays * stan fixes * fixed allHolidays return type --- src/Countries/Croatia.php | 43 +++++++++++++++ .../it_can_calculate_croatian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/CroatiaTest.php | 18 +++++++ 3 files changed, 115 insertions(+) create mode 100644 src/Countries/Croatia.php create mode 100644 tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap create mode 100644 tests/Countries/CroatiaTest.php diff --git a/src/Countries/Croatia.php b/src/Countries/Croatia.php new file mode 100644 index 000000000..d95906f74 --- /dev/null +++ b/src/Countries/Croatia.php @@ -0,0 +1,43 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Nova godina' => '01-01', + 'Bogojavljenje' => '01-06', + 'Praznik rada' => '05-01', + 'Dan državnosti' => '05-30', + 'Dan antifašističke borbe' => '06-22', + 'Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja' => '08-05', + 'Velika Gospa' => '08-15', + 'Svi sveti' => '11-01', + 'Dan sjećanja na žrtve Domovinskog rata i Dan sjećanja na žrtvu Vukovara i Škabrnje' => '11-18', + 'Božić' => '12-25', + 'Sveti Stjepan' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Zagreb'); + + return [ + 'Uskrsni ponedjeljak' => $easter->addDay(), + 'Tijelovo' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap new file mode 100644 index 000000000..821ad7073 --- /dev/null +++ b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Nova godina", + "date": "2024-01-01" + }, + { + "name": "Bogojavljenje", + "date": "2024-01-06" + }, + { + "name": "Uskrsni ponedjeljak", + "date": "2024-04-01" + }, + { + "name": "Praznik rada", + "date": "2024-05-01" + }, + { + "name": "Tijelovo", + "date": "2024-05-30" + }, + { + "name": "Dan dr\u017eavnosti", + "date": "2024-05-30" + }, + { + "name": "Dan antifa\u0161isti\u010dke borbe", + "date": "2024-06-22" + }, + { + "name": "Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja", + "date": "2024-08-05" + }, + { + "name": "Velika Gospa", + "date": "2024-08-15" + }, + { + "name": "Svi sveti", + "date": "2024-11-01" + }, + { + "name": "Dan sje\u0107anja na \u017ertve Domovinskog rata i Dan sje\u0107anja na \u017ertvu Vukovara i \u0160kabrnje", + "date": "2024-11-18" + }, + { + "name": "Bo\u017ei\u0107", + "date": "2024-12-25" + }, + { + "name": "Sveti Stjepan", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/CroatiaTest.php b/tests/Countries/CroatiaTest.php new file mode 100644 index 000000000..a78f5258a --- /dev/null +++ b/tests/Countries/CroatiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From a6b61d774aa8db721c00634952ead8639023eca6 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:23:47 +0100 Subject: [PATCH 51/71] use easter() instead --- src/Countries/Croatia.php | 4 +--- .../it_can_calculate_croatian_holidays.snap | 4 ++-- tests/Countries/AustriaTest.php | 12 ------------ 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Countries/Croatia.php b/src/Countries/Croatia.php index d95906f74..f5d7b7c8f 100644 --- a/src/Countries/Croatia.php +++ b/src/Countries/Croatia.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'hr'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -32,8 +31,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Zagreb'); + $easter = $this->easter($year); return [ 'Uskrsni ponedjeljak' => $easter->addDay(), diff --git a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap index 821ad7073..206f07845 100644 --- a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap +++ b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap @@ -16,11 +16,11 @@ "date": "2024-05-01" }, { - "name": "Tijelovo", + "name": "Dan dr\u017eavnosti", "date": "2024-05-30" }, { - "name": "Dan dr\u017eavnosti", + "name": "Tijelovo", "date": "2024-05-30" }, { diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 3473abef1..747943069 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -17,15 +17,3 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - -it('can calculate austrian holidays with region holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); - - $holidays = Holidays::for(Austria::make('bg'))->get(); - - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); - - expect(formatDates($holidays))->toMatchSnapshot(); -})->skip('Austria class has to be extended with regions first.'); From b985b90749faf6ce9391ec3540f1a0c7958a333d Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 15:24:06 +0000 Subject: [PATCH 52/71] Fix styling --- tests/Countries/AustriaTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 747943069..9018307f2 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Countries\Austria; use Spatie\Holidays\Holidays; it('can calculate austrian holidays', function () { From b4cdb9cf851b36448a3abd98be02dc83f8446757 Mon Sep 17 00:00:00 2001 From: rats4final <80012704+rats4final@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:26:58 -0400 Subject: [PATCH 53/71] Bolivian holidays (#40) * feature: add bolivian holidays * test: add bolivia test * test snap * fixed typo and phpstan * calculate correct easter date * Fix styling --------- Co-authored-by: rats4final Co-authored-by: rats4final --- src/Countries/Bolivia.php | 39 ++++++++++++++++ .../it_can_calculate_bolivian_holidays.snap | 46 +++++++++++++++++++ tests/Countries/BoliviaTest.php | 18 ++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/Countries/Bolivia.php create mode 100644 tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap create mode 100644 tests/Countries/BoliviaTest.php diff --git a/src/Countries/Bolivia.php b/src/Countries/Bolivia.php new file mode 100644 index 000000000..977d9bfa1 --- /dev/null +++ b/src/Countries/Bolivia.php @@ -0,0 +1,39 @@ + '01-01', + 'Día del Estado Plurinacional' => '01-22', + 'Día del Trabajador' => '05-01', + 'Año Nuevo Aymara' => '06-21', + 'Día de la Independencia' => '08-06', + 'Día de Todos los Santos' => '11-02', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter((string) $year); + + return [ + 'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6), + 'Martes de Carnaval' => $easter->subWeeks(6)->subDays(5), + 'Viernes Santo' => $easter->subDays(2), + 'Corpus Christi' => $easter->addWeeks(8)->addDays(4), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap b/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap new file mode 100644 index 000000000..c169618cb --- /dev/null +++ b/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "D\u00eda de A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda del Estado Plurinacional", + "date": "2024-01-22" + }, + { + "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 Trabajador", + "date": "2024-05-01" + }, + { + "name": "Corpus Christi", + "date": "2024-05-30" + }, + { + "name": "A\u00f1o Nuevo Aymara", + "date": "2024-06-21" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-08-06" + }, + { + "name": "D\u00eda de Todos los Santos", + "date": "2024-11-02" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BoliviaTest.php b/tests/Countries/BoliviaTest.php new file mode 100644 index 000000000..e1305657f --- /dev/null +++ b/tests/Countries/BoliviaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); + +}); From dc932c8ffcd4837b9dbc32e6808867ed9f965d2d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:27:30 +0100 Subject: [PATCH 54/71] remove unneeded conversion --- src/Countries/Bolivia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Bolivia.php b/src/Countries/Bolivia.php index 977d9bfa1..94072ed08 100644 --- a/src/Countries/Bolivia.php +++ b/src/Countries/Bolivia.php @@ -27,7 +27,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter((string) $year); + $easter = $this->easter($year); return [ 'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6), From aad7d49f19f46c9d43383b533fe89f0954643623 Mon Sep 17 00:00:00 2001 From: Jaanus Vapper Date: Fri, 19 Jan 2024 17:46:23 +0200 Subject: [PATCH 55/71] Add Estonian holidays (#47) * Add Estonian holidays * Use easter() method for easter date --- src/Countries/Estonia.php | 40 +++++++++++++++ .../it_can_calculate_estonian_holidays.snap | 50 +++++++++++++++++++ tests/Countries/EstoniaTest.php | 18 +++++++ 3 files changed, 108 insertions(+) create mode 100644 src/Countries/Estonia.php create mode 100644 tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap create mode 100644 tests/Countries/EstoniaTest.php diff --git a/src/Countries/Estonia.php b/src/Countries/Estonia.php new file mode 100644 index 000000000..4ba7efcdc --- /dev/null +++ b/src/Countries/Estonia.php @@ -0,0 +1,40 @@ + '01-01', + 'Iseseisvuspäev' => '02-24', + 'Kevadpüha' => '05-01', + 'Võidupüha' => '06-23', + 'Jaanipäev' => '06-24', + 'Taasiseseisvumispäev' => '08-20', + 'Jõululaupäev' => '12-24', + 'Esimene jõulupüha' => '12-25', + 'Teine jõulupüha' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Suur reede' => $easter->subDays(2), + 'Ülestõusmispühade 1. püha' => $easter, + 'Nelipühade 1. püha' => $easter->addDays(49), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap b/tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap new file mode 100644 index 000000000..bbd7f3c12 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Uusaasta", + "date": "2024-01-01" + }, + { + "name": "Iseseisvusp\u00e4ev", + "date": "2024-02-24" + }, + { + "name": "Suur reede", + "date": "2024-03-29" + }, + { + "name": "\u00dclest\u00f5usmisp\u00fchade 1. p\u00fcha", + "date": "2024-03-31" + }, + { + "name": "Kevadp\u00fcha", + "date": "2024-05-01" + }, + { + "name": "Nelip\u00fchade 1. p\u00fcha", + "date": "2024-05-19" + }, + { + "name": "V\u00f5idup\u00fcha", + "date": "2024-06-23" + }, + { + "name": "Jaanip\u00e4ev", + "date": "2024-06-24" + }, + { + "name": "Taasiseseisvumisp\u00e4ev", + "date": "2024-08-20" + }, + { + "name": "J\u00f5ululaup\u00e4ev", + "date": "2024-12-24" + }, + { + "name": "Esimene j\u00f5ulup\u00fcha", + "date": "2024-12-25" + }, + { + "name": "Teine j\u00f5ulup\u00fcha", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/EstoniaTest.php b/tests/Countries/EstoniaTest.php new file mode 100644 index 000000000..c7ee1aa0b --- /dev/null +++ b/tests/Countries/EstoniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 2a0d024ecd81acd230e83ee2c11b619428b2fc8e Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Sat, 20 Jan 2024 05:40:55 +0900 Subject: [PATCH 56/71] Update README.md (#134) contructor -> constructor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e0ecdef1..d2ce5b057 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ for example region specific holidays, you can pass this to the constructor of yo $holidays = Holidays::for(Austria::make(region: 'de-bw'))->get(); ``` -The value, `de-bw`, will be passed to the region parameter of the contructor of a country. +The value, `de-bw`, will be passed to the region parameter of the constructor of a country. ```php class Austria extends Country From 5941d7bfe00bb3243d91cfe519512e3faa92d101 Mon Sep 17 00:00:00 2001 From: Crawford30 <30619160+Crawford30@users.noreply.github.com> Date: Fri, 19 Jan 2024 23:43:15 +0300 Subject: [PATCH 57/71] Public Holidays for Malawi (#133) --- src/Countries/Malawi.php | 41 +++++++++++++++++ .../it_can_calculate_ugandan_holidays.snap | 46 +++++++++++++++++++ tests/Countries/MalawiTest.php | 18 ++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/Countries/Malawi.php create mode 100644 tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_ugandan_holidays.snap create mode 100644 tests/Countries/MalawiTest.php diff --git a/src/Countries/Malawi.php b/src/Countries/Malawi.php new file mode 100644 index 000000000..f34a2323d --- /dev/null +++ b/src/Countries/Malawi.php @@ -0,0 +1,41 @@ + '01-01', + 'John Chilembwe Day' => '01-15', + 'Martyrs Day' => '03-03', + 'Labour Day' => '05-01', + 'Kamuzu Day' => '05-14', + 'Independence Day' => '07-06', + 'Mothers Day' => '10-15', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + /** + * @return array + */ + private function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_ugandan_holidays.snap b/tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_ugandan_holidays.snap new file mode 100644 index 000000000..63bfa81dc --- /dev/null +++ b/tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_ugandan_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New Years Day", + "date": "2024-01-01" + }, + { + "name": "John Chilembwe Day", + "date": "2024-01-15" + }, + { + "name": "Martyrs Day", + "date": "2024-03-03" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Kamuzu Day", + "date": "2024-05-14" + }, + { + "name": "Independence Day", + "date": "2024-07-06" + }, + { + "name": "Mothers Day", + "date": "2024-10-15" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/MalawiTest.php b/tests/Countries/MalawiTest.php new file mode 100644 index 000000000..606d904fc --- /dev/null +++ b/tests/Countries/MalawiTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 46fc7f39fd7e3a2d362f2e3ea986c6ac9f24e1c0 Mon Sep 17 00:00:00 2001 From: Ariful Alam Date: Sat, 20 Jan 2024 02:57:25 +0600 Subject: [PATCH 58/71] Add Bangladesh holidays (#21) Co-authored-by: Ariful Alam --- src/Countries/Bangladesh.php | 35 +++++++++++++++++++ .../it_can_calculate_bangladesh_holidays.snap | 34 ++++++++++++++++++ tests/Countries/BangladeshTest.php | 18 ++++++++++ 3 files changed, 87 insertions(+) create mode 100644 src/Countries/Bangladesh.php create mode 100644 tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays.snap create mode 100644 tests/Countries/BangladeshTest.php diff --git a/src/Countries/Bangladesh.php b/src/Countries/Bangladesh.php new file mode 100644 index 000000000..6df457a6a --- /dev/null +++ b/src/Countries/Bangladesh.php @@ -0,0 +1,35 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'International Mother Language Day' => '02-21', + 'Birthday of Sheikh Mujibur Rahman' => '03-17', + 'Independence Day' => '03-26', + 'Bengali New Year' => '04-14', + 'May Day' => '05-01', + 'National Mourning Day' => '08-15', + 'Victory Day' => '12-16', + 'Christmas Day' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + // The variable holidays all follow the lunar calendar, so their dates are not confirmed. + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays.snap b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays.snap new file mode 100644 index 000000000..f5a0e91db --- /dev/null +++ b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "International Mother Language Day", + "date": "2024-02-21" + }, + { + "name": "Birthday of Sheikh Mujibur Rahman", + "date": "2024-03-17" + }, + { + "name": "Independence Day", + "date": "2024-03-26" + }, + { + "name": "Bengali New Year", + "date": "2024-04-14" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "National Mourning Day", + "date": "2024-08-15" + }, + { + "name": "Victory Day", + "date": "2024-12-16" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BangladeshTest.php b/tests/Countries/BangladeshTest.php new file mode 100644 index 000000000..b5b0f0b59 --- /dev/null +++ b/tests/Countries/BangladeshTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From acd018535be8bbeebc085160ac5a50e35063ad09 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:54:59 +0100 Subject: [PATCH 59/71] malawi fixes --- src/Countries/Malawi.php | 2 +- .../it_can_calculate_malawi_holidays.snap | 46 +++++++++++++++++++ tests/Countries/MalawiTest.php | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_malawi_holidays.snap diff --git a/src/Countries/Malawi.php b/src/Countries/Malawi.php index f34a2323d..573564d5e 100644 --- a/src/Countries/Malawi.php +++ b/src/Countries/Malawi.php @@ -31,7 +31,7 @@ protected function allHolidays(int $year): array */ private function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + $easter = $this->easter($year); return [ 'Good Friday' => $easter->subDays(2), diff --git a/tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_malawi_holidays.snap b/tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_malawi_holidays.snap new file mode 100644 index 000000000..63bfa81dc --- /dev/null +++ b/tests/.pest/snapshots/Countries/MalawiTest/it_can_calculate_malawi_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New Years Day", + "date": "2024-01-01" + }, + { + "name": "John Chilembwe Day", + "date": "2024-01-15" + }, + { + "name": "Martyrs Day", + "date": "2024-03-03" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Kamuzu Day", + "date": "2024-05-14" + }, + { + "name": "Independence Day", + "date": "2024-07-06" + }, + { + "name": "Mothers Day", + "date": "2024-10-15" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/MalawiTest.php b/tests/Countries/MalawiTest.php index 606d904fc..bc2710322 100644 --- a/tests/Countries/MalawiTest.php +++ b/tests/Countries/MalawiTest.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate ugandan holidays', function () { +it('can calculate malawi holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); $holidays = Holidays::for(country: 'mw')->get(); From 120a9f3de4b772bed023cd6032ac487311cbd481 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:58:32 +0100 Subject: [PATCH 60/71] remove annotation --- src/Countries/Bangladesh.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Bangladesh.php b/src/Countries/Bangladesh.php index 6df457a6a..b269f53dd 100644 --- a/src/Countries/Bangladesh.php +++ b/src/Countries/Bangladesh.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'bd'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From edc8d392258ea33ef935e421214f4615db8d54df Mon Sep 17 00:00:00 2001 From: dantes4ur <114443923+dantes4ur@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:53:18 -0600 Subject: [PATCH 61/71] Adding Full Mandatory Mexican holidays (#20) * feat(Mexico.php): rebase main to put mandatory days * feat(Mexico.php): finished dates --- src/Countries/Mexico.php | 76 +++++++------------ .../it_can_calculate_mexican_holidays.snap | 34 +++++++++ .../it_can_calculate_mexico_holidays.snap | 66 ---------------- tests/Countries/MexicoTest.php | 3 +- 4 files changed, 64 insertions(+), 115 deletions(-) create mode 100644 tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexican_holidays.snap delete mode 100644 tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 21b25f104..9a363fd07 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -2,9 +2,7 @@ namespace Spatie\Holidays\Countries; -use Carbon\Carbon; use Carbon\CarbonImmutable; -use Carbon\CarbonPeriod; class Mexico extends Country { @@ -16,16 +14,10 @@ public function countryCode(): string 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', + 'Año Nuevo' => '01-01', + 'Día Internacional de los Trabajadores' => '05-01', + 'Día de Independencia' => '09-16', + 'Cambio de Gobierno' => '10-01', 'Navidad' => '12-25', ], $this->variableHolidays($year)); } @@ -33,53 +25,43 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { + $constitutionDay = (new CarbonImmutable("first monday of february $year")) // 5 of february + ->setTimezone('America/Mexico_City'); - $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'); + $benitoJuarezBirth = (new CarbonImmutable("third monday of March $year")) // 21 of march + ->setTimezone('America/Mexico_City'); - if ($revolucionMexicana->isSunday()) { - $revolucionMexicana = $revolucionMexicana->next('monday'); - } - - $fathersDay = new CarbonImmutable(sprintf('third sunday of june %s', $year)); + $revolutionDay = (new CarbonImmutable("third monday of november $year")) // 20 of november + ->setTimezone('America/Mexico_City'); - $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'), - 'Revolución Mexicana' => $revolucionMexicana->format('m-d'), - 'Día del Padre' => $fathersDay->format('m-d'), + /** @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, ]; - if ($this->transmisionPoderEjecutivoFederal($year)) { - $days[ - 'Transmisión del Poder Ejecutivo Federal' - ] = $this->transmisionPoderEjecutivoFederal($year); - } - - return $days; + return array_merge( + $known_days, + $executiveChange ? ['Cambio de Gobierno' => $executiveChange] : [] + ); } - protected function transmisionPoderEjecutivoFederal($year): bool|string + protected function governmentChangeDate(): CarbonImmutable|false { - $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)); + $baseYear = 1946; // The first occurrence with president Miguel Aleman Valdes + $currentYear = CarbonImmutable::now()->year; // Get the current year - $period->addFilter(function ($date) use ($year) { - return $date->year === $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'); - $availableDates = $period->toArray(); - - if (count($availableDates)) { - return $availableDates[0]->format('m-d'); } - return false; } + } diff --git a/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexican_holidays.snap b/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexican_holidays.snap new file mode 100644 index 000000000..7f15803a3 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexican_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda de la Constituci\u00f3n", + "date": "2024-02-04" + }, + { + "name": "Natalicio de Benito Ju\u00e1rez", + "date": "2024-03-17" + }, + { + "name": "D\u00eda Internacional de los Trabajadores", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de Independencia", + "date": "2024-09-16" + }, + { + "name": "Cambio de Gobierno", + "date": "2024-09-30" + }, + { + "name": "D\u00eda de la Revoluci\u00f3n", + "date": "2024-11-17" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap b/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap deleted file mode 100644 index ecafb2e00..000000000 --- a/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap +++ /dev/null @@ -1,66 +0,0 @@ -[ - { - "name": "A\u00f1o nuevo", - "date": "2024-01-01" - }, - { - "name": "D\u00eda de la Candelaria", - "date": "2024-02-02" - }, - { - "name": "Aniversario de la promulgaci\u00f3n de la Constituci\u00f3n de 1917", - "date": "2024-02-05" - }, - { - "name": "D\u00eda de la Bandera", - "date": "2024-02-24" - }, - { - "name": "Natalicio de Benito Ju\u00e1rez", - "date": "2024-03-18" - }, - { - "name": "D\u00eda del Ni\u00f1o", - "date": "2024-04-30" - }, - { - "name": "D\u00eda de la Madre", - "date": "2024-04-30" - }, - { - "name": "D\u00eda del Trabajo", - "date": "2024-05-01" - }, - { - "name": "D\u00eda del Padre", - "date": "2024-06-16" - }, - { - "name": "D\u00eda de la Independencia", - "date": "2024-09-15" - }, - { - "name": "Transmisi\u00f3n del Poder Ejecutivo Federal", - "date": "2024-10-01" - }, - { - "name": "D\u00eda de la Raza", - "date": "2024-10-12" - }, - { - "name": "D\u00eda de Muertos", - "date": "2024-11-02" - }, - { - "name": "Revoluci\u00f3n Mexicana", - "date": "2024-11-19" - }, - { - "name": "Virgen de Guadalupe", - "date": "2024-12-12" - }, - { - "name": "Navidad", - "date": "2024-12-25" - } -] \ No newline at end of file diff --git a/tests/Countries/MexicoTest.php b/tests/Countries/MexicoTest.php index cb2876aeb..dfd62a71e 100644 --- a/tests/Countries/MexicoTest.php +++ b/tests/Countries/MexicoTest.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate mexico holidays', function () { +it('can calculate mexican holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); $holidays = Holidays::for(country: 'mx')->get(); @@ -15,5 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); - }); From f9ea67d2d03895019fc717724a02d3a32b0dcf48 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 22:53:36 +0000 Subject: [PATCH 62/71] Fix styling --- src/Countries/Mexico.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 9a363fd07..5c5534105 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -26,13 +26,13 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { $constitutionDay = (new CarbonImmutable("first monday of february $year")) // 5 of february - ->setTimezone('America/Mexico_City'); + ->setTimezone('America/Mexico_City'); $benitoJuarezBirth = (new CarbonImmutable("third monday of March $year")) // 21 of march - ->setTimezone('America/Mexico_City'); + ->setTimezone('America/Mexico_City'); $revolutionDay = (new CarbonImmutable("third monday of november $year")) // 20 of november - ->setTimezone('America/Mexico_City'); + ->setTimezone('America/Mexico_City'); /** @var CarbonImmutable|false $executiveChange */ $executiveChange = $this->governmentChangeDate(); @@ -58,10 +58,10 @@ protected function governmentChangeDate(): CarbonImmutable|false 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'); + ->setTimezone('America/Mexico_City'); } + return false; } - } From 8d52336f670b0830970ada2647555892b79f8ad7 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 20 Jan 2024 00:05:39 +0100 Subject: [PATCH 63/71] mexico fixes --- phpstan-baseline.neon | 10 ---------- src/Countries/Mexico.php | 34 ++++++++++++++++------------------ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7de51241d..3f282e151 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,16 +25,6 @@ parameters: count: 1 path: src/Countries/Mexico.php - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:transmisionPoderEjecutivoFederal\\(\\) has parameter \\$year with no type specified\\.$#" - count: 1 - path: src/Countries/Mexico.php - - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Mexico.php - - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 5c5534105..1cb2cdfa9 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -25,43 +25,41 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $constitutionDay = (new CarbonImmutable("first monday of february $year")) // 5 of february + $constitutionDay = (new CarbonImmutable("first monday of february $year")) ->setTimezone('America/Mexico_City'); - $benitoJuarezBirth = (new CarbonImmutable("third monday of March $year")) // 21 of march + $benitoJuarezBirth = (new CarbonImmutable("third monday of March $year")) ->setTimezone('America/Mexico_City'); - $revolutionDay = (new CarbonImmutable("third monday of november $year")) // 20 of november + $revolutionDay = (new CarbonImmutable("third monday of november $year")) ->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 + $holidays = [ + 'Día de la Constitución' => $constitutionDay, 'Natalicio de Benito Juárez' => $benitoJuarezBirth, 'Día de la Revolución' => $revolutionDay, ]; - return array_merge( - $known_days, - $executiveChange ? ['Cambio de Gobierno' => $executiveChange] : [] - ); + $executiveChange = $this->governmentChangeDate($year); + + if ($executiveChange) { + $holidays = array_merge($holidays, ['Cambio de Gobierno' => $executiveChange]); + } + + return $holidays; } - protected function governmentChangeDate(): CarbonImmutable|false + protected function governmentChangeDate(int $year): ?CarbonImmutable { $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 + if (($year - $baseYear) % 6 === 0) { + return CarbonImmutable::create($year, 10, 1) // October 1st of the transmission year ->setTimezone('America/Mexico_City'); } - return false; + return null; } } From a6b39398f9a88e7eb19b0318553c88c19fad89f3 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 23:22:51 +0000 Subject: [PATCH 64/71] Update CHANGELOG --- CHANGELOG.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d8e90265..8cdd8fd19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,67 @@ All notable changes to `holidays` will be documented in this file. +## 1.1.0 - 2024-01-19 + +### What's Changed + +* Fix incorrect usage in README by @cybernerdie in https://github.com/spatie/holidays/pull/16 +* Add Andorra Holidays by @BurtDS in https://github.com/spatie/holidays/pull/36 +* Add documentation on how to contribute by @Nielsvanpach in https://github.com/spatie/holidays/pull/73 +* Danish holidays by @RootAccessPlease in https://github.com/spatie/holidays/pull/5 +* Introducing Basic Playground by @devajmeireles in https://github.com/spatie/holidays/pull/28 +* fix: Oudjaarsdag is not a public holiday by @RickDBCN in https://github.com/spatie/holidays/pull/64 +* Adds support for Portuguese Holidays by @lamelas in https://github.com/spatie/holidays/pull/9 +* Added Zambian Holidays by @chandachewe10 in https://github.com/spatie/holidays/pull/83 +* Add Italian holidays by @mauricius in https://github.com/spatie/holidays/pull/24 +* Add French holidays by @levrailoup in https://github.com/spatie/holidays/pull/15 +* Add Czech holidays by @vrerabek in https://github.com/spatie/holidays/pull/22 +* Update Brazil.php by @juliofagundes in https://github.com/spatie/holidays/pull/101 +* Added Uganda Public Holidays and Unit Tests by @Crawford30 in https://github.com/spatie/holidays/pull/126 +* Support for Venezuelan holidays by @ricardomartos in https://github.com/spatie/holidays/pull/125 +* Add Macedonian holidays by @object505 in https://github.com/spatie/holidays/pull/119 +* Adding Nicaragua Holidays by @calonzolg in https://github.com/spatie/holidays/pull/92 +* add Philippine national holidays by @kndrckjvr in https://github.com/spatie/holidays/pull/25 +* Adding Full Mexican Holidays by @davsaniuv in https://github.com/spatie/holidays/pull/23 +* Add support for Irish public holidays by @marchanlon in https://github.com/spatie/holidays/pull/44 +* Add support for Croatian public holidays by @mcbuckets in https://github.com/spatie/holidays/pull/45 +* Bolivian holidays by @rats4final in https://github.com/spatie/holidays/pull/40 +* Add Estonian holidays by @hulkur in https://github.com/spatie/holidays/pull/47 +* Update README.md by @eltociear in https://github.com/spatie/holidays/pull/134 +* Public Holidays for Malawi by @Crawford30 in https://github.com/spatie/holidays/pull/133 +* Add Bangladesh holidays by @arifszn in https://github.com/spatie/holidays/pull/21 +* Adding Full Mandatory Mexican holidays by @dantes4ur in https://github.com/spatie/holidays/pull/20 +* mexico fixes by @Nielsvanpach in https://github.com/spatie/holidays/pull/140 + +### New Contributors + +* @cybernerdie made their first contribution in https://github.com/spatie/holidays/pull/16 +* @BurtDS made their first contribution in https://github.com/spatie/holidays/pull/36 +* @Nielsvanpach made their first contribution in https://github.com/spatie/holidays/pull/73 +* @RootAccessPlease made their first contribution in https://github.com/spatie/holidays/pull/5 +* @RickDBCN made their first contribution in https://github.com/spatie/holidays/pull/64 +* @lamelas made their first contribution in https://github.com/spatie/holidays/pull/9 +* @chandachewe10 made their first contribution in https://github.com/spatie/holidays/pull/83 +* @mauricius made their first contribution in https://github.com/spatie/holidays/pull/24 +* @levrailoup made their first contribution in https://github.com/spatie/holidays/pull/15 +* @vrerabek made their first contribution in https://github.com/spatie/holidays/pull/22 +* @juliofagundes made their first contribution in https://github.com/spatie/holidays/pull/101 +* @Crawford30 made their first contribution in https://github.com/spatie/holidays/pull/126 +* @ricardomartos made their first contribution in https://github.com/spatie/holidays/pull/125 +* @object505 made their first contribution in https://github.com/spatie/holidays/pull/119 +* @calonzolg made their first contribution in https://github.com/spatie/holidays/pull/92 +* @kndrckjvr made their first contribution in https://github.com/spatie/holidays/pull/25 +* @davsaniuv made their first contribution in https://github.com/spatie/holidays/pull/23 +* @marchanlon made their first contribution in https://github.com/spatie/holidays/pull/44 +* @mcbuckets made their first contribution in https://github.com/spatie/holidays/pull/45 +* @rats4final made their first contribution in https://github.com/spatie/holidays/pull/40 +* @hulkur made their first contribution in https://github.com/spatie/holidays/pull/47 +* @eltociear made their first contribution in https://github.com/spatie/holidays/pull/134 +* @arifszn made their first contribution in https://github.com/spatie/holidays/pull/21 +* @dantes4ur made their first contribution in https://github.com/spatie/holidays/pull/20 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.0.2...1.1.0 + ## 1.0.2 - 2024-01-17 ### What's Changed From d30d0562eaf2618f2e659695f6a1269cefcdefec Mon Sep 17 00:00:00 2001 From: Javier Emmanuel Mercedes Date: Fri, 19 Jan 2024 20:06:27 -0400 Subject: [PATCH 65/71] Fixed non national holiday --- src/Countries/DominicanRepublic.php | 15 +-------------- ...can_calculate_dominican_republic_holidays.snap | 12 ------------ 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/src/Countries/DominicanRepublic.php b/src/Countries/DominicanRepublic.php index 98cb24a77..c632ae430 100644 --- a/src/Countries/DominicanRepublic.php +++ b/src/Countries/DominicanRepublic.php @@ -14,7 +14,7 @@ public function countryCode(): string /** @return array */ protected function allHolidays(int $year): array { - return array_merge([ + return [ 'Año Nuevo' => '01-01', 'Día de la Altagracia' => '01-21', 'Día de Duarte' => '01-26', @@ -23,20 +23,7 @@ protected function allHolidays(int $year): array 'Día de la Restauración' => '08-16', 'Día de las Mercedes' => '09-24', 'Día de la Constitución' => '11-06', - 'Día de la Virgen de la Altagracia' => '12-08', 'Navidad' => '12-25', - ], $this->variableHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('America/Santo_Domingo'); - - return [ - 'Jueves Santo' => $easter->subDays(3), - 'Viernes Santo' => $easter->subDays(2), ]; } } diff --git a/tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap b/tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap index 163490da2..3bdd36d0d 100644 --- a/tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap +++ b/tests/.pest/snapshots/Countries/DominicanRepublicTest/it_can_calculate_dominican_republic_holidays.snap @@ -15,14 +15,6 @@ "name": "D\u00eda de la Independencia", "date": "2024-02-27" }, - { - "name": "Jueves Santo", - "date": "2024-03-28" - }, - { - "name": "Viernes Santo", - "date": "2024-03-29" - }, { "name": "D\u00eda del Trabajo", "date": "2024-05-01" @@ -39,10 +31,6 @@ "name": "D\u00eda de la Constituci\u00f3n", "date": "2024-11-06" }, - { - "name": "D\u00eda de la Virgen de la Altagracia", - "date": "2024-12-08" - }, { "name": "Navidad", "date": "2024-12-25" From a69a226e4c02840b34ac388052162c6f665bc2d3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 20 Jan 2024 11:52:43 +0100 Subject: [PATCH 66/71] move orthodox easter to Country class --- src/Countries/Country.php | 8 ++++++++ src/Countries/NorthMacedonia.php | 11 +---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 1c74eb6e1..3a09768db 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -48,6 +48,14 @@ protected function easter(int $year): CarbonImmutable return $easter->addDays(easter_days($year)); } + protected function orthodoxEaster(int $year): CarbonImmutable + { + $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); + $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; + + return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); + } + public static function find(string $countryCode): ?Country { $countryCode = strtolower($countryCode); diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 9865e3c3c..50057ea9d 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -29,19 +29,10 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp($this->orthodoxEaster($year)) - ->setTimezone('Europe/Skopje'); + $easter = $this->orthodoxEaster($year); return [ 'Велигден, вториот ден на Велигден според православниот календар' => $easter->addDay(), ]; } - - protected function orthodoxEaster(int $year): int - { - $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); - $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - - return (int) strtotime("+$daysDifference days", $timestamp); - } } From 44a846ab59611c5ebfd90337a937e6ea6cb21623 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 20 Jan 2024 12:38:34 +0100 Subject: [PATCH 67/71] update readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d2ce5b057..47ff12730 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ $holidays = Holidays::for(Belgium::make())->get(); ``` Alternatively, you could also pass an [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) code to the `for` method. +In case of region based holidays, these will not be included. Use a country class instead. ```php use Spatie\Holidays\Holidays; @@ -87,6 +88,9 @@ use Spatie\Holidays\Holidays; Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar ``` +### Package limitations +1. Islamic holidays are not supported (yet) + ## Contributing a new country If you want to add a new country, you can create a pull request. From 1056c96a333e813647ba7c7a871da6473c71a88b Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 20 Jan 2024 11:50:56 +0000 Subject: [PATCH 68/71] Fix styling --- tests/Countries/DominicanRepublicTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Countries/DominicanRepublicTest.php b/tests/Countries/DominicanRepublicTest.php index 7a388eda6..954e2a589 100644 --- a/tests/Countries/DominicanRepublicTest.php +++ b/tests/Countries/DominicanRepublicTest.php @@ -16,4 +16,3 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - From 60b73edbbbc88691ed50f561843c677c581bfb46 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 20 Jan 2024 12:50:55 +0100 Subject: [PATCH 69/71] update readme --- README.md | 6 ++++-- phpstan-baseline.neon | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47ff12730..8bc3564e3 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,11 @@ Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar ### Package limitations 1. Islamic holidays are not supported (yet) -## Contributing a new country +## Contributing -If you want to add a new country, you can create a pull request. +This is a community driven package. If you find any errors, please create an issue or a pull request. + +## Adding a new country 1. Create a new class in the `Countries` directory. It should extend the `Country` class. 2. Add a test for the new country in the `tests` directory. diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3f282e151..17eba40a1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15,6 +15,11 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Parameter \\#1 \\$timestamp of static method Carbon\\\\CarbonImmutable\\:\\:createFromTimestamp\\(\\) expects float\\|int\\|string, int\\|false given\\.$#" + count: 1 + path: src/Countries/Country.php + - message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(bool\\|Carbon\\\\CarbonImmutable, bool\\|Carbon\\\\CarbonImmutable\\)\\: int, Closure\\(Carbon\\\\CarbonImmutable, Carbon\\\\CarbonImmutable\\)\\: int\\<\\-1, 1\\> given\\.$#" count: 1 From 7bc859dcf5554ad6774690878ed1311b37d72666 Mon Sep 17 00:00:00 2001 From: thecaliskan Date: Sat, 20 Jan 2024 20:54:09 +0300 Subject: [PATCH 70/71] Added pint packages --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 91002ed8c..9f8a2f7fb 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "ext-calendar": "*" }, "require-dev": { + "laravel/pint": "^1.0", "laravel/prompts": "^0.1.15", "pestphp/pest": "^2.31", "phpstan/phpstan": "^1.10.56", @@ -46,7 +47,7 @@ "baseline": "vendor/bin/phpstan analyse --generate-baseline", "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage", - "format": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes" + "format": "vendor/bin/pint" }, "config": { "sort-packages": true, From f25e12761733a2c5448239a355cfae6a990362e4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:19:27 +0100 Subject: [PATCH 71/71] add notes on Sri Lanka --- src/Countries/SriLanka.php | 21 +++++++++++++++++++++ tests/Countries/SriLankaTest.php | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/Countries/SriLanka.php create mode 100644 tests/Countries/SriLankaTest.php diff --git a/src/Countries/SriLanka.php b/src/Countries/SriLanka.php new file mode 100644 index 000000000..a94f46cdf --- /dev/null +++ b/src/Countries/SriLanka.php @@ -0,0 +1,21 @@ +countryCode()); + } +} diff --git a/tests/Countries/SriLankaTest.php b/tests/Countries/SriLankaTest.php new file mode 100644 index 000000000..ab8eefe4a --- /dev/null +++ b/tests/Countries/SriLankaTest.php @@ -0,0 +1,10 @@ +get(); +})->throws(UnsupportedCountry::class);