From 9338f9c5e79fc1d5289a56b09fd9ad8fc89728d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Wed, 17 Jan 2024 14:19:56 +0000 Subject: [PATCH 001/114] Added portuguese holidays --- src/Countries/Portugal.php | 44 ++++++++++++++ .../it_can_calculate_portuguese_holidays.snap | 58 +++++++++++++++++++ tests/Countries/PortugalTest.php | 19 ++++++ 3 files changed, 121 insertions(+) create mode 100644 src/Countries/Portugal.php create mode 100644 tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap create mode 100644 tests/Countries/PortugalTest.php diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php new file mode 100644 index 00000000..65f87ab5 --- /dev/null +++ b/src/Countries/Portugal.php @@ -0,0 +1,44 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Dia de Ano Novo' => '01-01', + 'Dia da Liberdade' => '04-25', + 'Dia do Trabalhador' => '05-01', + 'Dia do Portugal' => '06-10', + 'Assunção da Nossa Senhora' => '08-15', + 'Implantação da República' => '10-05', + 'Dia de Todos os Santos' => '11-01', + 'Restauração da Independência' => '12-01', + 'Imaculada Conceição' => '12-08', + 'Natal' => '12-25' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Brussels'); + + return [ + 'Páscoa' => $easter, + 'Carnaval' => $easter->subDays(47), + 'Sexta-feira Santa' => $easter->subDays(2), + 'Corpo de Deus' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap new file mode 100644 index 00000000..7e409c71 --- /dev/null +++ b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "Dia de Ano Novo", + "date": "2024-01-01" + }, + { + "name": "Carnaval", + "date": "2024-02-13" + }, + { + "name": "Sexta-feira Santa", + "date": "2024-03-29" + }, + { + "name": "P\u00e1scoa", + "date": "2024-03-31" + }, + { + "name": "Dia da Liberdade", + "date": "2024-04-25" + }, + { + "name": "Dia do Trabalhador", + "date": "2024-05-01" + }, + { + "name": "Corpo de Deus", + "date": "2024-05-30" + }, + { + "name": "Dia do Portugal", + "date": "2024-06-10" + }, + { + "name": "Assun\u00e7\u00e3o da Nossa Senhora", + "date": "2024-08-15" + }, + { + "name": "Implanta\u00e7\u00e3o da Rep\u00fablica", + "date": "2024-10-05" + }, + { + "name": "Dia de Todos os Santos", + "date": "2024-11-01" + }, + { + "name": "Restaura\u00e7\u00e3o da Independ\u00eancia", + "date": "2024-12-01" + }, + { + "name": "Imaculada Concei\u00e7\u00e3o", + "date": "2024-12-08" + }, + { + "name": "Natal", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/PortugalTest.php b/tests/Countries/PortugalTest.php new file mode 100644 index 00000000..7c2ed381 --- /dev/null +++ b/tests/Countries/PortugalTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From d84e49ad0c36e72aad2acfca71fd116f9f27eea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Wed, 17 Jan 2024 14:24:53 +0000 Subject: [PATCH 002/114] Use proper timezone --- src/Countries/Portugal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 65f87ab5..3bbf9384 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -32,7 +32,7 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + ->setTimezone('Europe/Lisbon'); return [ 'Páscoa' => $easter, From 9541ffcd4ccdf31bcb4477ac92ce697c7e258a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Wed, 17 Jan 2024 14:27:49 +0000 Subject: [PATCH 003/114] Fixes small typo --- src/Countries/Portugal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 3bbf9384..00fbad8a 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -18,7 +18,7 @@ protected function allHolidays(int $year): array 'Dia de Ano Novo' => '01-01', 'Dia da Liberdade' => '04-25', 'Dia do Trabalhador' => '05-01', - 'Dia do Portugal' => '06-10', + 'Dia de Portugal' => '06-10', 'Assunção da Nossa Senhora' => '08-15', 'Implantação da República' => '10-05', 'Dia de Todos os Santos' => '11-01', From 288a7f92e3f45213c7a2baa5567d412df6c6e316 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 15:47:45 +0100 Subject: [PATCH 004/114] 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 00000000..3c7a488e --- /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 005/114] 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 00000000..6b69bbf2 --- /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 006/114] 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 3c7a488e..632552f4 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 007/114] 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 00000000..aef1f0ea --- /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 008/114] 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 aef1f0ea..f89d1730 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 009/114] 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 00000000..c2339775 --- /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 8c496df7e3860435f79f23de1d7a94bf2c84200e Mon Sep 17 00:00:00 2001 From: mauricius Date: Wed, 17 Jan 2024 18:02:34 +0100 Subject: [PATCH 010/114] add: italian holidays --- src/Countries/Italy.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Countries/Italy.php diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php new file mode 100644 index 00000000..abfc530e --- /dev/null +++ b/src/Countries/Italy.php @@ -0,0 +1,41 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Capodanno' => '01-01', + 'Epifania' => '01-06', + 'Liberazione dal nazifascismo' => '04-25', + 'Festa del lavoro' => '05-01', + 'Festa della Repubblica' => '06-02', + 'Assunzione di Maria' => '08-15', + 'Ognissanti' => '11-01', + 'Immacolata Concezione' => '12-08', + 'Natale di Gesù' => '12-25', + 'Santo Stefano' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Rome'); + + return [ + 'Lunedì di Pasqua' => $easter->addDay(1), + ]; + } +} From 97e031aae6dd74cdb8747da60ff9c3490129b426 Mon Sep 17 00:00:00 2001 From: mauricius Date: Wed, 17 Jan 2024 18:02:58 +0100 Subject: [PATCH 011/114] add: italian tests --- .../it_can_calculate_italian_holidays.snap | 46 +++++++++++++++++++ tests/Countries/ItalyTest.php | 18 ++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap create mode 100644 tests/Countries/ItalyTest.php diff --git a/tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap b/tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap new file mode 100644 index 00000000..b390d06e --- /dev/null +++ b/tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Capodanno", + "date": "2024-01-01" + }, + { + "name": "Epifania", + "date": "2024-01-06" + }, + { + "name": "Luned\u00ec di Pasqua", + "date": "2024-04-01" + }, + { + "name": "Liberazione dal nazifascismo", + "date": "2024-04-25" + }, + { + "name": "Festa del lavoro", + "date": "2024-05-01" + }, + { + "name": "Festa della Repubblica", + "date": "2024-06-02" + }, + { + "name": "Assunzione di Maria", + "date": "2024-08-15" + }, + { + "name": "Ognissanti", + "date": "2024-11-01" + }, + { + "name": "Immacolata Concezione", + "date": "2024-12-08" + }, + { + "name": "Natale di Ges\u00f9", + "date": "2024-12-25" + }, + { + "name": "Santo Stefano", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/ItalyTest.php b/tests/Countries/ItalyTest.php new file mode 100644 index 00000000..bd42933b --- /dev/null +++ b/tests/Countries/ItalyTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); 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 012/114] 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 00000000..ac89542a --- /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 013/114] 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 00000000..b242572e --- /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 c2339775..9c85f523 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 ac89542a..cb2876ae 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 014/114] remove vscode folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ff8bfd7e..96b3d690 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 015/114] 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 b242572e..00000000 --- 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 016/114] 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 632552f4..3b1813b4 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 81a4a615a0aa1a150953c607df7e231716cf23a8 Mon Sep 17 00:00:00 2001 From: AJ <60591772+devajmeireles@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:18:35 -0300 Subject: [PATCH 017/114] introducing playground --- composer.json | 4 +++- playground.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 playground.php diff --git a/composer.json b/composer.json index aa1da046..91002ed8 100644 --- a/composer.json +++ b/composer.json @@ -25,9 +25,11 @@ "ext-calendar": "*" }, "require-dev": { + "laravel/prompts": "^0.1.15", "pestphp/pest": "^2.31", "phpstan/phpstan": "^1.10.56", - "spatie/ray": "^1.40.1" + "spatie/ray": "^1.40.1", + "symfony/var-dumper": "^6.4" }, "autoload": { "psr-4": { diff --git a/playground.php b/playground.php new file mode 100644 index 00000000..16d5e472 --- /dev/null +++ b/playground.php @@ -0,0 +1,30 @@ +get()) + ->map(fn (array $holiday) => [ + 'name' => $holiday['name'], + 'date' => $holiday['date']->format('Y-m-d'), // @phpstan-ignore-line + ])->toArray(); + +dd($result); From 0e885c0f436cbf78c310d1e6f8dc5c7333698a78 Mon Sep 17 00:00:00 2001 From: BurtDS Date: Wed, 17 Jan 2024 21:12:54 +0100 Subject: [PATCH 018/114] Add Andorra Holidays --- src/Countries/Andorra.php | 43 +++++++++++++++ .../it_can_calculate_andorra_holidays.snap | 54 +++++++++++++++++++ tests/Countries/AndorraTest.php | 18 +++++++ 3 files changed, 115 insertions(+) create mode 100644 src/Countries/Andorra.php create mode 100644 tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap create mode 100644 tests/Countries/AndorraTest.php diff --git a/src/Countries/Andorra.php b/src/Countries/Andorra.php new file mode 100644 index 00000000..19e342ca --- /dev/null +++ b/src/Countries/Andorra.php @@ -0,0 +1,43 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Any nou' => '01-01', + 'Reis' => '01-06', + 'Dia de la Constitució' => '03-14', + 'Festa del Treball' => '05-01', + 'Assumpció' => '08-15', + 'Mare de Déu de Meritxell' => '09-08', + 'Tots Sants' => '11-01', + 'Immaculada Concepció' => '11-08', + 'Nadal' => '12-25', + 'Sant Esteve' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Brussels'); + + return [ + 'Divendres Sant' => $easter->subDays(2), + 'Dilluns de Pasqua' => $easter->addDay(), + 'Dilluns de Pentecosta' => $easter->addDays(50), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap b/tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap new file mode 100644 index 00000000..b46fb624 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Any nou", + "date": "2024-01-01" + }, + { + "name": "Reis", + "date": "2024-01-06" + }, + { + "name": "Dia de la Constituci\u00f3", + "date": "2024-03-14" + }, + { + "name": "Divendres Sant", + "date": "2024-03-29" + }, + { + "name": "Dilluns de Pasqua", + "date": "2024-04-01" + }, + { + "name": "Festa del Treball", + "date": "2024-05-01" + }, + { + "name": "Dilluns de Pentecosta", + "date": "2024-05-20" + }, + { + "name": "Assumpci\u00f3", + "date": "2024-08-15" + }, + { + "name": "Mare de D\u00e9u de Meritxell", + "date": "2024-09-08" + }, + { + "name": "Tots Sants", + "date": "2024-11-01" + }, + { + "name": "Immaculada Concepci\u00f3", + "date": "2024-11-08" + }, + { + "name": "Nadal", + "date": "2024-12-25" + }, + { + "name": "Sant Esteve", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/AndorraTest.php b/tests/Countries/AndorraTest.php new file mode 100644 index 00000000..6ab6d869 --- /dev/null +++ b/tests/Countries/AndorraTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); \ No newline at end of file From fedcae817b2f78b8a1af1b4f2c5c7d60c7479e5d Mon Sep 17 00:00:00 2001 From: freekmurze Date: Wed, 17 Jan 2024 22:49:55 +0000 Subject: [PATCH 019/114] Fix styling --- tests/Countries/AndorraTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Countries/AndorraTest.php b/tests/Countries/AndorraTest.php index 6ab6d869..43f1c49c 100644 --- a/tests/Countries/AndorraTest.php +++ b/tests/Countries/AndorraTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); \ No newline at end of file +}); From a0666fbd7f52648d25941bd9ad303c0c7cc70279 Mon Sep 17 00:00:00 2001 From: Javier Emmanuel Mercedes Date: Wed, 17 Jan 2024 21:00:39 -0400 Subject: [PATCH 020/114] 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 00000000..98cb24a7 --- /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 00000000..163490da --- /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 00000000..7a388eda --- /dev/null +++ b/tests/Countries/DominicanRepublicTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + From 17d8e558356d5de8f8403a21ed9abd1fcabe8adc Mon Sep 17 00:00:00 2001 From: Rick de Boer Date: Thu, 18 Jan 2024 08:51:32 +0100 Subject: [PATCH 021/114] Update Netherlands.php --- src/Countries/Netherlands.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index c79223dd..e63dcdd0 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -19,7 +19,6 @@ protected function allHolidays(int $year): array 'Bevrijdingsdag' => '05-05', '1e Kerstdag' => '12-25', '2e Kerstdag' => '12-26', - 'Oudejaarsdag' => '12-31', ], $this->variableHolidays($year)); } From d588e864548b93cb1a0e2b73b0162f940289fa7f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:38:15 +0100 Subject: [PATCH 022/114] add docs for contributing + add example for regions --- README.md | 45 ++++++++++++---- src/Countries/Austria.php | 5 ++ src/Countries/Country.php | 2 +- ...ustrian_holidays_with_region_holidays.snap | 54 +++++++++++++++++++ tests/Countries/AustriaTest.php | 13 +++++ 5 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap diff --git a/README.md b/README.md index 12f5b0ff..e41ea2ff 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ use Spatie\Holidays\Holidays; // returns an array of Belgian holidays // for the current year -$holidays = Holidays::for('be')->get(); +$holidays = Holidays::for('be')->get(); ``` ## Support us @@ -40,21 +40,22 @@ You can get all holidays for a country by using the `get` method. ```php use Spatie\Holidays\Holidays; +use Spatie\Holidays\Countries\Belgium; // returns an array of Belgian holidays // for the current year -$holidays = Holidays::for('be')->get(); +$holidays = Holidays::for(Belgium::make())->get(); ``` -Alternatively, you could also pass an instance of `Country` to the `for` method. +Alternatively, you could also pass an ISO code to the `for` method. +But region specific holidays will not be included. ```php use Spatie\Holidays\Holidays; -use Spatie\Holidays\Countries\Belgium; // returns an array of Belgian holidays // for the current year -$holidays = Holidays::for(Belgium::make())->get(); +$holidays = Holidays::for('be')->get(); ``` ### Getting holidays for a specific year @@ -87,6 +88,36 @@ use Spatie\Holidays\Holidays; Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar ``` +## Contributing a new country + +If you want to add a new country, you can create a pull request. + +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. + +In case your country has specific rules for calculating holidays, +for example region specific holidays, you can pass this to the constructor of your country class. + +```php +$holidays = Holidays::for(Austria::make('de-bw'))->get(); + +class Austria extends Country +{ + protected function __construct( + protected ?string $region = null, + ) { + } + + protected function allHolidays(int $year): array + { + // Here you can use $this->region (or other variables) to calculate holidays + } +``` + +Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for more details. + + + ## Testing ```bash @@ -97,10 +128,6 @@ composer test Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. -## Contributing - -Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. - ## Security Vulnerabilities Please review [our security policy](../../security/policy) on how to report security vulnerabilities. diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index c8eea5d6..b03a22e5 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -6,6 +6,11 @@ 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 b99262a5..2c875aa7 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -37,7 +37,7 @@ public function get(int $year): array public static function make(): static { - return new static(); + return new static(...func_get_args()); } public static function find(string $countryCode): ?Country diff --git a/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap b/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap new file mode 100644 index 00000000..67cda42e --- /dev/null +++ b/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Heilige Drei K\u00f6nige", + "date": "2024-01-06" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Staatsfeiertag", + "date": "2024-05-01" + }, + { + "name": "Christi Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Fronleichnam", + "date": "2024-05-30" + }, + { + "name": "Mari\u00e4 Himmelfahrt", + "date": "2024-08-15" + }, + { + "name": "Nationalfeiertag", + "date": "2024-10-26" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "Mari\u00e4 Empf\u00e4ngnis", + "date": "2024-12-08" + }, + { + "name": "Christtag", + "date": "2024-12-25" + }, + { + "name": "Stefanitag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 9018307f..3473abef 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Countries\Austria; use Spatie\Holidays\Holidays; it('can calculate austrian holidays', function () { @@ -16,3 +17,15 @@ 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 abd8c23e896022511b714e37e8ea3335aef0f9f0 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:49:17 +0100 Subject: [PATCH 023/114] remove skipped test --- ...ustrian_holidays_with_region_holidays.snap | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap diff --git a/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap b/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap deleted file mode 100644 index 67cda42e..00000000 --- a/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap +++ /dev/null @@ -1,54 +0,0 @@ -[ - { - "name": "Neujahr", - "date": "2024-01-01" - }, - { - "name": "Heilige Drei K\u00f6nige", - "date": "2024-01-06" - }, - { - "name": "Ostermontag", - "date": "2024-04-01" - }, - { - "name": "Staatsfeiertag", - "date": "2024-05-01" - }, - { - "name": "Christi Himmelfahrt", - "date": "2024-05-09" - }, - { - "name": "Pfingstmontag", - "date": "2024-05-20" - }, - { - "name": "Fronleichnam", - "date": "2024-05-30" - }, - { - "name": "Mari\u00e4 Himmelfahrt", - "date": "2024-08-15" - }, - { - "name": "Nationalfeiertag", - "date": "2024-10-26" - }, - { - "name": "Allerheiligen", - "date": "2024-11-01" - }, - { - "name": "Mari\u00e4 Empf\u00e4ngnis", - "date": "2024-12-08" - }, - { - "name": "Christtag", - "date": "2024-12-25" - }, - { - "name": "Stefanitag", - "date": "2024-12-26" - } -] \ No newline at end of file From 701ce112f0d6a3252ec4df3f8a3d460d814e030d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:55:07 +0100 Subject: [PATCH 024/114] edit readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e41ea2ff..09dec13f 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,9 @@ for example region specific holidays, you can pass this to the constructor of yo ```php $holidays = Holidays::for(Austria::make('de-bw'))->get(); +``` +```php class Austria extends Country { protected function __construct( From 4951179e10e76a10c2b249b6783948e97b42319e Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Thu, 18 Jan 2024 11:00:05 +0100 Subject: [PATCH 025/114] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 09dec13f..479ae549 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,6 @@ $holidays = Holidays::for(Belgium::make())->get(); ``` Alternatively, you could also pass an ISO code to the `for` method. -But region specific holidays will not be included. ```php use Spatie\Holidays\Holidays; @@ -94,14 +93,18 @@ If you want to add a new country, you can create a pull request. 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. In case your country has specific rules for calculating holidays, for example region specific holidays, you can pass this to the constructor of your country class. ```php -$holidays = Holidays::for(Austria::make('de-bw'))->get(); +$holidays = Holidays::for(Austria::make(region: 'de-bw'))->get(); ``` +The value, `de-bw`, will be passed the region parameter of the contructor of a country. + ```php class Austria extends Country { @@ -118,8 +121,6 @@ class Austria extends Country Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for more details. - - ## Testing ```bash From 09e703e41070322cbf23028c94a39c1327976a29 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:05:56 +0100 Subject: [PATCH 026/114] fixes for phpstan --- phpstan-baseline.neon | 17 ++++++----------- src/Countries/Andorra.php | 1 - src/Countries/Austria.php | 3 +-- src/Countries/Belgium.php | 1 - src/Countries/Brazil.php | 1 - src/Countries/Country.php | 2 +- src/Countries/Hungary.php | 1 - src/Countries/Netherlands.php | 1 - 8 files changed, 8 insertions(+), 19 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 40f94f7e..1d1a8ab5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,17 +1,12 @@ parameters: ignoreErrors: - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Belgium\\:\\:allHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Belgium.php - - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 path: src/Countries/Country.php - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\ but returns array\\\\.$#" + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\ but returns array\\\\.$#" count: 1 path: src/Countries/Country.php @@ -20,11 +15,6 @@ parameters: count: 1 path: src/Countries/Country.php - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Hungary\\:\\:allHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Hungary.php - - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 @@ -44,3 +34,8 @@ parameters: message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Carbon\\\\CarbonImmutable\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#" count: 1 path: src/Holidays.php + + - + message: "#^Property Spatie\\\\Holidays\\\\Holidays\\:\\:\\$holidays \\(array\\\\) does not accept array\\\\.$#" + count: 1 + path: src/Holidays.php diff --git a/src/Countries/Andorra.php b/src/Countries/Andorra.php index 19e342ca..51615e69 100644 --- a/src/Countries/Andorra.php +++ b/src/Countries/Andorra.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'ad'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index b03a22e5..73fb6128 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -16,7 +16,6 @@ public function countryCode(): string return 'at'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -39,7 +38,7 @@ protected function variableHolidays(int $year): array ->setTimezone('Europe/Vienna'); return [ - 'Ostermontag' => $easter->addDay(1), + 'Ostermontag' => $easter->addDay(), 'Christi Himmelfahrt' => $easter->addDays(39), 'Pfingstmontag' => $easter->addDays(50), 'Fronleichnam' => $easter->addDays(60), diff --git a/src/Countries/Belgium.php b/src/Countries/Belgium.php index f5d268db..af52b681 100644 --- a/src/Countries/Belgium.php +++ b/src/Countries/Belgium.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'be'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index 4c93f100..479d7836 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'br'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 2c875aa7..8b75b8df 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -13,7 +13,7 @@ abstract public function countryCode(): string; /** @return array */ abstract protected function allHolidays(int $year): array; - /** @return array */ + /** @return array */ public function get(int $year): array { $this->ensureYearCanBeCalculated($year); diff --git a/src/Countries/Hungary.php b/src/Countries/Hungary.php index 8a646745..15a46e99 100644 --- a/src/Countries/Hungary.php +++ b/src/Countries/Hungary.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'hu'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index c79223dd..427c670d 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'nl'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From dc83b8deb55e034bd741b3ad242fa8b43f61de83 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:10:05 +0100 Subject: [PATCH 027/114] ci changes --- .github/workflows/phpstan.yml | 2 +- .github/workflows/run-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 60ce66b6..e171b046 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,6 +1,6 @@ name: PHPStan -on: [push] +on: [push, pull_request] jobs: phpstan: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 14315473..c15c8423 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -4,7 +4,7 @@ on: push: paths: - '**.php' - - '.github/workflows/run-tests-pest.yml' + - '.github/workflows/run-tests.yml' - 'phpunit.xml.dist' - 'composer.json' - 'composer.lock' From 71402199a37e36c75e2b906e7d21d981df63bb98 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:14:59 +0100 Subject: [PATCH 028/114] run ci for every PR --- .github/workflows/fix-php-code-style-issues.yml | 5 +---- .github/workflows/run-tests.yml | 9 +-------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index cd4239c2..30e62c77 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -1,9 +1,6 @@ name: Fix PHP code style issues -on: - push: - paths: - - '**.php' +on: [push] permissions: contents: write diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c15c8423..77a34a44 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,13 +1,6 @@ name: Tests -on: - push: - paths: - - '**.php' - - '.github/workflows/run-tests.yml' - - 'phpunit.xml.dist' - - 'composer.json' - - 'composer.lock' +on: [push, pull_request] jobs: test: From a11672e3f6f5af63c23b61de6026cd3c90821953 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:17:03 +0100 Subject: [PATCH 029/114] skip Brazil implementation returned bad dates --- src/Countries/Brazil.php | 2 ++ tests/Countries/BrazilTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index 479d7836..19b9af7a 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -13,6 +13,8 @@ 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 91be74d4..a91509ff 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 82267a8fa35dfa8feff2ffeb51d14b7c45e5f1fa Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:19:43 +0100 Subject: [PATCH 030/114] ignore issue --- phpstan-baseline.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1d1a8ab5..51b9330f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: src/Countries/Brazil.php + - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 From bd8f16aac6b2eef7a16d2ee546a3bad496290e44 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:42:45 +0100 Subject: [PATCH 031/114] Added Danish holidays. --- src/Countries/Denmark.php | 39 +++++++++++++++++++++++++++++++++++++++ tests/DenmarkTest.php | 18 ++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/Countries/Denmark.php create mode 100644 tests/DenmarkTest.php diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php new file mode 100644 index 00000000..e1d62510 --- /dev/null +++ b/src/Countries/Denmark.php @@ -0,0 +1,39 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Nytår' => '01-01', + 'Juleaften' => '24-12', + 'Juledag' => '25-12', + 'Anden Juledag' => '26-12' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Copenhagen'); + + return [ + 'Påskedag' => $easter->addDay(), + 'Anden påskedag' => $easter->addDays(2), + 'Kristi Himmelfartsdag' => $easter->addDays(39), + 'Pinse' => $easter->addDays(49), + 'Anden pisedag' => $easter->addDays(50), + ]; + } +} diff --git a/tests/DenmarkTest.php b/tests/DenmarkTest.php new file mode 100644 index 00000000..dc01757c --- /dev/null +++ b/tests/DenmarkTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 09b3994ddf90824805d3d64ec5b5d00df876a173 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:49:40 +0100 Subject: [PATCH 032/114] Added missing holidays. --- src/Countries/Denmark.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index e1d62510..152bf229 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -30,6 +30,8 @@ protected function variableHolidays(int $year): array return [ 'Påskedag' => $easter->addDay(), + 'Skærtorsdag' => $easter->subDays(3), + 'Langfredag' => $easter->subDays(2), 'Anden påskedag' => $easter->addDays(2), 'Kristi Himmelfartsdag' => $easter->addDays(39), 'Pinse' => $easter->addDays(49), From 77124fff7dd31b841cbc740f18751974ea13877e Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:58:16 +0100 Subject: [PATCH 033/114] Fixed spelling mistake. --- src/Countries/Denmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 152bf229..0852bfeb 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -32,10 +32,10 @@ protected function variableHolidays(int $year): array 'Påskedag' => $easter->addDay(), 'Skærtorsdag' => $easter->subDays(3), 'Langfredag' => $easter->subDays(2), - 'Anden påskedag' => $easter->addDays(2), + 'Anden Påskedag' => $easter->addDays(2), 'Kristi Himmelfartsdag' => $easter->addDays(39), 'Pinse' => $easter->addDays(49), - 'Anden pisedag' => $easter->addDays(50), + 'Anden Pinsedag' => $easter->addDays(50), ]; } } From 34e692eceabb5855a9a85b4decb62fbac1768aa8 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 15:02:15 +0100 Subject: [PATCH 034/114] Added generated snapshot. --- .../it_can_calculate_danish_holidays.snap | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap diff --git a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap new file mode 100644 index 00000000..7fa897a9 --- /dev/null +++ b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Nyt\u00e5r", + "date": "2024-01-01" + }, + { + "name": "Sk\u00e6rtorsdag", + "date": "2024-03-28" + }, + { + "name": "Langfredag", + "date": "2024-03-29" + }, + { + "name": "P\u00e5skedag", + "date": "2024-04-01" + }, + { + "name": "Anden P\u00e5skedag", + "date": "2024-04-02" + }, + { + "name": "Kristi Himmelfartsdag", + "date": "2024-05-09" + }, + { + "name": "Pinse", + "date": "2024-05-19" + }, + { + "name": "Anden Pinsedag", + "date": "2024-05-20" + }, + { + "name": "Juleaften", + "date": "2025-12-12" + }, + { + "name": "Juledag", + "date": "2026-01-12" + }, + { + "name": "Anden Juledag", + "date": "2026-02-12" + } +] \ No newline at end of file From a2b7208e1f70f50176cb83dd5ea7ee5027080a45 Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 18 Jan 2024 09:15:59 +0100 Subject: [PATCH 035/114] Fixed errors regarding the order of day/month and took into account that Great Prayer Day is no longer a public holiday in 2024. --- src/Countries/Denmark.php | 14 ++++++++++---- .../it_can_calculate_danish_holidays.snap | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 0852bfeb..3c8a6976 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -16,9 +16,9 @@ protected function allHolidays(int $year): array { return array_merge([ 'Nytår' => '01-01', - 'Juleaften' => '24-12', - 'Juledag' => '25-12', - 'Anden Juledag' => '26-12' + 'Juleaften' => '12-24', + 'Juledag' => '12-25', + 'Anden Juledag' => '12-26' ], $this->variableHolidays($year)); } @@ -28,7 +28,7 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Europe/Copenhagen'); - return [ + $holidays = [ 'Påskedag' => $easter->addDay(), 'Skærtorsdag' => $easter->subDays(3), 'Langfredag' => $easter->subDays(2), @@ -37,5 +37,11 @@ protected function variableHolidays(int $year): array 'Pinse' => $easter->addDays(49), 'Anden Pinsedag' => $easter->addDays(50), ]; + + if ($year < 2024) { + $holidays['Store Bededag'] = $easter->addDays(26); + } + + return $holidays; } } diff --git a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap index 7fa897a9..b19f23c2 100644 --- a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap +++ b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap @@ -33,14 +33,14 @@ }, { "name": "Juleaften", - "date": "2025-12-12" + "date": "2024-12-24" }, { "name": "Juledag", - "date": "2026-01-12" + "date": "2024-12-25" }, { "name": "Anden Juledag", - "date": "2026-02-12" + "date": "2024-12-26" } ] \ No newline at end of file From ef4dbd91ec6c52bad5f6716b6ec8427681df30be Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 18 Jan 2024 09:24:01 +0100 Subject: [PATCH 036/114] Moved test to correct folder. --- .../DenmarkTest/it_can_calculate_danish_holidays.snap | 0 tests/{ => Countries}/DenmarkTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/.pest/snapshots/{ => Countries}/DenmarkTest/it_can_calculate_danish_holidays.snap (100%) rename tests/{ => Countries}/DenmarkTest.php (100%) diff --git a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap similarity index 100% rename from tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap rename to tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap diff --git a/tests/DenmarkTest.php b/tests/Countries/DenmarkTest.php similarity index 100% rename from tests/DenmarkTest.php rename to tests/Countries/DenmarkTest.php From 73493430ff14f29496dd0d42f3cc29bf36d40b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Thu, 18 Jan 2024 10:49:28 +0000 Subject: [PATCH 037/114] Removing Carnaval as it is not an official holiday. --- src/Countries/Portugal.php | 1 - .../PortugalTest/it_can_calculate_portuguese_holidays.snap | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 00fbad8a..769800ea 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -36,7 +36,6 @@ protected function variableHolidays(int $year): array return [ 'Páscoa' => $easter, - 'Carnaval' => $easter->subDays(47), 'Sexta-feira Santa' => $easter->subDays(2), 'Corpo de Deus' => $easter->addDays(60), ]; diff --git a/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap index 7e409c71..13513781 100644 --- a/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap +++ b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap @@ -3,10 +3,6 @@ "name": "Dia de Ano Novo", "date": "2024-01-01" }, - { - "name": "Carnaval", - "date": "2024-02-13" - }, { "name": "Sexta-feira Santa", "date": "2024-03-29" @@ -28,7 +24,7 @@ "date": "2024-05-30" }, { - "name": "Dia do Portugal", + "name": "Dia de Portugal", "date": "2024-06-10" }, { From e055593420fd179ebb7dfb09b0ec9d4f70bf1d80 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:08:40 +0100 Subject: [PATCH 038/114] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 479ae549..44af97b7 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 the region parameter of the contructor of a country. +The value, `de-bw`, will be passed to the region parameter of the contructor of a country. ```php class Austria extends Country From 7712542516cd0204065b7b8ec991d3237e1922e5 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 18 Jan 2024 11:15:02 +0000 Subject: [PATCH 039/114] Fix styling --- src/Countries/Denmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 3c8a6976..4e7ef6f7 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -18,7 +18,7 @@ protected function allHolidays(int $year): array 'Nytår' => '01-01', 'Juleaften' => '12-24', 'Juledag' => '12-25', - 'Anden Juledag' => '12-26' + 'Anden Juledag' => '12-26', ], $this->variableHolidays($year)); } From d09db5afbdc2e506a56263a3d584cfc2a34fbb14 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:15:11 +0100 Subject: [PATCH 040/114] remove annotation --- src/Countries/Denmark.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 4e7ef6f7..66d2113a 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'da'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 35ae98399003342dacc416e482867c9935eee1a2 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 18 Jan 2024 12:49:50 +0000 Subject: [PATCH 041/114] Fix styling --- playground.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/playground.php b/playground.php index 16d5e472..c53856a2 100644 --- a/playground.php +++ b/playground.php @@ -2,14 +2,15 @@ use Spatie\Holidays\Countries\Country; use Spatie\Holidays\Holidays; + use function Laravel\Prompts\select; -require __DIR__ . '/vendor/autoload.php'; +require __DIR__.'/vendor/autoload.php'; $countries = []; foreach (glob(__DIR__.'/src/Countries/*.php') as $filename) { // @phpstan-ignore-line - $countryClass = '\\Spatie\\Holidays\\Countries\\' . basename($filename, '.php'); + $countryClass = '\\Spatie\\Holidays\\Countries\\'.basename($filename, '.php'); if (basename($filename) === 'Country.php') { continue; From f9aba7a3e071ad0012e71100b0a0875808194ec7 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Thu, 18 Jan 2024 14:04:47 +0100 Subject: [PATCH 042/114] 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 3b1813b4..1aadad48 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 a55ac54b07c5f0c4a46c2abe83444ad07d5d2db7 Mon Sep 17 00:00:00 2001 From: mauricius Date: Thu, 18 Jan 2024 14:20:51 +0100 Subject: [PATCH 043/114] remove: phpdoc --- src/Countries/Italy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php index abfc530e..d302f94d 100644 --- a/src/Countries/Italy.php +++ b/src/Countries/Italy.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'it'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From bd85a24ffdec12c2ac6633b131a116b650ea548e Mon Sep 17 00:00:00 2001 From: chandachewe10 Date: Thu, 18 Jan 2024 16:12:26 +0200 Subject: [PATCH 044/114] Added Zambian Holidays --- src/Countries/Zambia.php | 44 ++++++++++++++ .../it_can_calculate_zambian_holidays.snap | 58 +++++++++++++++++++ tests/Countries/ZambiaTest.php | 18 ++++++ 3 files changed, 120 insertions(+) create mode 100644 src/Countries/Zambia.php create mode 100644 tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap create mode 100644 tests/Countries/ZambiaTest.php diff --git a/src/Countries/Zambia.php b/src/Countries/Zambia.php new file mode 100644 index 00000000..324567df --- /dev/null +++ b/src/Countries/Zambia.php @@ -0,0 +1,44 @@ + '01-01', + 'International Womens Day' => '03-08', + 'Youth Day' => '03-12', + 'Birthday of Kenneth Kaunda' => '04-28', + 'Labour Day' => '05-01', + 'Africa Day' => '05-25', + 'Heroes Day' => '07-01', + 'Unity Day' => '07-02', + 'Farmers Day' => '08-01', + 'National Prayer Day' => '10-18', + 'Independence Day' => '10-24', + 'Christmas Day' => '12-25', + + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Lusaka'); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap b/tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap new file mode 100644 index 00000000..8cec8422 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "New Year", + "date": "2024-01-01" + }, + { + "name": "International Womens Day", + "date": "2024-03-08" + }, + { + "name": "Youth Day", + "date": "2024-03-12" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Birthday of Kenneth Kaunda", + "date": "2024-04-28" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Africa Day", + "date": "2024-05-25" + }, + { + "name": "Heroes Day", + "date": "2024-07-01" + }, + { + "name": "Unity Day", + "date": "2024-07-02" + }, + { + "name": "Farmers Day", + "date": "2024-08-01" + }, + { + "name": "National Prayer Day", + "date": "2024-10-18" + }, + { + "name": "Independence Day", + "date": "2024-10-24" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ZambiaTest.php b/tests/Countries/ZambiaTest.php new file mode 100644 index 00000000..83e73225 --- /dev/null +++ b/tests/Countries/ZambiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 5024b38c3916036b9b70804cb621bedb3ee69d33 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:15:22 +0100 Subject: [PATCH 045/114] update nl snapshot --- .../NetherlandsTest/it_can_calculate_dutch_holidays.snap | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap b/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap index 3257dd42..7ba840be 100644 --- a/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap +++ b/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap @@ -42,9 +42,5 @@ { "name": "2e Kerstdag", "date": "2024-12-26" - }, - { - "name": "Oudejaarsdag", - "date": "2024-12-31" } ] \ No newline at end of file From 6c73bc3342b6effae6677470ee9ab552233a0f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Thu, 18 Jan 2024 15:20:33 +0000 Subject: [PATCH 046/114] Fix for phpstan --- src/Countries/Portugal.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 769800ea..c27489e5 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'pt'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 6374cb3d73dd6619b0ac1c995d621d1e0b1384a0 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Thu, 18 Jan 2024 15:50:25 +0000 Subject: [PATCH 047/114] Fix styling --- src/Countries/Portugal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index c27489e5..4525591d 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -23,7 +23,7 @@ protected function allHolidays(int $year): array 'Dia de Todos os Santos' => '11-01', 'Restauração da Independência' => '12-01', 'Imaculada Conceição' => '12-08', - 'Natal' => '12-25' + 'Natal' => '12-25', ], $this->variableHolidays($year)); } 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 048/114] 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 14315473..ee8a13ea 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 40e12a466586bf16a64ca8cece1ba73960cdbcba Mon Sep 17 00:00:00 2001 From: freekmurze Date: Thu, 18 Jan 2024 15:54:00 +0000 Subject: [PATCH 049/114] Fix styling --- src/Countries/Zambia.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Zambia.php b/src/Countries/Zambia.php index 324567df..14112e6e 100644 --- a/src/Countries/Zambia.php +++ b/src/Countries/Zambia.php @@ -26,7 +26,7 @@ protected function allHolidays(int $year): array 'National Prayer Day' => '10-18', 'Independence Day' => '10-24', 'Christmas Day' => '12-25', - + ], $this->variableHolidays($year)); } @@ -37,7 +37,7 @@ protected function variableHolidays(int $year): array ->setTimezone('Africa/Lusaka'); return [ - 'Good Friday' => $easter->subDays(2), + 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), ]; } From 47c40bfd3344e91a5e23c93e7aae92c35f833870 Mon Sep 17 00:00:00 2001 From: Javier Emmanuel Mercedes Date: Thu, 18 Jan 2024 11:59:02 -0400 Subject: [PATCH 050/114] 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 98cb24a7..ea965984 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 051/114] 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 ea965984..98cb24a7 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 5907c73907b96895d953154d658ad916997683ad Mon Sep 17 00:00:00 2001 From: mauricius Date: Thu, 18 Jan 2024 17:43:23 +0100 Subject: [PATCH 052/114] fix: fix phpstan --- src/Countries/Italy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php index d302f94d..169533ae 100644 --- a/src/Countries/Italy.php +++ b/src/Countries/Italy.php @@ -34,7 +34,7 @@ protected function variableHolidays(int $year): array ->setTimezone('Europe/Rome'); return [ - 'Lunedì di Pasqua' => $easter->addDay(1), + 'Lunedì di Pasqua' => $easter->addDay(), ]; } } From b41eda234eab20e27b6c0c8765142f60887caa77 Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 11:28:56 -0600 Subject: [PATCH 053/114] 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 a7c44ddb..6f7c0773 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 00000000..d185b59b --- /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 00000000..b92235be --- /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 00000000..840a0609 --- /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 054/114] 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 1aadad48..977e26a1 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 00000000..5256f894 --- /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 00000000..4dd52f18 --- /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 6b69bbf2..e70d919b 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 055/114] 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 977e26a1..449d13f5 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 056/114] 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 d185b59b..8614270b 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 7b61573783187fb54725cdf69a8f8498864f90cb Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:03:01 +0100 Subject: [PATCH 057/114] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 44af97b7..1e0ecdef 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ use Spatie\Holidays\Countries\Belgium; $holidays = Holidays::for(Belgium::make())->get(); ``` -Alternatively, you could also pass an ISO code to the `for` method. +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. ```php use Spatie\Holidays\Holidays; From 2759f974942f361170dbdc12e0ec6d11bd0ea8da Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 13:35:35 -0600 Subject: [PATCH 058/114] 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 b92235be..572176fc 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 059/114] 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 19b9af7a..a05dbbf4 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 060/114] 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 00000000..dd4cf848 --- /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 00000000..0859fcf5 --- /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 00000000..4fd99717 --- /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 061/114] 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 00000000..0ab6f07a --- /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 00000000..dfc69419 --- /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 00000000..b68507ff --- /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 062/114] 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 00000000..80441506 --- /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 00000000..1c867bd6 --- /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 00000000..5b2cf5ea --- /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 063/114] 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 00000000..fa520ece --- /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 064/114] 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 fa520ece..9fb40912 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 065/114] 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 449d13f5..c948556f 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 e70d919b..358f8b1c 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 066/114] 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 00000000..f0cce6f0 --- /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 00000000..9e3ba56a --- /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 00000000..a23bac97 --- /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 067/114] 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 a23bac97..0a7ece2f 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 068/114] 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 0ab6f07a..81da2e27 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 069/114] 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 a05dbbf4..e861e887 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 a91509ff..91be74d4 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 070/114] 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 00000000..023d20b7 --- /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 00000000..35276c50 --- /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 00000000..82ab1f7f --- /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 071/114] 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 023d20b7..635b1b29 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 35276c50..ff373318 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 072/114] 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 51615e69..89ce91c8 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 73fb6128..5041c401 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 af52b681..8710daf7 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 e861e887..d2be75a2 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 8b75b8df..2c554702 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 f0cce6f0..c4aff420 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 66d2113a..ee68d1d7 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 c948556f..c0272aab 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 15a46e99..9658c380 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 169533ae..e4f53b09 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 b694c25c..91abc9bd 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 4525591d..98c09b0a 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 14112e6e..c8802a90 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 5be3e640..eeaf05a7 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 073/114] 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 635b1b29..8673698d 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 074/114] 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 80441506..bda60ac9 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 075/114] 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 81da2e27..0d4a447f 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 076/114] 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 9c85f523..db745960 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 077/114] 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 8614270b..32837f3c 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 0d4a447f..4ae2e25b 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 dd4cf848..c4d193e8 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 8673698d..90a0af5b 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 bda60ac9..01edb601 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 078/114] 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 db745960..78effd74 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 00000000..ecafb2e0 --- /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 079/114] 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 2c554702..9416ca65 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 01edb601..10082f44 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 080/114] 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 9416ca65..82d5d882 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 081/114] 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 00000000..a75428ce --- /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 00000000..5d241806 --- /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 00000000..6ed63548 --- /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 082/114] 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 a75428ce..6d3c53b1 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 083/114] 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 6d3c53b1..527cd487 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 084/114] 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 572176fc..b92235be 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 1c867bd6..dd3850a4 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 085/114] 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 5041c401..36ddb41b 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 82d5d882..1c74eb6e 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 78effd74..21b25f10 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 086/114] 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 51b9330f..7de51241 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 4ae2e25b..9865e3c3 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 087/114] 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 00000000..d95906f7 --- /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 00000000..821ad707 --- /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 00000000..a78f5258 --- /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 088/114] 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 d95906f7..f5d7b7c8 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 821ad707..206f0784 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 3473abef..74794306 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 089/114] 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 74794306..9018307f 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 090/114] 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 00000000..977d9bfa --- /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 00000000..c169618c --- /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 00000000..e1305657 --- /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 091/114] 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 977d9bfa..94072ed0 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 092/114] 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 00000000..4ba7efcd --- /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 00000000..bbd7f3c1 --- /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 00000000..c7ee1aa0 --- /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 093/114] 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 1e0ecdef..d2ce5b05 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 094/114] 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 00000000..f34a2323 --- /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 00000000..63bfa81d --- /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 00000000..606d904f --- /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 095/114] 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 00000000..6df457a6 --- /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 00000000..f5a0e91d --- /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 00000000..b5b0f0b5 --- /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 096/114] 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 f34a2323..573564d5 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 00000000..63bfa81d --- /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 606d904f..bc271032 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 097/114] 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 6df457a6..b269f53d 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 098/114] 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 21b25f10..9a363fd0 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 00000000..7f15803a --- /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 ecafb2e0..00000000 --- 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 cb2876ae..dfd62a71 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 099/114] 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 9a363fd0..5c553410 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 100/114] 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 7de51241..3f282e15 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 5c553410..1cb2cdfa 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 101/114] Update CHANGELOG --- CHANGELOG.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d8e9026..8cdd8fd1 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 102/114] 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 98cb24a7..c632ae43 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 163490da..3bdd36d0 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 103/114] 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 1c74eb6e..3a09768d 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 9865e3c3..50057ea9 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 104/114] update readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d2ce5b05..47ff1273 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 105/114] 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 7a388eda..954e2a58 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 106/114] 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 47ff1273..8bc3564e 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 3f282e15..17eba40a 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 107/114] Added pint packages --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 91002ed8..9f8a2f7f 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 108/114] 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 00000000..a94f46cd --- /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 00000000..ab8eefe4 --- /dev/null +++ b/tests/Countries/SriLankaTest.php @@ -0,0 +1,10 @@ +get(); +})->throws(UnsupportedCountry::class); From 84511677c2ab3ecbaebc7ee46f02d3393d0700ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kowalewski?= Date: Mon, 22 Jan 2024 09:38:13 +0100 Subject: [PATCH 109/114] Polish holidays (#154) * poland * Fix polish holidays --------- Co-authored-by: fizgiel --- src/Countries/Poland.php | 42 +++++++++++++++ .../it_can_calculate_polish_holidays.snap | 54 +++++++++++++++++++ tests/Countries/PolandTest.php | 18 +++++++ 3 files changed, 114 insertions(+) create mode 100644 src/Countries/Poland.php create mode 100644 tests/.pest/snapshots/Countries/PolandTest/it_can_calculate_polish_holidays.snap create mode 100644 tests/Countries/PolandTest.php diff --git a/src/Countries/Poland.php b/src/Countries/Poland.php new file mode 100644 index 00000000..b6e111eb --- /dev/null +++ b/src/Countries/Poland.php @@ -0,0 +1,42 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Nowy Rok' => '01-01', + 'Święto Trzech Króli' => '01-06', + 'Święto Pracy' => '05-01', + 'Święto Konstytucji 3 Maja' => '05-03', + 'Święto Wojska Polskiego, Wniebowzięcie Najświętszej Maryi Panny' => '08-15', + 'Wszystkich Świętych' => '11-01', + 'Święto Niepodległości' => '11-11', + 'Boże Narodzenie' => '12-25', + 'Drugi Dzień Bożego Narodzenia' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Europe/Warsaw'); + + return [ + 'Wielkanoc' => $easter, + 'Poniedziałek Wielkanocny' => $easter->addDay(), + 'Zielone Świątki' => $easter->addWeeks(7), + 'Boże Ciało' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/PolandTest/it_can_calculate_polish_holidays.snap b/tests/.pest/snapshots/Countries/PolandTest/it_can_calculate_polish_holidays.snap new file mode 100644 index 00000000..a14c2115 --- /dev/null +++ b/tests/.pest/snapshots/Countries/PolandTest/it_can_calculate_polish_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Nowy Rok", + "date": "2024-01-01" + }, + { + "name": "\u015awi\u0119to Trzech Kr\u00f3li", + "date": "2024-01-06" + }, + { + "name": "Wielkanoc", + "date": "2024-03-31" + }, + { + "name": "Poniedzia\u0142ek Wielkanocny", + "date": "2024-04-01" + }, + { + "name": "\u015awi\u0119to Pracy", + "date": "2024-05-01" + }, + { + "name": "\u015awi\u0119to Konstytucji 3 Maja", + "date": "2024-05-03" + }, + { + "name": "Zielone \u015awi\u0105tki", + "date": "2024-05-19" + }, + { + "name": "Bo\u017ce Cia\u0142o", + "date": "2024-05-30" + }, + { + "name": "\u015awi\u0119to Wojska Polskiego, Wniebowzi\u0119cie Naj\u015bwi\u0119tszej Maryi Panny", + "date": "2024-08-15" + }, + { + "name": "Wszystkich \u015awi\u0119tych", + "date": "2024-11-01" + }, + { + "name": "\u015awi\u0119to Niepodleg\u0142o\u015bci", + "date": "2024-11-11" + }, + { + "name": "Bo\u017ce Narodzenie", + "date": "2024-12-25" + }, + { + "name": "Drugi Dzie\u0144 Bo\u017cego Narodzenia", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/PolandTest.php b/tests/Countries/PolandTest.php new file mode 100644 index 00000000..25a75ebc --- /dev/null +++ b/tests/Countries/PolandTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From ac17b38fae55c04687aa04cd129742c6985becd3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:39:09 +0100 Subject: [PATCH 110/114] cleanup Poland --- src/Countries/Poland.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/Poland.php b/src/Countries/Poland.php index b6e111eb..86dcf369 100644 --- a/src/Countries/Poland.php +++ b/src/Countries/Poland.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'pl'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -30,7 +29,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Europe/Warsaw'); + $easter = $this->easter($year); return [ 'Wielkanoc' => $easter, From a7f766e4fd648304a1ae425fc28bab1a5ebbed56 Mon Sep 17 00:00:00 2001 From: Martin Welte Date: Mon, 22 Jan 2024 12:17:11 +0100 Subject: [PATCH 111/114] Add Support for Liechtenstein (#33) * feat: add liechtenstein * test: add test for liechtenstein --- src/Countries/Liechtenstein.php | 43 +++++++++++++++ ..._can_calculate_liechtenstein_holidays.snap | 54 +++++++++++++++++++ tests/Countries/LiechtensteinTest.php | 18 +++++++ 3 files changed, 115 insertions(+) create mode 100644 src/Countries/Liechtenstein.php create mode 100644 tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap create mode 100644 tests/Countries/LiechtensteinTest.php diff --git a/src/Countries/Liechtenstein.php b/src/Countries/Liechtenstein.php new file mode 100644 index 00000000..dea95a0c --- /dev/null +++ b/src/Countries/Liechtenstein.php @@ -0,0 +1,43 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Neujahr' => '01-01', + 'Heilige Drei Könige' => '01-06', + 'Tag der Arbeit' => '05-01', + 'Staatsfeiertag / Mariä Himmelfahrt' => '08-15', + 'Mariä Geburt' => '09-08', + 'Allerheiligen' => '11-01', + 'Mariä Empfängnis' => '12-08', + 'Weihnachten' => '12-25', + 'Stephanstag' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp($this->easter($year)) + ->setTimezone('Europe/Vaduz'); + + return [ + 'Ostermontag' => $easter->addDay(), + 'Auffahrt' => $easter->addDays(39), + 'Pfingstmontag' => $easter->addDays(50), + 'Fronleichnam' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap b/tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap new file mode 100644 index 00000000..7c23985e --- /dev/null +++ b/tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Ostermontag", + "date": "1970-01-02" + }, + { + "name": "Auffahrt", + "date": "1970-02-09" + }, + { + "name": "Pfingstmontag", + "date": "1970-02-20" + }, + { + "name": "Fronleichnam", + "date": "1970-03-02" + }, + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Heilige Drei K\u00f6nige", + "date": "2024-01-06" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Staatsfeiertag \/ Mari\u00e4 Himmelfahrt", + "date": "2024-08-15" + }, + { + "name": "Mari\u00e4 Geburt", + "date": "2024-09-08" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "Mari\u00e4 Empf\u00e4ngnis", + "date": "2024-12-08" + }, + { + "name": "Weihnachten", + "date": "2024-12-25" + }, + { + "name": "Stephanstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/LiechtensteinTest.php b/tests/Countries/LiechtensteinTest.php new file mode 100644 index 00000000..00b62a5c --- /dev/null +++ b/tests/Countries/LiechtensteinTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From e5d1f98257c94863857814254690051cb05e229d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:17:47 +0100 Subject: [PATCH 112/114] cleanup Liechtenstein --- src/Countries/Liechtenstein.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Countries/Liechtenstein.php b/src/Countries/Liechtenstein.php index dea95a0c..372e5974 100644 --- a/src/Countries/Liechtenstein.php +++ b/src/Countries/Liechtenstein.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'li'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -30,8 +29,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp($this->easter($year)) - ->setTimezone('Europe/Vaduz'); + $easter = $this->easter($year); return [ 'Ostermontag' => $easter->addDay(), From 4b398f1fc3d26b92b4129b1e7e8783bbce6c4ba0 Mon Sep 17 00:00:00 2001 From: Martin Welte Date: Mon, 22 Jan 2024 13:41:50 +0100 Subject: [PATCH 113/114] test: update liechtenstein snapshot (#164) --- ..._can_calculate_liechtenstein_holidays.snap | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap b/tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap index 7c23985e..15498d19 100644 --- a/tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap +++ b/tests/.pest/snapshots/Countries/LiechtensteinTest/it_can_calculate_liechtenstein_holidays.snap @@ -1,31 +1,31 @@ [ { - "name": "Ostermontag", - "date": "1970-01-02" + "name": "Neujahr", + "date": "2024-01-01" }, { - "name": "Auffahrt", - "date": "1970-02-09" + "name": "Heilige Drei K\u00f6nige", + "date": "2024-01-06" }, { - "name": "Pfingstmontag", - "date": "1970-02-20" + "name": "Ostermontag", + "date": "2024-04-01" }, { - "name": "Fronleichnam", - "date": "1970-03-02" + "name": "Tag der Arbeit", + "date": "2024-05-01" }, { - "name": "Neujahr", - "date": "2024-01-01" + "name": "Auffahrt", + "date": "2024-05-09" }, { - "name": "Heilige Drei K\u00f6nige", - "date": "2024-01-06" + "name": "Pfingstmontag", + "date": "2024-05-20" }, { - "name": "Tag der Arbeit", - "date": "2024-05-01" + "name": "Fronleichnam", + "date": "2024-05-30" }, { "name": "Staatsfeiertag \/ Mari\u00e4 Himmelfahrt", From 48bb3ba0c84f514bccfafc50c7eccc5adf0f912e Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:43:50 +0100 Subject: [PATCH 114/114] reduce baseline errors --- phpstan-baseline.neon | 15 --------------- src/Countries/Netherlands.php | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 17eba40a..8364bfa9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -30,21 +30,6 @@ parameters: count: 1 path: src/Countries/Mexico.php - - - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Netherlands.php - - - - message: "#^Cannot call method subDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Netherlands.php - - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Netherlands\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Netherlands.php - - message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Carbon\\\\CarbonImmutable\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#" count: 1 diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index 91abc9bd..9c366ad5 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -24,6 +24,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { + /** @var CarbonImmutable $koningsDag */ $koningsDag = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-04-27"); if ($koningsDag->isSunday()) {