From 8ef9b967c9e56a5f143a258ab4facb3a1af160ac Mon Sep 17 00:00:00 2001 From: Javier Altez Date: Wed, 7 Feb 2024 10:14:38 +0100 Subject: [PATCH 01/50] Add Spanish Holidays (#34) * Add Spanish Holidays * Holidays added by region for the current year. * Regional holidays: 2023, 2022 * Variable naming as holidays. * Added exceptions and null region check. * Change to custom exceptions. --- src/Countries/Spain.php | 394 ++++++++++++++++++ .../it_can_calculate_spanish_holidays.snap | 42 ++ ...n_calculate_spanish_regional_holidays.snap | 54 +++ tests/Countries/SpainTest.php | 31 ++ 4 files changed, 521 insertions(+) create mode 100644 src/Countries/Spain.php create mode 100644 tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap create mode 100644 tests/Countries/SpainTest.php diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php new file mode 100644 index 000000000..1a005e638 --- /dev/null +++ b/src/Countries/Spain.php @@ -0,0 +1,394 @@ + '01-01', + 'Epifanía del Señor' => '01-06', + 'Día del Trabajador' => '05-01', + 'Asunción de la Virgen' => '08-15', + 'Fiesta Nacional de España' => '10-12', + 'Todos los Santos' => '11-01', + 'Día de la Constitución Española' => '12-06', + 'Inmaculada Concepción' => '12-08', // 2024? + 'Navidad' => '12-25' + ], + $this->variableHolidays($year), + $this->regionHolidays($year), + ); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Viernes Santo' => $easter->subDays(2), + ]; + } + + /** @return array */ + protected function regionHolidays(int $year): array + { + if ($this->region === null) { + return []; + } + + $method = "regionHolidays{$year}"; + if (method_exists($this, $method)) { + return $this->$method(); + } else { + throw InvalidYear::range($this->countryCode() . " ({$this->region})", 2022, 2024); + } + } + + /** @return array */ + protected function regionHolidays2022(): array + { + $juevesSanto = ['Jueves Santo' => '04-14']; + $lunesPascua = ['Lunes de Pascua' => '04-18']; + $fiestaTrabajo = ['Lunes siguiente a la Fiesta del Trabajo' => '05-02']; + $sanJuan = ['San Juan' => '06-24']; + $santiagoApostol = ['Santiago Apóstol' => '07-25']; + $navidad = ['Lunes siguiente a Navidad' => '12-26']; + + return match ($this->region) { + // Andalucía + 'es-an' => [ + 'Día de Andalucía' => '02-28', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Aragón + 'es-ar' => [ + 'Lunes siguiente a San Jorge, Día de Aragón' => '04-23', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Principado de Asturias + 'es-as' => [ + 'Día de Asturias' => '09-08', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Cantabria + 'es-cb' => [ + 'Día de las Instituciones de Cantabria' => '07-28', + 'La Bien Aparecida' => '09-15', + ] + $juevesSanto + $navidad, + + // Ciudad Autónoma de Ceuta + 'es-ce' => [ + 'Fiesta del Sacrificio Eid al-Adha' => '07-09', + 'Nuestra Señora de África' => '08-05', + 'Día de Ceuta' => '09-02', + ] + $juevesSanto, + + // Castilla y León + 'es-cl' => [ + 'Día de Castilla y León' => '04-23', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Castilla-La Mancha + 'es-cm' => [ + 'Día de Castilla-La Mancha' => '05-31', + 'Corpus Christi' => '06-16', + ] + $juevesSanto + $navidad, + + // Canarias + 'es-cn' => [ + 'Día de Canarias' => '05-30', + ] + $juevesSanto + $navidad, + + // Cataluña / Catalunya + 'es-ct' => [ + 'Pascua Granada' => '06-06', + ] + $lunesPascua + $sanJuan + $navidad, + + // Extremadura + 'es-ex' => [ + 'Día de Extremadura' => '09-08', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Galicia + 'es-ga' => [ + 'Día de las Letras Gallegas' => '05-17', + 'Santiago Apóstol / Día de Galicia' => '07-25', + ] + $juevesSanto + $sanJuan, + + // Islas Baleares / Illes Balears + 'es-ib' => [ + 'Día de les Illes Balears' => '03-01', + ] + $juevesSanto + $lunesPascua + $navidad, + + // Región de Murcia + 'es-mc' => [ + 'Día de la Región de Murcia' => '06-09', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Comunidad de Madrid + 'es-md' => [ + 'Fiesta de la Comunidad de Madrid' => '05-02', + ] + $juevesSanto + $santiagoApostol + $navidad, + + // Ciudad Autónoma de Melilla + 'es-ml' => [ + 'Fiesta del Eid al-Fitr' => '05-03', + 'Fiesta del Sacrificio Eid al-Adha' => '07-11' + ] + $juevesSanto + $navidad, + + // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea + 'es-nc' => $juevesSanto + $lunesPascua + $santiagoApostol + $navidad, + + // País Vasco / Euskal Herria + 'es-pv' => [ + 'V Centenario de la Primera Vuelta al Mundo' => '09-06', + ] + $juevesSanto + $lunesPascua + $santiagoApostol, + + // La Rioja + 'es-ri' => [ + 'Día de La Rioja' => '06-09', + ] + $juevesSanto + $lunesPascua + $navidad, + + // Comunidad Valenciana / Comunitat Valenciana + 'es-vc' => [ + 'Día de la Comunidad Valenciana' => '10-09', + 'San José' => '03-19', + ] + $juevesSanto + $lunesPascua + $sanJuan, + + default => throw InvalidRegion::notFound($this->region), + }; + } + + /** @return array */ + protected function regionHolidays2023(): array + { + $anoNuevo = ['Lunes siguiente a la Fiesta de Año Nuevo' => '01-02']; + $jueveSanto = ['Jueves Santo' => '04-06']; + $lunesPascua = ['Lunes de Pascua' => '04-10']; + $sanJuan = ['San Juan' => '06-24']; + $fiestaSacrificio = ['Fiesta del Sacrificio Eid al-Adha' => '06-29']; + $santiagoApostol = ['Santiago Apóstol' => '07-25']; + + return match ($this->region) { + // Andalucía + 'es-an' => [ + 'Día de Andalucía' => '02-28', + ] + $anoNuevo + $jueveSanto, + + // Aragón + 'es-ar' => [ + 'Lunes siguiente a San Jorge, Día de Aragón' => '04-24', + ] + $anoNuevo + $jueveSanto, + + // Principado de Asturias + 'es-as' => [ + 'Día de Asturias' => '09-08', + ] + $anoNuevo + $jueveSanto, + + // Cantabria + 'es-cb' => [ + 'Día de las Instituciones de Cantabria' => '07-28', + 'La Bien Aparecida' => '09-15', + ] + $jueveSanto, + + // Ciudad Autónoma de Ceuta + 'es-ce' => [ + 'Nuestra Señora de África' => '08-05', + 'Día de Ceuta' => '09-02', + ] + $jueveSanto + $fiestaSacrificio, + + // Castilla y León + 'es-cl' => $anoNuevo + $jueveSanto + $santiagoApostol, + + // Castilla-La Mancha + 'es-cm' => [ + 'Día de Castilla-La Mancha' => '05-31', + 'Corpus Christi' => '06-08', + ] + $jueveSanto, + + // Canarias + 'es-cn' => [ + 'Día de Canarias' => '05-30', + ] + $jueveSanto, + + // Cataluña / Catalunya + 'es-ct' => [ + 'Fiesta Nacional de Cataluña' => '09-11', + 'San Esteban' => '12-26', + ] + $lunesPascua + $sanJuan, + + // Extremadura + 'es-ex' => [ + 'Carnaval' => '02-13', + 'Día de Extremadura' => '09-08', + ] + $jueveSanto, + + // Galicia + 'es-ga' => [ + 'Día de las Letras Gallegas' => '05-17', + 'Santiago Apóstol / Día de Galicia' => '07-25', + ] + $jueveSanto, + + // Islas Baleares / Illes Balears + 'es-ib' => [ + 'Día de les Illes Balears' => '03-01', + ] + $lunesPascua, + + // Región de Murcia + 'es-mc' => [ + 'Día de la Región de Murcia' => '06-09', + ] + $anoNuevo + $jueveSanto, + + // Comunidad de Madrid + 'es-md' => [ + 'Lunes siguiente A San José' => '03-20', + 'Fiesta de la Comunidad de Madrid' => '05-02', + ] + $jueveSanto, + + // Ciudad Autónoma de Melilla + 'es-ml' => [ + 'Fiesta del Eid al-Fitr' => '04-21', + ] + $jueveSanto + $fiestaSacrificio, + + // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea + 'es-nc' => $jueveSanto + $lunesPascua + $santiagoApostol, + + // País Vasco / Euskal Herria + 'es-pv' => $jueveSanto + $lunesPascua + $santiagoApostol, + + // La Rioja + 'es-ri' => [ + 'Día de La Rioja' => '06-09', + ] + $jueveSanto + $lunesPascua, + + // Comunidad Valenciana / Comunitat Valenciana + 'es-vc' => [ + 'Día de la Comunidad Valenciana' => '10-09', + ] + $lunesPascua + $sanJuan, + + default => throw InvalidRegion::notFound($this->region), + }; + } + + /** @return array */ + protected function regionHolidays2024(): array + { + $sanJose = ['San José' => '03-19']; + $juevesSanto = ['Jueves Santo' => '03-28']; + $lunesPascua = ['Lunes de Pascua' => '04-01']; + $fiestaSacrificio = ['Fiesta del Sacrificio Eid al-Adha' => '06-17']; + $sanJuan = ['San Juan' => '06-24']; + $santiagoApostol = ['Santiago Apóstol' => '07-25']; + $inmaculadaConcepcion = ['Lunes siguiente a la Inmaculada Concepción' => '12-09']; + + return match ($this->region) { + // Andalucía + 'es-an' => [ + 'Día de Andalucía' => '02-28', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Aragón + 'es-ar' => [ + 'San Jorge / Día de Aragón' => '04-23', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Principado de Asturias + 'es-as' => [ + 'Lunes siguiente al Día de Asturias' => '09-09', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Cantabria + 'es-cb' => $juevesSanto + $lunesPascua + $santiagoApostol, + + // Ciudad Autónoma de Ceuta + 'es-ce' => [ + 'Nuestra Señora de África' => '08-05', + ] + $juevesSanto + $fiestaSacrificio, + + // Castilla y León + 'es-cl' => [ + 'Fiesta de Castilla y León' => '04-23', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Castilla-La Mancha + 'es-cm' => [ + 'Corpus Christi' => '05-30', + 'Día de Castilla-La Mancha' => '05-31', + ] + $juevesSanto, + + // Canarias + 'es-cn' => [ + 'Día de Canarias' => '05-30', + ] + $juevesSanto, + + // Cataluña / Catalunya + 'es-ct' => [ + 'Fiesta Nacional de Cataluña' => '09-11', + 'San Esteban' => '12-26', + ] + $lunesPascua + $sanJuan, + + // Extremadura + 'es-ex' => [ + 'Carnaval' => '02-13', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Galicia + 'es-ga' => [ + 'Día de las Letras Gallegas' => '05-17', + 'Santiago Apóstol / Día de Galicia' => '07-25', + ] + $juevesSanto, + + // Islas Baleares / Illes Balears + 'es-ib' => [ + 'Día de les Illes Balears' => '03-01', + ] + $juevesSanto + $lunesPascua, + + // Región de Murcia + 'es-mc' => $sanJose + $juevesSanto + $inmaculadaConcepcion, + + // Comunidad de Madrid + 'es-md' => [ + 'Fiesta de la Comunidad de Madrid' => '05-02', + ] + $juevesSanto + $santiagoApostol, + + // Ciudad Autónoma de Melilla + 'es-ml' => $juevesSanto + $fiestaSacrificio + $inmaculadaConcepcion, + + // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea + 'es-nc' => $juevesSanto + $lunesPascua + $santiagoApostol, + + // País Vasco / Euskal Herria + 'es-pv' => $juevesSanto + $lunesPascua + $santiagoApostol, + + // La Rioja + 'es-ri' => [ + 'Lunes siguiente al Día de La Rioja' => '06-10', + ] + $juevesSanto + $lunesPascua, + + // Comunidad Valenciana / Comunitat Valenciana + 'es-vc' => [ + 'Día de la Comunidad Valenciana' => '10-09', + ] + $sanJose + $lunesPascua + $sanJuan, + + default => throw InvalidRegion::notFound($this->region), + }; + } +} diff --git a/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap new file mode 100644 index 000000000..b9a396fe9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Epifan\u00eda del Se\u00f1or", + "date": "2024-01-06" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-15" + }, + { + "name": "Fiesta Nacional de Espa\u00f1a", + "date": "2024-10-12" + }, + { + "name": "Todos los Santos", + "date": "2024-11-01" + }, + { + "name": "D\u00eda de la Constituci\u00f3n Espa\u00f1ola", + "date": "2024-12-06" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap new file mode 100644 index 000000000..5684d7595 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Epifan\u00eda del Se\u00f1or", + "date": "2024-01-06" + }, + { + "name": "Jueves Santo", + "date": "2024-03-28" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "San Jorge \/ D\u00eda de Arag\u00f3n", + "date": "2024-04-23" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-15" + }, + { + "name": "Fiesta Nacional de Espa\u00f1a", + "date": "2024-10-12" + }, + { + "name": "Todos los Santos", + "date": "2024-11-01" + }, + { + "name": "D\u00eda de la Constituci\u00f3n Espa\u00f1ola", + "date": "2024-12-06" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Lunes siguiente a la Inmaculada Concepci\u00f3n", + "date": "2024-12-09" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/SpainTest.php b/tests/Countries/SpainTest.php new file mode 100644 index 000000000..3c39a62e2 --- /dev/null +++ b/tests/Countries/SpainTest.php @@ -0,0 +1,31 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate spanish regional holidays', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(Spain::make('es-ar'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 7fbed6101dc3ef180217d7063af3d78e4f847f29 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 09:14:57 +0000 Subject: [PATCH 02/50] Fix styling --- src/Countries/Spain.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php index 1a005e638..9a0afc6d4 100644 --- a/src/Countries/Spain.php +++ b/src/Countries/Spain.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array 'Todos los Santos' => '11-01', 'Día de la Constitución Española' => '12-06', 'Inmaculada Concepción' => '12-08', // 2024? - 'Navidad' => '12-25' + 'Navidad' => '12-25', ], $this->variableHolidays($year), $this->regionHolidays($year), @@ -58,7 +58,7 @@ protected function regionHolidays(int $year): array if (method_exists($this, $method)) { return $this->$method(); } else { - throw InvalidYear::range($this->countryCode() . " ({$this->region})", 2022, 2024); + throw InvalidYear::range($this->countryCode()." ({$this->region})", 2022, 2024); } } @@ -151,7 +151,7 @@ protected function regionHolidays2022(): array // Ciudad Autónoma de Melilla 'es-ml' => [ 'Fiesta del Eid al-Fitr' => '05-03', - 'Fiesta del Sacrificio Eid al-Adha' => '07-11' + 'Fiesta del Sacrificio Eid al-Adha' => '07-11', ] + $juevesSanto + $navidad, // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea From 3c5fccb0b44ac5762ad2e2984132c2ca59e37112 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:30:36 +0100 Subject: [PATCH 03/50] rename second Carnival day for Argentine --- src/Countries/Argentine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Argentine.php b/src/Countries/Argentine.php index c5ea425d9..50364797d 100644 --- a/src/Countries/Argentine.php +++ b/src/Countries/Argentine.php @@ -16,7 +16,7 @@ protected function allHolidays(int $year): array return array_merge([ 'Día de Año Nuevo' => '01-01', 'Carnaval' => '12-02', - 'Carnaval' => '13-02', + 'Carnaval Día 2' => '13-02', 'Día Nacional de la Memoria por la Verdad y la Justicia' => '24-04', 'Día del Veterano y de los Caídos en la Guerra de Malvinas' => '02-04', 'Día del Trabajador' => '05-01', From f3858d64d23cea9d00f9f87e47dae8ecc3583fc4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:32:07 +0100 Subject: [PATCH 04/50] fix phpstan issues with Spain --- src/Countries/Spain.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php index 9a0afc6d4..27a7f166f 100644 --- a/src/Countries/Spain.php +++ b/src/Countries/Spain.php @@ -173,6 +173,7 @@ protected function regionHolidays2022(): array 'San José' => '03-19', ] + $juevesSanto + $lunesPascua + $sanJuan, + null => [], default => throw InvalidRegion::notFound($this->region), }; } @@ -284,6 +285,7 @@ protected function regionHolidays2023(): array 'Día de la Comunidad Valenciana' => '10-09', ] + $lunesPascua + $sanJuan, + null => [], default => throw InvalidRegion::notFound($this->region), }; } @@ -388,6 +390,7 @@ protected function regionHolidays2024(): array 'Día de la Comunidad Valenciana' => '10-09', ] + $sanJose + $lunesPascua + $sanJuan, + null => [], default => throw InvalidRegion::notFound($this->region), }; } From fc6c650fef61b2e133324324b196bd1c933d0b64 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:32:31 +0100 Subject: [PATCH 05/50] update argentina snapshot --- .../it_can_calculate_argentinians_holidays.snap | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap b/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap index ed25e78a8..aaa0aa671 100644 --- a/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap +++ b/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap @@ -23,12 +23,16 @@ "name": "D\u00eda de la Independencia", "date": "2024-09-07" }, + { + "name": "Carnaval", + "date": "2024-12-02" + }, { "name": "Navidad", "date": "2024-12-25" }, { - "name": "Carnaval", + "name": "Carnaval D\u00eda 2", "date": "2025-01-02" }, { From 05873e7d602ab9977b743e108805073ea83355ab Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:42:51 +0100 Subject: [PATCH 06/50] run test suite with carbon v2 and v3 --- .github/workflows/run-tests.yml | 5 ++++- composer.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 780a74427..84f9eb311 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,6 +12,7 @@ jobs: os: [ubuntu-latest] php: [8.3, 8.2, 8.1] stability: [prefer-lowest, prefer-stable] + carbon: [2.72, 3.0] name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -32,7 +33,9 @@ jobs: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install dependencies - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + run: | + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} --prefer-dist --no-interaction - name: List Installed Dependencies run: composer show -D diff --git a/composer.json b/composer.json index d51ff2f1e..46ef42ee3 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require": { "php": "^8.1", "ext-intl": "*", - "nesbot/carbon": "^2.72.1" + "nesbot/carbon": "^2.72.1|^3.0" }, "require-dev": { "laravel/pint": "^1.0", From 78111895c3a7f736961c215665f1e7906e97e699 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:00:56 +0100 Subject: [PATCH 07/50] upgrade all carbon dependencies too in the tests --- .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 84f9eb311..80a2047bf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -35,7 +35,7 @@ jobs: - name: Install dependencies run: | composer update --${{ matrix.stability }} --prefer-dist --no-interaction - composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} --prefer-dist --no-interaction + composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} -W --prefer-dist --no-interaction - name: List Installed Dependencies run: composer show -D From 4ceb5750fab046ca8c57b41c2615f7ba7dbd4dcf Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:15:02 +0100 Subject: [PATCH 08/50] phpstan fixes after migrating to carbon v3 --- src/Countries/Australia.php | 2 +- src/Countries/Colombia.php | 10 ++++++---- src/Countries/Finland.php | 3 ++- src/Countries/Jamaica.php | 3 ++- src/Countries/NorthernIreland.php | 7 ++++--- src/Countries/Scotland.php | 9 +++++---- src/Countries/Sweden.php | 2 +- src/Countries/Wales.php | 11 ++++++----- 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 3de478baa..b17c853fa 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -41,7 +41,7 @@ protected function variableHolidays(int $year): array 'Canberra Day' => CarbonImmutable::parse("second monday of march {$year}"), 'Easter Saturday' => $easter->subDay(), 'Easter Sunday' => $easter, - 'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)->modify('monday'), + 'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)?->modify('monday'), $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), 'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"), ], diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php index f3176f794..999264e9d 100644 --- a/src/Countries/Colombia.php +++ b/src/Countries/Colombia.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Colombia extends Country { @@ -23,7 +24,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); @@ -45,13 +46,14 @@ protected function variableHolidays(int $year): array ]; } - private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable + private function emilianiHoliday(int $year, int $month, int $day): CarbonInterface { $dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); + if ($dateObj->is('Monday')) { return $dateObj; - } else { - return $dateObj->next('Monday'); } + + return $dateObj->next('Monday'); } } diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 69fa1fd39..32e75c649 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Finland extends Country { @@ -29,7 +30,7 @@ protected function fixedHolidays(int $year): array ]; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index e9b3af3d4..751fb994b 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Jamaica extends Country { @@ -52,7 +53,7 @@ protected function variableHolidays(int $year): array ]; } - /** @return array */ + /** @return array */ protected function observedHolidays(int $year): array { diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 889fa513e..cb424980f 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class NorthernIreland extends Wales { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-nir'; } - /** @return array */ + /** @return array */ private function stPatricksDay(int $year): array { $stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London'); @@ -25,7 +26,7 @@ private function stPatricksDay(int $year): array return [$key => $stPatricksDay]; } - /** @return array */ + /** @return array */ private function battleOfTheBoyne(int $year): array { $battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London'); @@ -51,7 +52,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index 09e2ea097..f70145325 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Scotland extends Wales { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-sct'; } - /** @return array */ + /** @return array */ protected function secondOfJanuary(int $year): array { $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); @@ -31,7 +32,7 @@ protected function secondOfJanuary(int $year): array return [$key => $secondOfJanuary]; } - /** @return array */ + /** @return array */ private function stAndrewsDay(int $year): array { $stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London'); @@ -45,7 +46,7 @@ private function stAndrewsDay(int $year): array return [$key => $stAndrewsDay]; } - /** @return array */ + /** @return array */ protected function oneOffHolidays(int $year): array { return match ($year) { @@ -57,7 +58,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( diff --git a/src/Countries/Sweden.php b/src/Countries/Sweden.php index e16eae6eb..fce4f7135 100644 --- a/src/Countries/Sweden.php +++ b/src/Countries/Sweden.php @@ -24,7 +24,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index 7468ba889..33e1ca3b8 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Wales extends Country { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-cym'; } - /** @return array */ + /** @return array */ protected function christmasDay(int $year): array { $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); @@ -30,7 +31,7 @@ protected function christmasDay(int $year): array return [$key => $christmasDay]; } - /** @return array */ + /** @return array */ protected function boxingDay(int $year): array { $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); @@ -50,7 +51,7 @@ protected function boxingDay(int $year): array return [$key => $boxingDay]; } - /** @return array */ + /** @return array */ protected function newYearsDay(int $year): array { $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); @@ -64,7 +65,7 @@ protected function newYearsDay(int $year): array return [$key => $newYearsDay]; } - /** @return array */ + /** @return array */ protected function earlyMayBankHoliday(int $year): array { if ($year === 2020) { @@ -96,7 +97,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( From 34d6ccd061ca1cc97fa52295990563640ada0f0c Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:15:13 +0100 Subject: [PATCH 09/50] update baseline --- phpstan-baseline.neon | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b253bace3..dffb82781 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,34 +1,14 @@ parameters: ignoreErrors: - - - message: "#^Cannot call method modify\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Australia.php - - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 path: src/Countries/Country.php - - message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 2 - path: src/Countries/Country.php - - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\ but returns array\\\\.$#" - 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 - path: src/Countries/Country.php - - - - message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 2 - path: src/Countries/Sweden.php + message: "#^Ternary operator condition is always true\\.$#" + count: 3 + path: src/Countries/Turkey.php - message: "#^Cannot call method setTimeStamp\\(\\) on DateTime\\|false\\.$#" From 4e859b0e18ce39de0cfad13703b4ce60aaa5574f Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 10:20:29 +0000 Subject: [PATCH 10/50] Update CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9f22404d..3490335e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to `holidays` will be documented in this file. +## 1.6.0 - 2024-02-07 + +### What's Changed + +* Add holidays for Argentine by @damian-developer in https://github.com/spatie/holidays/pull/200 +* Add Spanish Holidays by @jaltez in https://github.com/spatie/holidays/pull/34 +* Add support for Carbon v3 by @Nielsvanpach in https://github.com/spatie/holidays/pull/204 + +### New Contributors + +* @damian-developer made their first contribution in https://github.com/spatie/holidays/pull/200 +* @jaltez made their first contribution in https://github.com/spatie/holidays/pull/34 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.5.1...1.6.0 + ## 1.5.1 - 2024-02-01 Fix translations for Albania & Iran From 9df73f865671e3f7ca7bb1d9c50ad5e44205b35b Mon Sep 17 00:00:00 2001 From: Wessam Ahmed Date: Wed, 7 Feb 2024 12:39:54 +0200 Subject: [PATCH 11/50] Add Egyptian holidays (#155) * Add Egyptian holidays * For consistency * Minor enhancements * Rename holiday * Minor * Minor * Pint * Rename test * Rename method * Early return * Docblock * Docblock * Add New Year's * Minor * Add holidays statically/Turkey solution * Fix translations * Minor * Remove snapshot * This can be misunderstood * Add more translations --------- Co-authored-by: Wessam Ahmed --- lang/egypt/ar/holidays.json | 46 ++- lang/egypt/en/holidays.json | 33 ++ src/Countries/Egypt.php | 365 ++++++++++++++++-- .../it_can_calculate_egypt_holidays.snap | 86 ----- .../it_can_calculate_egyptian_holidays.snap | 130 +++++++ tests/Countries/EgyptTest.php | 9 +- 6 files changed, 536 insertions(+), 133 deletions(-) create mode 100644 lang/egypt/en/holidays.json delete mode 100644 tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap diff --git a/lang/egypt/ar/holidays.json b/lang/egypt/ar/holidays.json index 2ca7af8d3..efdf7779f 100644 --- a/lang/egypt/ar/holidays.json +++ b/lang/egypt/ar/holidays.json @@ -1,23 +1,33 @@ { - "New Year\n's Day": "يوم رأس السنة", - "Coptic Christmas": "عيد الميلاد القبطي", - "Revolution Day January 25": "عيد ثورة 25 يناير", + "New Year\\'s Day": "رأس السنة الميلادية", + "Coptic Christmas Day": "عيد الميلاد المجيد", + "Revolution Day 2011": "ثورة ٢٥ يناير وعيد الشرطة", "March Equinox": "اعتدال مارس", - "Sinai Liberation": "تحرير سيناء", - "Labor": "العمل", - "Coptic Good": "الصالح القبطي", - "Coptic Holy": "المقدس القبطي", - "Coptic Easter": "عيد الفصح القبطي", - "Spring Festival": "مهرجان الربيع", - "June Solstice": "انقلاب يونيو", - "June 30 Revolution": "ثورة 30 يونيو", - "Day off for June 30 Revolution": "يوم عطلة بمناسبة ثورة 30 يونيو", - "Revolution Day July 23": "عيد ثورة 23 يوليو", - "Day off for Revolution Day July 23": "يوم عطلة بمناسبة عيد ثورة 23 يوليو", + "Sinai Liberation Day": "عيد تحرير سيناء (٢٥ أبريل ١٩٨٢)", + "Labour Day": "عيد العمال", + "Coptic Good Friday": "الصالح القبطي", + "Coptic Holy Saturday": "المقدس القبطي", + "Coptic Easter Sunday": "عيد الفصح القبطي", + "Spring Festival": "عيد شم النسيم", + "June Solstice": "الانقلاب الشمسي في يونيو", + "June 30 Revolution Day": "عيد ثورة 30 يونيو", + "Day off for June 30 Revolution Day": "بمناسبة عيد ثورة 30 يونيو", + "Revolution Day": "عيد ثورة 23 يوليو", + "Day off for Revolution Day": "بمناسبة عيد ثورة 23 يوليو", "Flooding of the Nile": "فيضان النيل", "Nayrouz": "النيروز", "September Equinox": "الاعتدال في سبتمبر", - "Armed Forces": "القوات المسلحة", - "Day off for Armed Forces": "يوم عطلة للقوات المسلحة", - "December Solstice": "الانقلاب الشمسي في ديسمبر" -} \ No newline at end of file + "Armed Forces Day": "عيد القوات المسلحة (٦ أكتوبر ١٩٧٣)", + "Day off for Armed Forces Day": "يوم عطلة للقوات المسلحة", + "December Solstice": "الانقلاب الشمسي في ديسمبر", + "Eid al-Fitr": "عيد الفطر المبارك", + "Eid al-Fitr Day 2": "عيد الفطر المبارك", + "Eid al-Fitr Day 3": "عيد الفطر المبارك", + "Eid al-Adha": "عيد الأضحى المبارك", + "Eid al-Adha Day 2": "عيد الأضحى المبارك", + "Eid al-Adha Day 3": "عيد الأضحى المبارك", + "Eid al-Adha Day 4": "عيد الأضحى المبارك", + "Islamic New Year": "رأس السنة الهجرية", + "Birthday of the Prophet Muhammad": "المولد النبوي الشريف", + "Arafat Day": "يوم عرفة (وقفة عيد الأضحى)" +} diff --git a/lang/egypt/en/holidays.json b/lang/egypt/en/holidays.json new file mode 100644 index 000000000..a503639ee --- /dev/null +++ b/lang/egypt/en/holidays.json @@ -0,0 +1,33 @@ +{ + "New Year\\'s Day": "New Year\\'s Day", + "Coptic Christmas Day": "Coptic Christmas Day", + "Revolution Day 2011": "Revolution Day 2011", + "March Equinox": "March Equinox", + "Sinai Liberation Day": "Sinai Liberation Day", + "Labour Day": "Labour Day", + "Coptic Good Friday": "Coptic Good Friday", + "Coptic Holy Saturday": "Coptic Holy Saturday", + "Coptic Easter Sunday": "Coptic Easter Sunday", + "Spring Festival": "Spring Festival", + "June Solstice": "June Solstice", + "June 30 Revolution Day": "June 30 Revolution Day", + "Day off for June 30 Revolution Day": "Day off for June 30 Revolution Day", + "Revolution Day": "Revolution Day", + "Day off for Revolution Day": "Day off for Revolution Day", + "Flooding of the Nile": "Flooding of the Nile", + "Nayrouz": "Nayrouz", + "September Equinox": "September Equinox", + "Armed Forces Day": "Armed Forces Day", + "Day off for Armed Forces Day": "Day off for Armed Forces", + "December Solstice": "December Solstice", + "Eid al-Fitr": "Eid al-Fitr", + "Eid al-Fitr Day 2": "Eid al-Fitr", + "Eid al-Fitr Day 3": "Eid al-Fitr", + "Eid al-Adha": "Eid al-Adha", + "Eid al-Adha Day 2": "Eid al-Adha", + "Eid al-Adha Day 3": "Eid al-Adha", + "Eid al-Adha Day 4": "Eid al-Adha", + "Islamic New Year": "Islamic New Year (Muharram)", + "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", + "Arafat Day": "Arafat Day", +} diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index 4154b53f4..52ec78672 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -3,45 +3,360 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; +use RuntimeException; class Egypt extends Country { + protected const EID_AL_FITR_HOLIDAYS = [ + 2005 => '11-04', + 2006 => '10-24', + 2007 => '10-13', + 2008 => '10-02', + 2009 => '09-21', + 2010 => '09-10', + 2011 => '08-30', + 2012 => '08-19', + 2013 => '08-08', + 2014 => '07-28', + 2015 => '07-17', + 2016 => '07-07', + 2017 => '06-26', + 2018 => '06-15', + 2019 => '06-05', + 2020 => '05-24', + 2021 => '05-13', + 2022 => '05-02', + 2023 => '04-20', + 2024 => '04-10', + 2025 => '03-31', + 2026 => '03-21', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-04', + 2031 => '01-25', + 2032 => '01-15', + 2033 => '01-03', + 2034 => '12-13', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-09', + ]; + + protected const ARAFAT_DAY_HOLIDAYS = [ + 2005 => '01-21', + 2006 => '01-10', + 2007 => '01-01', + 2008 => '12-09', + 2009 => '11-26', + 2010 => '11-15', + 2011 => '11-05', + 2012 => '10-25', + 2013 => '10-15', + 2014 => '10-04', + 2015 => '09-23', + 2016 => '09-11', + 2017 => '08-31', + 2018 => '08-20', + 2019 => '08-10', + 2020 => '07-30', + 2021 => '07-19', + 2022 => '07-09', + 2023 => '06-27', + 2024 => '06-16', + 2025 => '06-06', + 2026 => '05-26', + 2027 => '05-16', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-13', + 2031 => '04-02', + 2032 => '03-21', + 2033 => '03-11', + 2034 => '03-01', + 2035 => '02-18', + 2036 => '02-07', + 2037 => '01-26', + ]; + + protected const EID_AL_ADHA_HOLIDAYS = [ + 2005 => '01-22', + 2006 => '01-11', + 2007 => '01-02', + 2008 => '12-10', + 2009 => '11-27', + 2010 => '11-16', + 2011 => '11-06', + 2012 => '10-26', + 2013 => '10-16', + 2014 => '10-05', + 2015 => '09-24', + 2016 => '09-12', + 2017 => '08-31', + 2018 => '08-21', + 2019 => '08-11', + 2020 => '07-31', + 2021 => '07-20', + 2022 => '07-09', + 2023 => '06-28', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-06', + 2029 => '04-25', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-02', + 2035 => '02-19', + 2036 => '02-08', + 2037 => '01-27', + ]; + + protected const ISLAMIC_NEW_YEAR_HOLIDAYS = [ + 2005 => '02-10', + 2006 => '01-31', + 2007 => '01-20', + 2008 => '01-10', + 2009 => '12-18', + 2010 => '12-07', + 2011 => '11-27', + 2012 => '11-15', + 2013 => '11-05', + 2014 => '10-25', + 2015 => '10-14', + 2016 => '10-03', + 2017 => '09-22', + 2018 => '09-11', + 2019 => '08-31', + 2020 => '08-20', + 2021 => '08-09', + 2022 => '07-30', + 2023 => '07-19', + 2024 => '07-08', + 2025 => '06-06', + 2026 => '06-17', + 2027 => '06-07', + 2028 => '05-26', + 2029 => '05-15', + 2030 => '05-05', + 2031 => '04-24', + 2032 => '04-12', + 2033 => '04-01', + 2034 => '03-22', + 2035 => '03-12', + 2036 => '02-29', + 2037 => '02-17', + ]; + + protected const ASHURA_HOLIDAYS = [ + 2005 => '02-19', + 2006 => '02-09', + 2007 => '01-29', + 2008 => '01-19', + 2009 => '12-27', + 2010 => '12-16', + 2011 => '12-06', + 2012 => '11-25', + 2013 => '11-15', + 2014 => '11-04', + 2015 => '10-24', + 2016 => '10-13', + 2017 => '10-02', + 2018 => '09-21', + 2019 => '09-10', + 2020 => '08-30', + 2021 => '08-19', + 2022 => '08-08', + 2023 => '07-28', + 2024 => '07-17', + 2025 => '07-07', + 2026 => '06-26', + 2027 => '06-15', + 2028 => '06-04', + 2029 => '05-24', + 2030 => '05-13', + 2031 => '05-02', + 2032 => '04-20', + 2033 => '04-10', + 2034 => '03-30', + 2035 => '03-19', + 2036 => '03-08', + 2037 => '02-25', + ]; + + protected const PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS = [ + 2005 => '04-21', + 2006 => '04-11', + 2007 => '03-31', + 2008 => '03-20', + 2009 => '03-09', + 2010 => '02-26', + 2011 => '02-16', + 2012 => '02-05', + 2013 => '01-24', + 2014 => '01-13', + 2015 => '12-23', + 2016 => '12-12', + 2017 => '12-01', + 2018 => '11-20', + 2019 => '11-09', + 2020 => '10-29', + 2021 => '10-21', + 2022 => '10-08', + 2023 => '09-28', + 2024 => '09-16', + 2025 => '09-06', + 2026 => '08-26', + 2027 => '08-15', + 2028 => '08-04', + 2029 => '07-25', + 2030 => '07-14', + 2031 => '07-03', + 2032 => '06-21', + 2033 => '06-10', + 2034 => '05-31', + 2035 => '05-21', + 2036 => '05-09', + 2037 => '04-29', + ]; + public function countryCode(): string { return 'eg'; } + /** + * @return array + */ protected function allHolidays(int $year): array { + $fixedHolidays = $this->fixedHolidays($year); + $variableHolidays = $this->variableHolidays($year); + return array_merge([ - 'New Year\'s Day' => '01-01', - 'Coptic Christmas' => '01-07', - 'Revolution Day January 25' => '01-25', - 'March Equinox' => '03-20', - 'Sinai Liberation' => '04-25', - 'Labor' => '05-01', - 'Coptic Good' => '05-03', - 'Coptic Holy' => '05-04', - 'Coptic Easter' => '05-05', - 'Spring Festival' => '05-06', - 'June Solstice' => '06-20', - 'June 30 Revolution' => '06-30', - 'Day off for June 30 Revolution' => '07-04', - 'Revolution Day July 23' => '07-23', - 'Day off for Revolution Day July 23' => '07-25', - 'Flooding of the Nile' => '08-15', - 'Nayrouz' => '09-11', - 'September Equinox' => '09-22', - 'Armed Forces' => '10-06', - 'Day off for Armed Forces' => '10-10', - 'December Solstice' => '12-21', - ], $this->variableHolidays($year)); + // These are fixed, but seasonal holidays that aren't observed in Egypt + 'New Year\'s Day' => CarbonImmutable::create($year, 1, 1), + 'Flooding of the Nile' => CarbonImmutable::create($year, 8, 15), + 'March Equinox' => CarbonImmutable::create($year, 3, 20), + 'June Solstice' => CarbonImmutable::create($year, 6, 21), + 'September Equinox' => CarbonImmutable::create($year, 9, 22), + 'Nayrouz' => CarbonImmutable::create($year, 9, 11), + 'December Solstice' => CarbonImmutable::create($year, 12, 21), + ], $fixedHolidays, $variableHolidays); } - /** @return array */ + /** + * @return array + */ protected function variableHolidays(int $year): array { - // The variable holidays all follow the lunar calendar, so their dates are not confirmed. - return []; + $orthodoxEaster = $this->orthodoxEaster($year); + + $eidAlFitrDates = $this->getIslamicHolidayDatesForYear(self::EID_AL_FITR_HOLIDAYS, $year, 'Eid al-Fitr', 3); + $eidAlAdhaDates = $this->getIslamicHolidayDatesForYear(self::EID_AL_ADHA_HOLIDAYS, $year, 'Eid al-Adha', 4); + $arafatDayDates = $this->getIslamicHolidayDatesForYear(self::ARAFAT_DAY_HOLIDAYS, $year, 'Arafat Day'); + $islamicNewYearDates = $this->getIslamicHolidayDatesForYear(self::ISLAMIC_NEW_YEAR_HOLIDAYS, $year, 'Islamic New Year'); + $ashuraDates = $this->getIslamicHolidayDatesForYear(self::ASHURA_HOLIDAYS, $year, 'Ashura'); + $prophetMuhammadBirthdayDates = $this->getIslamicHolidayDatesForYear(self::PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS, $year, 'Birthday of the Prophet Muhammad'); + + return array_merge([ + 'Coptic Good Friday' => $orthodoxEaster->subDays(2)->toImmutable(), + 'Coptic Holy Saturday' => $orthodoxEaster->subDays()->toImmutable(), + 'Coptic Easter Sunday' => $orthodoxEaster->toImmutable(), + ], $eidAlFitrDates, $eidAlAdhaDates, $arafatDayDates, $islamicNewYearDates, $ashuraDates, $prophetMuhammadBirthdayDates); + } + + /** + * Prepare holiday dates for the given year. + * + * @param array $holidayDates Array mapping years to dates. + * @param int $year The year for which to prepare holiday dates. + * @param string $holidayName The name of the holiday. + * @param int $duration The duration of the holiday in days. + * @return array An array of holiday dates. + */ + private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array + { + $dates = []; + + /** + * No reliable sources exist for Islamic holidays observed in Egypt prior to 2005. + * So we'll only calculate holidays from 2005 onwards. + * + * @see https://www.timeanddate.com/holidays/egypt + */ + if (isset($holidayDates[$year])) { + $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); + + if (! $startDay instanceof CarbonImmutable) { + throw new RuntimeException('Date could not be created.'); + } + + if ($duration === 1) { + // For single-day holidays, use the holiday name without "Day" + $dates[$holidayName] = $startDay; + } else { + // For multi-day holidays, append "Day N" for the second day onwards + for ($i = 0; $i < $duration; $i++) { + $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); + $dates[$dayLabel] = $startDay->addDays($i); + } + } + } + + return $dates; + } + + /** + * @return array + */ + private function fixedHolidays(int $year): array + { + $holidays = [ + 'Coptic Christmas Day' => CarbonImmutable::create($year, 1, 7), + 'Revolution Day 2011' => CarbonImmutable::create($year, 1, 25), + 'Sinai Liberation Day' => CarbonImmutable::create($year, 4, 25), + 'Labour Day' => CarbonImmutable::create($year, 5, 1), + 'June 30 Revolution Day' => CarbonImmutable::create($year, 6, 30), + 'Revolution Day' => CarbonImmutable::create($year, 7, 23), + 'Armed Forces Day' => CarbonImmutable::create($year, 10, 6), + 'Spring Festival' => $this->orthodoxEaster($year)->addDay()->toImmutable(), + ]; + + foreach ($holidays as $name => $date) { + $holidays = array_merge($holidays, $this->adjustForWeekend($name, $date)); + } + + return $holidays; + } + + /** + * @return array + */ + private function adjustForWeekend(string $name, CarbonImmutable|false $date): array + { + $adjustedHolidays = []; + + if (! $date instanceof CarbonImmutable) { + return []; + } + + // Explicitly define this logic to avoid timezone confusion on the CarbonInterface::next() method + if ($date->isFriday() || $date->isSaturday()) { + // If the holiday falls on a weekend (Friday or Saturday), it is observed on the following Sunday + $adjustedHolidays['Day off for '.$name] = $date->next(CarbonInterface::SUNDAY); + } elseif ($date->isSunday() || $date->isThursday()) { + // If the holiday falls on a Sunday or Thursday, it is observed on the same day + $adjustedHolidays[$name] = $date; + } else { + // If the holiday falls on a weekday (Monday, Tuesday, Wednesday), it is observed on the following Thursday + $adjustedHolidays['Day off for '.$name] = $date->next(CarbonInterface::THURSDAY); + } + + return $adjustedHolidays; } } diff --git a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap deleted file mode 100644 index 97a3a8144..000000000 --- a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap +++ /dev/null @@ -1,86 +0,0 @@ -[ - { - "name": "New Year's Day", - "date": "2024-01-01" - }, - { - "name": "Coptic Christmas", - "date": "2024-01-07" - }, - { - "name": "Revolution Day January 25", - "date": "2024-01-25" - }, - { - "name": "March Equinox", - "date": "2024-03-20" - }, - { - "name": "Sinai Liberation", - "date": "2024-04-25" - }, - { - "name": "Labor", - "date": "2024-05-01" - }, - { - "name": "Coptic Good", - "date": "2024-05-03" - }, - { - "name": "Coptic Holy", - "date": "2024-05-04" - }, - { - "name": "Coptic Easter", - "date": "2024-05-05" - }, - { - "name": "Spring Festival", - "date": "2024-05-06" - }, - { - "name": "June Solstice", - "date": "2024-06-20" - }, - { - "name": "June 30 Revolution", - "date": "2024-06-30" - }, - { - "name": "Day off for June 30 Revolution", - "date": "2024-07-04" - }, - { - "name": "Revolution Day July 23", - "date": "2024-07-23" - }, - { - "name": "Day off for Revolution Day July 23", - "date": "2024-07-25" - }, - { - "name": "Flooding of the Nile", - "date": "2024-08-15" - }, - { - "name": "Nayrouz", - "date": "2024-09-11" - }, - { - "name": "September Equinox", - "date": "2024-09-22" - }, - { - "name": "Armed Forces", - "date": "2024-10-06" - }, - { - "name": "Day off for Armed Forces", - "date": "2024-10-10" - }, - { - "name": "December Solstice", - "date": "2024-12-21" - } -] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap new file mode 100644 index 000000000..2bd487894 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap @@ -0,0 +1,130 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Coptic Christmas Day", + "date": "2024-01-07" + }, + { + "name": "Revolution Day 2011", + "date": "2024-01-25" + }, + { + "name": "March Equinox", + "date": "2024-03-20" + }, + { + "name": "Eid al-Fitr", + "date": "2024-04-10" + }, + { + "name": "Eid al-Fitr Day 2", + "date": "2024-04-11" + }, + { + "name": "Eid al-Fitr Day 3", + "date": "2024-04-12" + }, + { + "name": "Sinai Liberation Day", + "date": "2024-04-25" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Day off for Labour Day", + "date": "2024-05-02" + }, + { + "name": "Coptic Good Friday", + "date": "2024-05-03" + }, + { + "name": "Coptic Holy Saturday", + "date": "2024-05-04" + }, + { + "name": "Coptic Easter Sunday", + "date": "2024-05-05" + }, + { + "name": "Spring Festival", + "date": "2024-05-06" + }, + { + "name": "Day off for Spring Festival", + "date": "2024-05-09" + }, + { + "name": "Arafat Day", + "date": "2024-06-16" + }, + { + "name": "Eid al-Adha", + "date": "2024-06-17" + }, + { + "name": "Eid al-Adha Day 2", + "date": "2024-06-18" + }, + { + "name": "Eid al-Adha Day 3", + "date": "2024-06-19" + }, + { + "name": "Eid al-Adha Day 4", + "date": "2024-06-20" + }, + { + "name": "June Solstice", + "date": "2024-06-21" + }, + { + "name": "June 30 Revolution Day", + "date": "2024-06-30" + }, + { + "name": "Islamic New Year", + "date": "2024-07-08" + }, + { + "name": "Ashura", + "date": "2024-07-17" + }, + { + "name": "Revolution Day", + "date": "2024-07-23" + }, + { + "name": "Day off for Revolution Day", + "date": "2024-07-25" + }, + { + "name": "Flooding of the Nile", + "date": "2024-08-15" + }, + { + "name": "Nayrouz", + "date": "2024-09-11" + }, + { + "name": "Birthday of the Prophet Muhammad", + "date": "2024-09-16" + }, + { + "name": "September Equinox", + "date": "2024-09-22" + }, + { + "name": "Armed Forces Day", + "date": "2024-10-06" + }, + { + "name": "December Solstice", + "date": "2024-12-21" + } +] \ No newline at end of file diff --git a/tests/Countries/EgyptTest.php b/tests/Countries/EgyptTest.php index 24f5d9ea5..842b8b4ef 100644 --- a/tests/Countries/EgyptTest.php +++ b/tests/Countries/EgyptTest.php @@ -5,13 +5,14 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate egypt holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); +it('can calculate egyptian holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Africa/Cairo'); $holidays = Holidays::for(country: 'eg')->get(); expect($holidays) ->toBeArray() - ->not()->toBeEmpty() - ->and(formatDates($holidays))->toMatchSnapshot(); + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); }); From 3e9ccced56772666ec93cc460a4285f73a0d5b02 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:59:53 +0100 Subject: [PATCH 12/50] fixes for Egypt --- src/Countries/Country.php | 4 +- src/Countries/Egypt.php | 78 ++++++++++++------------- src/Exceptions/InvalidYear.php | 8 +-- tests/Countries/AlbaniaTest.php | 2 +- tests/Countries/AngolaTest.php | 2 +- tests/Countries/ChileTest.php | 2 +- tests/Countries/EgyptTest.php | 9 ++- tests/Countries/EnglandTest.php | 12 ++-- tests/Countries/GhanaTest.php | 6 +- tests/Countries/JamaicaTest.php | 2 +- tests/Countries/KenyaTest.php | 2 +- tests/Countries/MoldovaTest.php | 2 +- tests/Countries/MontenegroTest.php | 2 +- tests/Countries/NigeriaTest.php | 2 +- tests/Countries/NorthernIrelandTest.php | 14 ++--- tests/Countries/ScotlandTest.php | 14 ++--- tests/Countries/SloveniaTest.php | 2 +- tests/Countries/SwitzerlandTest.php | 4 +- tests/Countries/TaiwanTest.php | 2 +- tests/Countries/TanzaniaTest.php | 2 +- tests/Countries/WalesTest.php | 12 ++-- 21 files changed, 93 insertions(+), 90 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 538b89675..fa0352908 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -109,11 +109,11 @@ protected function ensureYearCanBeCalculated(int $year): void * https://www.php.net/manual/en/function.easter-date.php */ if ($year < 1970) { - throw InvalidYear::yearTooLow(); + throw InvalidYear::yearTooLow(1970); } if ($year > 2037) { - throw InvalidYear::yearTooHigh(); + throw InvalidYear::yearTooHigh(2038); } } } diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index 52ec78672..b220aca86 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -5,6 +5,7 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; use RuntimeException; +use Spatie\Holidays\Exceptions\InvalidYear; class Egypt extends Country { @@ -229,28 +230,24 @@ public function countryCode(): string return 'eg'; } - /** - * @return array - */ protected function allHolidays(int $year): array { $fixedHolidays = $this->fixedHolidays($year); $variableHolidays = $this->variableHolidays($year); return array_merge([ - // These are fixed, but seasonal holidays that aren't observed in Egypt - 'New Year\'s Day' => CarbonImmutable::create($year, 1, 1), - 'Flooding of the Nile' => CarbonImmutable::create($year, 8, 15), - 'March Equinox' => CarbonImmutable::create($year, 3, 20), - 'June Solstice' => CarbonImmutable::create($year, 6, 21), - 'September Equinox' => CarbonImmutable::create($year, 9, 22), - 'Nayrouz' => CarbonImmutable::create($year, 9, 11), - 'December Solstice' => CarbonImmutable::create($year, 12, 21), + 'New Year\'s Day' => '1-1', + 'Flooding of the Nile' => '8-15', + 'March Equinox' => '3-20', + 'June Solstice' => '6-21', + 'Nayrouz' => '9-11', + 'September Equinox' => '9-22', + 'December Solstice' => '12-21', ], $fixedHolidays, $variableHolidays); } /** - * @return array + * @return array */ protected function variableHolidays(int $year): array { @@ -277,7 +274,7 @@ protected function variableHolidays(int $year): array * @param int $year The year for which to prepare holiday dates. * @param string $holidayName The name of the holiday. * @param int $duration The duration of the holiday in days. - * @return array An array of holiday dates. + * @return array An array of holiday dates. */ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array { @@ -289,22 +286,25 @@ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, s * * @see https://www.timeanddate.com/holidays/egypt */ - if (isset($holidayDates[$year])) { - $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); - if (! $startDay instanceof CarbonImmutable) { - throw new RuntimeException('Date could not be created.'); - } + if ($year < 2005) { + throw InvalidYear::yearTooLow(2005); + } + + if (! isset($holidayDates[$year])) { + return $dates; + } + + $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); - if ($duration === 1) { - // For single-day holidays, use the holiday name without "Day" - $dates[$holidayName] = $startDay; - } else { - // For multi-day holidays, append "Day N" for the second day onwards - for ($i = 0; $i < $duration; $i++) { - $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); - $dates[$dayLabel] = $startDay->addDays($i); - } + if ($duration === 1) { + // For single-day holidays, use the holiday name without "Day" + $dates[$holidayName] = $startDay; + } else { + // For multi-day holidays, append "Day N" for the second day onwards + for ($i = 0; $i < $duration; $i++) { + $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); + $dates[$dayLabel] = $startDay->addDays($i); } } @@ -312,18 +312,18 @@ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, s } /** - * @return array + * @return array */ private function fixedHolidays(int $year): array { $holidays = [ - 'Coptic Christmas Day' => CarbonImmutable::create($year, 1, 7), - 'Revolution Day 2011' => CarbonImmutable::create($year, 1, 25), - 'Sinai Liberation Day' => CarbonImmutable::create($year, 4, 25), - 'Labour Day' => CarbonImmutable::create($year, 5, 1), - 'June 30 Revolution Day' => CarbonImmutable::create($year, 6, 30), - 'Revolution Day' => CarbonImmutable::create($year, 7, 23), - 'Armed Forces Day' => CarbonImmutable::create($year, 10, 6), + 'Coptic Christmas Day' => CarbonImmutable::createFromDate($year, 1, 7), + 'Revolution Day 2011' => CarbonImmutable::createFromDate($year, 1, 25), + 'Sinai Liberation Day' => CarbonImmutable::createFromDate($year, 4, 25), + 'Labour Day' => CarbonImmutable::createFromDate($year, 5, 1), + 'June 30 Revolution Day' => CarbonImmutable::createFromDate($year, 6, 30), + 'Revolution Day' => CarbonImmutable::createFromDate($year, 7, 23), + 'Armed Forces Day' => CarbonImmutable::createFromDate($year, 10, 6), 'Spring Festival' => $this->orthodoxEaster($year)->addDay()->toImmutable(), ]; @@ -335,16 +335,12 @@ private function fixedHolidays(int $year): array } /** - * @return array + * @return array */ - private function adjustForWeekend(string $name, CarbonImmutable|false $date): array + private function adjustForWeekend(string $name, CarbonImmutable $date): array { $adjustedHolidays = []; - if (! $date instanceof CarbonImmutable) { - return []; - } - // Explicitly define this logic to avoid timezone confusion on the CarbonInterface::next() method if ($date->isFriday() || $date->isSaturday()) { // If the holiday falls on a weekend (Friday or Saturday), it is observed on the following Sunday diff --git a/src/Exceptions/InvalidYear.php b/src/Exceptions/InvalidYear.php index 0eac2b9e1..13fd335ad 100644 --- a/src/Exceptions/InvalidYear.php +++ b/src/Exceptions/InvalidYear.php @@ -6,14 +6,14 @@ class InvalidYear extends RuntimeException { - public static function yearTooLow(): self + public static function yearTooLow(int $year): self { - return new self('Holidays can only be calculated for years after 1970.'); + return new self("Holidays can only be calculated for years after {$year}."); } - public static function yearTooHigh(): self + public static function yearTooHigh(int $year): self { - return new self('Holidays can only be calculated for years before 2038.'); + return new self("Holidays can only be calculated for years before {$year}."); } public static function range(string $country, int $start, int $end): self diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php index 1bfb5ba1b..6099e1a77 100644 --- a/tests/Countries/AlbaniaTest.php +++ b/tests/Countries/AlbaniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate albanian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'al')->get(); expect($holidays) diff --git a/tests/Countries/AngolaTest.php b/tests/Countries/AngolaTest.php index ae0e07518..6021f721d 100644 --- a/tests/Countries/AngolaTest.php +++ b/tests/Countries/AngolaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate angola holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ao')->get(); diff --git a/tests/Countries/ChileTest.php b/tests/Countries/ChileTest.php index aed6f880f..daf50b0e9 100644 --- a/tests/Countries/ChileTest.php +++ b/tests/Countries/ChileTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate chile holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'cl')->get(); diff --git a/tests/Countries/EgyptTest.php b/tests/Countries/EgyptTest.php index 842b8b4ef..6579f79c5 100644 --- a/tests/Countries/EgyptTest.php +++ b/tests/Countries/EgyptTest.php @@ -3,10 +3,11 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Holidays; it('can calculate egyptian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Africa/Cairo'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'eg')->get(); @@ -16,3 +17,9 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('cannot calculate egyptian holidays before 2005', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + Holidays::for(country: 'eg', year: 2004)->get(); +})->throws(InvalidYear::class); diff --git a/tests/Countries/EnglandTest.php b/tests/Countries/EnglandTest.php index ee3d22e80..0746c50a3 100644 --- a/tests/Countries/EnglandTest.php +++ b/tests/Countries/EnglandTest.php @@ -40,7 +40,7 @@ ]); it('can calculate welsh holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -50,7 +50,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -59,7 +59,7 @@ }); it('can calculate welsh holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -68,7 +68,7 @@ }); it('can calculate welsh holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -77,7 +77,7 @@ }); it('can calculate welsh holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -86,7 +86,7 @@ }); it('can calculate holidays for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); diff --git a/tests/Countries/GhanaTest.php b/tests/Countries/GhanaTest.php index 3a02ed9d3..f8186e756 100644 --- a/tests/Countries/GhanaTest.php +++ b/tests/Countries/GhanaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate Ghana holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gh')->get(); @@ -18,7 +18,7 @@ }); it('can calculate Ghana easter based region holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gh')->get(); @@ -30,7 +30,7 @@ }); it('can calculate Ghana date based regional holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gh')->get(); diff --git a/tests/Countries/JamaicaTest.php b/tests/Countries/JamaicaTest.php index 1ea7b0237..5b06881f5 100644 --- a/tests/Countries/JamaicaTest.php +++ b/tests/Countries/JamaicaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate jamaican holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'jm')->get(); diff --git a/tests/Countries/KenyaTest.php b/tests/Countries/KenyaTest.php index 96d17cdf3..c5aef294d 100644 --- a/tests/Countries/KenyaTest.php +++ b/tests/Countries/KenyaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate kenyan holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ke')->get(); diff --git a/tests/Countries/MoldovaTest.php b/tests/Countries/MoldovaTest.php index 02ac0db64..86fafa45e 100644 --- a/tests/Countries/MoldovaTest.php +++ b/tests/Countries/MoldovaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate moldavian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'md')->get(); diff --git a/tests/Countries/MontenegroTest.php b/tests/Countries/MontenegroTest.php index 9f5078b93..e5450ba3f 100644 --- a/tests/Countries/MontenegroTest.php +++ b/tests/Countries/MontenegroTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate montenegro holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'me')->get(); diff --git a/tests/Countries/NigeriaTest.php b/tests/Countries/NigeriaTest.php index 8fdb2a32a..d0559a305 100644 --- a/tests/Countries/NigeriaTest.php +++ b/tests/Countries/NigeriaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate nigerian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ng')->get(); diff --git a/tests/Countries/NorthernIrelandTest.php b/tests/Countries/NorthernIrelandTest.php index 11266d3af..1f5dc237c 100644 --- a/tests/Countries/NorthernIrelandTest.php +++ b/tests/Countries/NorthernIrelandTest.php @@ -47,7 +47,7 @@ ]); it('can calculate northern irish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + CarbonImmutable::setTestNow('2025-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -57,7 +57,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -66,7 +66,7 @@ }); it('returns a substitute day for second of january if new years day falls on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -75,7 +75,7 @@ }); it('can calculate northern irish holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -84,7 +84,7 @@ }); it('can calculate northern irish holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -93,7 +93,7 @@ }); it('can calculate northern irish holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -102,7 +102,7 @@ }); it('can calculate northern irish for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); diff --git a/tests/Countries/ScotlandTest.php b/tests/Countries/ScotlandTest.php index f8aa5d926..dc2d9aaad 100644 --- a/tests/Countries/ScotlandTest.php +++ b/tests/Countries/ScotlandTest.php @@ -43,7 +43,7 @@ ]); it('can calculate scottish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + CarbonImmutable::setTestNow('2025-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -53,7 +53,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -62,7 +62,7 @@ }); it('returns a substitute day for second of january if new years day falls on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -71,7 +71,7 @@ }); it('can calculate scottish holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -80,7 +80,7 @@ }); it('can calculate scottish holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -89,7 +89,7 @@ }); it('can calculate scottish holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -98,7 +98,7 @@ }); it('can calculate holidays for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); diff --git a/tests/Countries/SloveniaTest.php b/tests/Countries/SloveniaTest.php index 0dc846a6e..da8a6e011 100644 --- a/tests/Countries/SloveniaTest.php +++ b/tests/Countries/SloveniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate slovenian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'si')->get(); diff --git a/tests/Countries/SwitzerlandTest.php b/tests/Countries/SwitzerlandTest.php index 0e4a97f41..386019210 100644 --- a/tests/Countries/SwitzerlandTest.php +++ b/tests/Countries/SwitzerlandTest.php @@ -8,7 +8,7 @@ use Spatie\Holidays\Holidays; it('can calculate swiss holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ch')->get(); @@ -20,7 +20,7 @@ }); it('can get swiss holidays for a specified region (zh)', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $switzerland = new Switzerland(region: 'ch-zh'); diff --git a/tests/Countries/TaiwanTest.php b/tests/Countries/TaiwanTest.php index 75c7b6906..9aa6578bc 100644 --- a/tests/Countries/TaiwanTest.php +++ b/tests/Countries/TaiwanTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate taiwan holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'tw')->get(); diff --git a/tests/Countries/TanzaniaTest.php b/tests/Countries/TanzaniaTest.php index 69777866b..38f15ec39 100644 --- a/tests/Countries/TanzaniaTest.php +++ b/tests/Countries/TanzaniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate tanzania holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'tz')->get(); diff --git a/tests/Countries/WalesTest.php b/tests/Countries/WalesTest.php index 2e840357b..01d65370e 100644 --- a/tests/Countries/WalesTest.php +++ b/tests/Countries/WalesTest.php @@ -58,7 +58,7 @@ ]); it('can calculate welsh holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -68,7 +68,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -77,7 +77,7 @@ }); it('can calculate welsh holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -86,7 +86,7 @@ }); it('can calculate welsh holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -95,7 +95,7 @@ }); it('can calculate welsh holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -104,7 +104,7 @@ }); it('can calculate holidays for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); From 3be86627ac9f9772a1decc3568a56dbd1899f0e6 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 11:00:24 +0000 Subject: [PATCH 13/50] Fix styling --- src/Countries/Egypt.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index b220aca86..464759c26 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; -use RuntimeException; use Spatie\Holidays\Exceptions\InvalidYear; class Egypt extends Country @@ -286,7 +285,6 @@ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, s * * @see https://www.timeanddate.com/holidays/egypt */ - if ($year < 2005) { throw InvalidYear::yearTooLow(2005); } From 7a335da7507ed0abb0996b9457fdb71dd7756ef3 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 11:01:32 +0000 Subject: [PATCH 14/50] Update CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3490335e6..fc14bbaa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to `holidays` will be documented in this file. +## 1.6.1 - 2024-02-07 + +### What's Changed + +* Fixes for Egyptian holidays by @wessama in https://github.com/spatie/holidays/pull/155 + +### New Contributors + +* @wessama made their first contribution in https://github.com/spatie/holidays/pull/155 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.6.0...1.6.1 + ## 1.6.0 - 2024-02-07 ### What's Changed From 5223465c49ee7339cbd97b16c6a33169938cff41 Mon Sep 17 00:00:00 2001 From: Shokhrukh Shomakhmudov Date: Thu, 8 Feb 2024 14:38:18 +0500 Subject: [PATCH 15/50] Add Uzbekistan Holidays (#81) * Add Uzbekistan Holidays * phpstan error fix * feat: add locale & update islamic holidays * tests updated and verified * tests updated and verified --- lang/uzbekistan/en/holidays.json | 13 ++ lang/uzbekistan/ru/holidays.json | 13 ++ src/Countries/Uzbekistan.php | 165 ++++++++++++++++++ ...olidays_with_data_set___2000____2000_.snap | 42 +++++ ...olidays_with_data_set___2006____2006_.snap | 42 +++++ ...olidays_with_data_set___2022____2022_.snap | 38 ++++ ...olidays_with_data_set___2023____2023_.snap | 38 ++++ tests/Countries/UzbekistanTest.php | 18 ++ 8 files changed, 369 insertions(+) create mode 100644 lang/uzbekistan/en/holidays.json create mode 100644 lang/uzbekistan/ru/holidays.json create mode 100644 src/Countries/Uzbekistan.php create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap create mode 100644 tests/Countries/UzbekistanTest.php diff --git a/lang/uzbekistan/en/holidays.json b/lang/uzbekistan/en/holidays.json new file mode 100644 index 000000000..63db8bac2 --- /dev/null +++ b/lang/uzbekistan/en/holidays.json @@ -0,0 +1,13 @@ +{ + "Yangi yil": "New year", + "Xalqaro xotin-qizlar kuni": "International Women's Day", + "Navro'z": "Nowruz", + "Xotira va qadrlash kuni": "Remembrance Day", + "Mustaqillik kuni": "Independence Day", + "Ustoz va murabbiylar kuni": "Teachers Day", + "Konstitutsiya kuni": "Constitution Day", + "Ramazon Hayiti": "Eid al-Fitr", + "Qurbon Hayiti": "Eid al-Adha", + "Ramazon Hayiti 2": "Eid al-Fitr", + "Qurbon Hayiti 2": "Eid al-Adha" +} \ No newline at end of file diff --git a/lang/uzbekistan/ru/holidays.json b/lang/uzbekistan/ru/holidays.json new file mode 100644 index 000000000..8dea77311 --- /dev/null +++ b/lang/uzbekistan/ru/holidays.json @@ -0,0 +1,13 @@ +{ + "Yangi yil": "Новый год", + "Xalqaro xotin-qizlar kuni": "Международный женский день", + "Navro'z": "Навруз", + "Xotira va qadrlash kuni": "День памяти и почестей", + "Mustaqillik kuni": "День Независимости", + "Ustoz va murabbiylar kuni": "День учителя", + "Konstitutsiya kuni": "День Конституции", + "Ramazon Hayiti": "Рамазан Хаит", + "Qurbon Hayiti": "Курбан Хаит", + "Ramazon Hayiti 2": "Рамазан Хаит", + "Qurbon Hayiti 2": "Курбан Хаит" +} \ No newline at end of file diff --git a/src/Countries/Uzbekistan.php b/src/Countries/Uzbekistan.php new file mode 100644 index 000000000..ffb371916 --- /dev/null +++ b/src/Countries/Uzbekistan.php @@ -0,0 +1,165 @@ + '04-16', + 1992 => '04-04', + 1993 => '03-25', + 1994 => '03-14', + 1995 => '03-03', + 1996 => '02-21', + 1997 => '02-09', + 1998 => '01-30', + 1999 => '01-19', + 2000 => [ + '01-08', + '12-28', + ], + 2001 => '12-17', + 2002 => '12-06', + 2003 => '11-26', + 2004 => '11-14', + 2005 => '11-04', + 2006 => '10-24', + 2007 => '10-13', + 2008 => '10-02', + 2009 => '09-21', + 2010 => '09-10', + 2011 => '08-31', + 2012 => '08-19', + 2013 => '08-08', + 2014 => '07-29', + 2015 => '07-18', + 2016 => '07-07', + 2017 => '06-26', + 2018 => '06-15', + 2019 => '06-04', + 2020 => '05-24', + 2021 => '05-13', + 2022 => '05-02', + 2023 => '04-21', + 2024 => '04-10', + 2025 => '03-31', + 2026 => '03-20', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-05', + 2031 => '01-25', + 2032 => '01-14', + 2033 => [ + '01-03', + '12-23', + ], + 2034 => '12-12', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-10', + ]; + + public const sacrificeHolidays = [ + 1991 => '06-23', + 1992 => '06-11', + 1993 => '06-01', + 1994 => '05-21', + 1995 => '05-10', + 1996 => '04-29', + 1997 => '04-18', + 1998 => '04-08', + 1999 => '03-28', + 2000 => '03-16', + 2001 => '03-06', + 2002 => '02-23', + 2003 => '02-12', + 2004 => '02-02', + 2005 => '01-21', + 2006 => [ + '01-10', + '12-31', + ], + 2007 => '12-20', + 2008 => '12-09', + 2009 => '11-28', + 2010 => '11-17', + 2011 => '11-07', + 2012 => '10-26', + 2013 => '10-15', + 2014 => '10-05', + 2015 => '09-24', + 2016 => '09-13', + 2017 => '09-02', + 2018 => '08-22', + 2019 => '08-11', + 2020 => '07-31', + 2021 => '07-20', + 2022 => '07-09', + 2023 => '06-28', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-01', + 2035 => '02-18', + 2036 => '02-08', + 2037 => '01-27', + ]; + + public function countryCode(): string + { + return 'uz'; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + //After gaining independence on September 1, 1991, Uzbekistan introduced a new set of public holidays. + if ($year < 1991) { + return []; + } + + return array_merge([ + 'Yangi yil' => '01-01', + 'Xalqaro xotin-qizlar kuni' => '03-08', + 'Navro\'z' => '03-21', + 'Xotira va qadrlash kuni' => '05-09', + 'Mustaqillik kuni' => '09-01', + 'Ustoz va murabbiylar kuni' => '10-01', + 'Konstitutsiya kuni' => '12-08', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $holidays = []; + + if (isset(self::ramadanHolidays[$year])) { + foreach ((array) self::ramadanHolidays[$year] as $key => $holiday) { + $prefix = $key == 0 ? '' : ' '.($key + 1); + $holidays['Ramazon Hayiti'.$prefix] = $holiday; + } + } + if (isset(self::sacrificeHolidays[$year])) { + foreach ((array) self::sacrificeHolidays[$year] as $key => $holiday) { + $prefix = $key == 0 ? '' : ' '.($key + 1); + $holidays['Qurbon Hayiti'.$prefix] = $holiday; + } + } + + return $holidays; + } +} diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap new file mode 100644 index 000000000..46826c3aa --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Yangi yil", + "date": "2000-01-01" + }, + { + "name": "Ramazon Hayiti", + "date": "2000-01-08" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2000-03-08" + }, + { + "name": "Qurbon Hayiti", + "date": "2000-03-16" + }, + { + "name": "Navro'z", + "date": "2000-03-21" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2000-05-09" + }, + { + "name": "Mustaqillik kuni", + "date": "2000-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2000-10-01" + }, + { + "name": "Konstitutsiya kuni", + "date": "2000-12-08" + }, + { + "name": "Ramazon Hayiti 2", + "date": "2000-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap new file mode 100644 index 000000000..4717ce431 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Yangi yil", + "date": "2006-01-01" + }, + { + "name": "Qurbon Hayiti", + "date": "2006-01-10" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2006-03-08" + }, + { + "name": "Navro'z", + "date": "2006-03-21" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2006-05-09" + }, + { + "name": "Mustaqillik kuni", + "date": "2006-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2006-10-01" + }, + { + "name": "Ramazon Hayiti", + "date": "2006-10-24" + }, + { + "name": "Konstitutsiya kuni", + "date": "2006-12-08" + }, + { + "name": "Qurbon Hayiti 2", + "date": "2006-12-31" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap new file mode 100644 index 000000000..34a96f797 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap @@ -0,0 +1,38 @@ +[ + { + "name": "Yangi yil", + "date": "2022-01-01" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2022-03-08" + }, + { + "name": "Navro'z", + "date": "2022-03-21" + }, + { + "name": "Ramazon Hayiti", + "date": "2022-05-02" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2022-05-09" + }, + { + "name": "Qurbon Hayiti", + "date": "2022-07-09" + }, + { + "name": "Mustaqillik kuni", + "date": "2022-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2022-10-01" + }, + { + "name": "Konstitutsiya kuni", + "date": "2022-12-08" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap new file mode 100644 index 000000000..516cc91b4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap @@ -0,0 +1,38 @@ +[ + { + "name": "Yangi yil", + "date": "2023-01-01" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2023-03-08" + }, + { + "name": "Navro'z", + "date": "2023-03-21" + }, + { + "name": "Ramazon Hayiti", + "date": "2023-04-21" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2023-05-09" + }, + { + "name": "Qurbon Hayiti", + "date": "2023-06-28" + }, + { + "name": "Mustaqillik kuni", + "date": "2023-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2023-10-01" + }, + { + "name": "Konstitutsiya kuni", + "date": "2023-12-08" + } +] \ No newline at end of file diff --git a/tests/Countries/UzbekistanTest.php b/tests/Countries/UzbekistanTest.php new file mode 100644 index 000000000..d59e5a1b9 --- /dev/null +++ b/tests/Countries/UzbekistanTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +})->with([2000, 2006, 2022, 2023]); From 0e9712513e624aed6203bb71959f29e8c63dc49f Mon Sep 17 00:00:00 2001 From: Kenan Aghayev <36705821+kenanaga@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:39:08 +0400 Subject: [PATCH 16/50] Add Azerbaijan holidays (#166) * Add Azerbaijan holidays * Added Azerbaijani holidays in English * update setTestNowAndTimezone to setTestNow --- lang/azerbaijan/en/holidays.json | 13 ++++++ src/Countries/Azerbaijan.php | 37 +++++++++++++++ ...it_can_calculate_azerbaijani_holidays.snap | 46 +++++++++++++++++++ ...ulate_azerbaijani_holidays_in_english.snap | 46 +++++++++++++++++++ tests/Countries/AzerbaijanTest.php | 30 ++++++++++++ 5 files changed, 172 insertions(+) create mode 100644 lang/azerbaijan/en/holidays.json create mode 100644 src/Countries/Azerbaijan.php create mode 100644 tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap create mode 100644 tests/Countries/AzerbaijanTest.php diff --git a/lang/azerbaijan/en/holidays.json b/lang/azerbaijan/en/holidays.json new file mode 100644 index 000000000..2fc0b49c3 --- /dev/null +++ b/lang/azerbaijan/en/holidays.json @@ -0,0 +1,13 @@ +{ + "Yeni il": "New year", + "Beynəlxalq Qadınlar günü": "International Women's Day", + "Novruz bayramı": "Novruz holiday", + "Faşizm üzərində qələbə günü": "Day of Victory over fascism", + "Müstəqillik Günü": "Independence Day", + "Azərbaycan xalqının milli qurtuluş günü": "National Salvation Day of the Azerbaijani people", + "Azərbaycan Respublikasının Silahlı Qüvvələri günü": "Day of Armed Forces of the Republic of Azerbaijan", + "Müstəqilliyin bərpası günü": "Day of Restoration of Independence", + "Zəfər Günü": "Victory Day", + "Azərbaycan Respublikasının Dövlət bayrağı günü": "National Flag Day of the Republic of Azerbaijan", + "Dünya azərbaycanlılarının həmrəyliyi günü": "World Azerbaijanis Solidarity Day" +} diff --git a/src/Countries/Azerbaijan.php b/src/Countries/Azerbaijan.php new file mode 100644 index 000000000..b92cd3b12 --- /dev/null +++ b/src/Countries/Azerbaijan.php @@ -0,0 +1,37 @@ + '01-01', + 'Beynəlxalq Qadınlar günü' => '03-08', + 'Novruz bayramı' => '03-20', + 'Faşizm üzərində qələbə günü' => '05-09', + 'Müstəqillik Günü' => '05-28', + 'Azərbaycan xalqının milli qurtuluş günü' => '06-15', + 'Azərbaycan Respublikasının Silahlı Qüvvələri günü' => '06-26', + 'Müstəqilliyin bərpası günü' => '10-18', + 'Zəfər Günü' => '11-08', + 'Azərbaycan Respublikasının Dövlət bayrağı günü' => '11-09', + 'Dünya azərbaycanlılarının həmrəyliyi günü' => '12-31', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + // does not change according to the standard + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap new file mode 100644 index 000000000..cb0489f97 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Yeni il", + "date": "2024-01-01" + }, + { + "name": "Beyn\u0259lxalq Qad\u0131nlar g\u00fcn\u00fc", + "date": "2024-03-08" + }, + { + "name": "Novruz bayram\u0131", + "date": "2024-03-20" + }, + { + "name": "Fa\u015fizm \u00fcz\u0259rind\u0259 q\u0259l\u0259b\u0259 g\u00fcn\u00fc", + "date": "2024-05-09" + }, + { + "name": "M\u00fcst\u0259qillik G\u00fcn\u00fc", + "date": "2024-05-28" + }, + { + "name": "Az\u0259rbaycan xalq\u0131n\u0131n milli qurtulu\u015f g\u00fcn\u00fc", + "date": "2024-06-15" + }, + { + "name": "Az\u0259rbaycan Respublikas\u0131n\u0131n Silahl\u0131 Q\u00fcvv\u0259l\u0259ri g\u00fcn\u00fc", + "date": "2024-06-26" + }, + { + "name": "M\u00fcst\u0259qilliyin b\u0259rpas\u0131 g\u00fcn\u00fc", + "date": "2024-10-18" + }, + { + "name": "Z\u0259f\u0259r G\u00fcn\u00fc", + "date": "2024-11-08" + }, + { + "name": "Az\u0259rbaycan Respublikas\u0131n\u0131n D\u00f6vl\u0259t bayra\u011f\u0131 g\u00fcn\u00fc", + "date": "2024-11-09" + }, + { + "name": "D\u00fcnya az\u0259rbaycanl\u0131lar\u0131n\u0131n h\u0259mr\u0259yliyi g\u00fcn\u00fc", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap new file mode 100644 index 000000000..e1ef8359c --- /dev/null +++ b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New year", + "date": "2024-01-01" + }, + { + "name": "International Women's Day", + "date": "2024-03-08" + }, + { + "name": "Novruz holiday", + "date": "2024-03-20" + }, + { + "name": "Day of Victory over fascism", + "date": "2024-05-09" + }, + { + "name": "Independence Day", + "date": "2024-05-28" + }, + { + "name": "National Salvation Day of the Azerbaijani people", + "date": "2024-06-15" + }, + { + "name": "Day of Armed Forces of the Republic of Azerbaijan", + "date": "2024-06-26" + }, + { + "name": "Day of Restoration of Independence", + "date": "2024-10-18" + }, + { + "name": "Victory Day", + "date": "2024-11-08" + }, + { + "name": "National Flag Day of the Republic of Azerbaijan", + "date": "2024-11-09" + }, + { + "name": "World Azerbaijanis Solidarity Day", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/Countries/AzerbaijanTest.php b/tests/Countries/AzerbaijanTest.php new file mode 100644 index 000000000..4de5efa5a --- /dev/null +++ b/tests/Countries/AzerbaijanTest.php @@ -0,0 +1,30 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate azerbaijani holidays in english', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'az',locale: 'en')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From fb625e2321ac72c1af869c962a9a802a1c4e5295 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 09:39:31 +0000 Subject: [PATCH 17/50] Fix styling --- tests/Countries/AzerbaijanTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Countries/AzerbaijanTest.php b/tests/Countries/AzerbaijanTest.php index 4de5efa5a..9aa9180a5 100644 --- a/tests/Countries/AzerbaijanTest.php +++ b/tests/Countries/AzerbaijanTest.php @@ -20,7 +20,7 @@ it('can calculate azerbaijani holidays in english', function () { CarbonImmutable::setTestNow('2024-01-01'); - $holidays = Holidays::for(country: 'az',locale: 'en')->get(); + $holidays = Holidays::for(country: 'az', locale: 'en')->get(); expect($holidays) ->toBeArray() From 0ab3409bbf7648de1d9719ff02bf59417c8529f2 Mon Sep 17 00:00:00 2001 From: Victor Ikpeba Date: Thu, 8 Feb 2024 09:56:10 +0000 Subject: [PATCH 18/50] Enhanced holiday dates in Ghana (#80) * Added holidays for `Ghana` * fix timezone when creating farmers day * Updated holidays that falls within weekend to be observed on the next monday * Fix return types * pr suggestions implemented * removed unwanted timezone in params * removed timezone * Updated test * removed test files * Add back test files * Added return types to methods --- src/Countries/Ghana.php | 91 +++++++++++++++++-- ...te_Ghana_date_based_regional_holidays.snap | 10 +- ...te_Ghana_easter_based_region_holidays.snap | 10 +- .../it_can_calculate_Ghana_holidays.snap | 10 +- 4 files changed, 102 insertions(+), 19 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 03342516c..505677c36 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -11,18 +11,81 @@ public function countryCode(): string return 'gh'; } + /** + * Return carbon date for christmas + * + * @return CarbonImmutable + */ + protected function getChristmasDay(int $year) + { + return new CarbonImmutable($year . '-12-25'); + } + + /** @return CarbonImmutable */ + protected function christmasDay(int $year): CarbonImmutable + { + $christmasDay = $this->getChristmasDay($year); + + if ($christmasDay->isSaturday()) { + + $christmasDay = $christmasDay->next('monday'); + } + + if ($christmasDay->isSunday()) { + $christmasDay = $christmasDay->next('tuesday'); + } + + return $christmasDay; + } + + /** @return CarbonImmutable */ + protected function boxingDay(int $year): CarbonImmutable + { + $christmasDay = $this->getChristmasDay($year); + $boxingDay = new CarbonImmutable($year . '-12-26'); + + if ($christmasDay->isFriday()) { + $boxingDay = $boxingDay->next('monday'); + } + if ($christmasDay->isSaturday()) { + $boxingDay = $boxingDay->next('tuesday'); + } + + return $boxingDay; + } + + /** + * Get holiday + * + * For example: If a holiday falls on a weekend, the new day to be observed is the next monday + * @return CarbonImmutable + */ + protected function getHoliday(int $year, string $monthAndDay): CarbonImmutable + { + $newYearsDay = new CarbonImmutable($year . '-' . $monthAndDay); + + if ($newYearsDay->isWeekend()) { + $newYearsDay = $newYearsDay->next('monday'); + } + + return $newYearsDay; + } + protected function allHolidays(int $year): array { - return array_merge([ - 'New Year\'s Day' => '01-01', - 'Constitution Day' => '01-07', - 'Independence Day' => '03-06', - 'May Day' => '05-01', - 'Founder\'s Day' => '08-04', - 'Kwame Nkrumah Memorial Day' => '09-21', - 'Christmas Day' => '12-25', - 'Boxing Day' => '12-26', - ], $this->variableHolidays($year)); + return array_merge( + [ + 'New Year\'s Day' => $this->getHoliday($year, '01-01'), + 'Constitution Day' => $this->getHoliday($year, '01-07'), + 'Independence Day' => $this->getHoliday($year, '03-06'), + 'May Day' => $this->getHoliday($year, '05-01'), + 'Founder\'s Day' => $this->getHoliday($year, '08-04'), + 'Kwame Nkrumah Memorial Day' => $this->getHoliday($year, '09-21'), + 'Christmas Day' => $this->christmasDay($year), + 'Boxing Day' => $this->boxingDay($year), + ], + $this->variableHolidays($year) + ); } /** @return array */ @@ -30,9 +93,17 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); + $farmersDay = new CarbonImmutable('first friday of December ' . $year); + return [ + 'Farmers Day' => $farmersDay, 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), + + // NB: *** There are no fixed dates for the Eid-Ul-Fitr and Eid-Ul-Adha because they are movable feasts. + // The dates for their observation are provided by the Office of the Chief Imam in the course of the year. + // 'Eid-Ul-Fitr' => "", + // 'Eid-Ul-Adha' => "", ]; } } diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap index 3d29c9e8f..b5d9a6c72 100644 --- a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap index 3d29c9e8f..b5d9a6c72 100644 --- a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap index 3d29c9e8f..b5d9a6c72 100644 --- a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", From a96f91368cc70d72b8f30172ac74de8611c385c2 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 09:56:31 +0000 Subject: [PATCH 19/50] Fix styling --- src/Countries/Ghana.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 505677c36..7d922e88d 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -18,10 +18,9 @@ public function countryCode(): string */ protected function getChristmasDay(int $year) { - return new CarbonImmutable($year . '-12-25'); + return new CarbonImmutable($year.'-12-25'); } - /** @return CarbonImmutable */ protected function christmasDay(int $year): CarbonImmutable { $christmasDay = $this->getChristmasDay($year); @@ -38,11 +37,10 @@ protected function christmasDay(int $year): CarbonImmutable return $christmasDay; } - /** @return CarbonImmutable */ protected function boxingDay(int $year): CarbonImmutable { $christmasDay = $this->getChristmasDay($year); - $boxingDay = new CarbonImmutable($year . '-12-26'); + $boxingDay = new CarbonImmutable($year.'-12-26'); if ($christmasDay->isFriday()) { $boxingDay = $boxingDay->next('monday'); @@ -58,11 +56,10 @@ protected function boxingDay(int $year): CarbonImmutable * Get holiday * * For example: If a holiday falls on a weekend, the new day to be observed is the next monday - * @return CarbonImmutable */ protected function getHoliday(int $year, string $monthAndDay): CarbonImmutable { - $newYearsDay = new CarbonImmutable($year . '-' . $monthAndDay); + $newYearsDay = new CarbonImmutable($year.'-'.$monthAndDay); if ($newYearsDay->isWeekend()) { $newYearsDay = $newYearsDay->next('monday'); @@ -93,7 +90,7 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $farmersDay = new CarbonImmutable('first friday of December ' . $year); + $farmersDay = new CarbonImmutable('first friday of December '.$year); return [ 'Farmers Day' => $farmersDay, From 34f8217c4b8e6055f3931bfb867d2e5c24a31b36 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:57:28 +0100 Subject: [PATCH 20/50] use --compact for tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 46ef42ee3..5937dbf4a 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "scripts": { "analyse": "vendor/bin/phpstan analyse", "baseline": "vendor/bin/phpstan analyse --generate-baseline", - "test": "vendor/bin/pest", + "test": "vendor/bin/pest --compact", "test-coverage": "vendor/bin/pest --coverage", "format": "vendor/bin/pint" }, From 91232cf6bb8961c0316a7a78e40219aceb073c61 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:11:59 +0100 Subject: [PATCH 21/50] code cleanup for Ghana --- src/Countries/Ghana.php | 106 +++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 7d922e88d..1a6f0cab0 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Ghana extends Country { @@ -11,86 +12,81 @@ public function countryCode(): string return 'gh'; } - /** - * Return carbon date for christmas - * - * @return CarbonImmutable - */ - protected function getChristmasDay(int $year) + protected function allHolidays(int $year): array { - return new CarbonImmutable($year.'-12-25'); + return array_merge( + $this->observedHolidays($year), + $this->variableHolidays($year), + ); } - protected function christmasDay(int $year): CarbonImmutable + /** @return array */ + protected function observedHolidays(int $year): array { - $christmasDay = $this->getChristmasDay($year); - - if ($christmasDay->isSaturday()) { - - $christmasDay = $christmasDay->next('monday'); - } + $holidays = [ + 'New Year\'s Day' => '01-01', + 'Constitution Day' => '01-07', + 'Independence Day' => '03-06', + 'May Day' => '05-01', + 'Founder\'s Day' => '08-04', + 'Kwame Nkrumah Memorial Day' => '09-21', + ]; - if ($christmasDay->isSunday()) { - $christmasDay = $christmasDay->next('tuesday'); - } + $holidays = array_map(function ($holiday) use ($year) { + return $this->observed($holiday, $year); + }, $holidays); - return $christmasDay; + return array_merge($holidays, [ + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + ]); } - protected function boxingDay(int $year): CarbonImmutable + protected function observed(string $date, int $year): CarbonInterface { - $christmasDay = $this->getChristmasDay($year); - $boxingDay = new CarbonImmutable($year.'-12-26'); + $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - if ($christmasDay->isFriday()) { - $boxingDay = $boxingDay->next('monday'); - } - if ($christmasDay->isSaturday()) { - $boxingDay = $boxingDay->next('tuesday'); + if ($holiday->isWeekend()) { + return $holiday->next('monday'); } - return $boxingDay; + return $holiday; } - /** - * Get holiday - * - * For example: If a holiday falls on a weekend, the new day to be observed is the next monday - */ - protected function getHoliday(int $year, string $monthAndDay): CarbonImmutable + protected function christmas(int $year): CarbonInterface { - $newYearsDay = new CarbonImmutable($year.'-'.$monthAndDay); + return (new CarbonImmutable($year.'-12-25'))->startOfDay(); + } - if ($newYearsDay->isWeekend()) { - $newYearsDay = $newYearsDay->next('monday'); - } + protected function observedChristmasDay(int $year): CarbonInterface + { + $christmasDay = $this->christmas($year); - return $newYearsDay; + return match ($christmasDay->dayName) { + 'Saturday' => $christmasDay->next('monday'), + 'Sunday' => $christmasDay->next('tuesday'), + default => $christmasDay, + }; } - protected function allHolidays(int $year): array + protected function observedBoxingDay(int $year): CarbonInterface { - return array_merge( - [ - 'New Year\'s Day' => $this->getHoliday($year, '01-01'), - 'Constitution Day' => $this->getHoliday($year, '01-07'), - 'Independence Day' => $this->getHoliday($year, '03-06'), - 'May Day' => $this->getHoliday($year, '05-01'), - 'Founder\'s Day' => $this->getHoliday($year, '08-04'), - 'Kwame Nkrumah Memorial Day' => $this->getHoliday($year, '09-21'), - 'Christmas Day' => $this->christmasDay($year), - 'Boxing Day' => $this->boxingDay($year), - ], - $this->variableHolidays($year) - ); + $christmasDay = $this->christmas($year); + $boxingDay = new CarbonImmutable($year.'-12-26'); + + return match ($christmasDay->dayName) { + 'Friday' => $boxingDay->next('monday'), + 'Saturday' => $boxingDay->next('tuesday'), + default => $boxingDay, + }; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $farmersDay = new CarbonImmutable('first friday of December '.$year); + $farmersDay = (new CarbonImmutable('first friday of December '.$year))->startOfDay(); return [ 'Farmers Day' => $farmersDay, @@ -99,8 +95,6 @@ protected function variableHolidays(int $year): array // NB: *** There are no fixed dates for the Eid-Ul-Fitr and Eid-Ul-Adha because they are movable feasts. // The dates for their observation are provided by the Office of the Chief Imam in the course of the year. - // 'Eid-Ul-Fitr' => "", - // 'Eid-Ul-Adha' => "", ]; } } From 9a7cf77f740c23fae87a5fcf362054dce0401533 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:25:54 +0100 Subject: [PATCH 22/50] cleanup Canada --- src/Countries/Angola.php | 1 - src/Countries/Canada.php | 45 ++++++++++++++------------------------- src/Countries/Country.php | 6 +++++- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/Countries/Angola.php b/src/Countries/Angola.php index 0ef3bb72a..982c4f3ed 100644 --- a/src/Countries/Angola.php +++ b/src/Countries/Angola.php @@ -13,7 +13,6 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge([ 'Dia de Ano Novo' => '01-01', 'Dia do Inicio da Luta Armada de Libertação Nacional' => '02-04', diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index 52ea0e958..653f6b0c9 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Canada extends Country { @@ -13,48 +14,34 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge( - [ - 'New Year\'s Day' => new CarbonImmutable($year.'-01-01', 'America/Toronto'), - 'Canada Day' => new CarbonImmutable($year.'-07-01', 'America/Toronto'), - 'Civic Holiday' => new CarbonImmutable( - 'first monday of August '.$year, 'America/Toronto' - ), - 'Labour Day' => new CarbonImmutable( - 'first monday of September '.$year, 'America/Toronto' - ), - 'National Day for Truth and Reconciliation' => new CarbonImmutable( - $year.'-09-30', - 'America/Toronto' - ), - 'Remembrance Day' => new CarbonImmutable($year.'-11-11', 'America/Toronto'), - 'Christmas Day' => new CarbonImmutable($year.'-12-25', 'America/Toronto'), - 'Boxing Day' => new CarbonImmutable($year.'-12-26', 'America/Toronto'), - ], - $this->variableHolidays($year) - ); + return array_merge([ + 'New Year\'s Day' => '01-01', + 'Canada Day' => '07-01', + 'Civic Holiday' => 'first monday of August', + 'Labour Day' => 'first monday of September', + 'National Day for Truth and Reconciliation' => '09-30', + 'Remembrance Day' => '11-11', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $goodFriday = $easter->subDays(2); - $easterMonday = $easter->addDay(); + $victoriaDay = (new CarbonImmutable("last monday of May $year"))->startOfDay(); - $victoriaDay = new CarbonImmutable("last monday of May $year", 'America/Toronto'); if ($victoriaDay->day < 25) { $victoriaDay = $victoriaDay->addWeek(); } - $thanksgiving = new CarbonImmutable("second monday of October $year", 'America/Toronto'); - return [ 'Victoria Day' => $victoriaDay, - 'Good Friday' => $goodFriday, - 'Easter Monday' => $easterMonday, - 'Thanksgiving' => $thanksgiving, + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + 'Thanksgiving' => "second monday of October", ]; } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index fa0352908..7006191bd 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -26,7 +26,11 @@ public function get(int $year, ?string $locale = null): array $translatedHolidays = []; foreach ($allHolidays as $name => $date) { if (is_string($date)) { - $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); + if (strlen($date) > 5) { + $date = (new CarbonImmutable($date . ' ' . $year))->startOfDay(); + } else { + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); + } } $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); From 2656e5b1dbba0c16bd23dec677272734ebda3115 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 10:26:31 +0000 Subject: [PATCH 23/50] Fix styling --- src/Countries/Canada.php | 2 +- src/Countries/Country.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index 653f6b0c9..f1350e198 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -41,7 +41,7 @@ protected function variableHolidays(int $year): array 'Victoria Day' => $victoriaDay, 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), - 'Thanksgiving' => "second monday of October", + 'Thanksgiving' => 'second monday of October', ]; } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 7006191bd..34f0284d2 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -27,7 +27,7 @@ public function get(int $year, ?string $locale = null): array foreach ($allHolidays as $name => $date) { if (is_string($date)) { if (strlen($date) > 5) { - $date = (new CarbonImmutable($date . ' ' . $year))->startOfDay(); + $date = (new CarbonImmutable($date.' '.$year))->startOfDay(); } else { $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); } From c1bf3597de13f370e50cdcb2088ed0b9d4059b3d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:31:14 +0100 Subject: [PATCH 24/50] cleanup Finland --- src/Countries/Finland.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 32e75c649..84fcf74a6 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -14,19 +14,22 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge($this->fixedHolidays($year), $this->variableHolidays($year)); + return array_merge( + $this->fixedHolidays(), + $this->variableHolidays($year) + ); } - /** @return array */ - protected function fixedHolidays(int $year): array + /** @return array */ + protected function fixedHolidays(): array { return [ - 'Uudenvuodenpäivä' => CarbonImmutable::createFromDate($year, 1, 1), - 'Loppiainen' => CarbonImmutable::createFromDate($year, 1, 6), - 'Vappu' => CarbonImmutable::createFromDate($year, 5, 1), - 'Itsenäisyyspäivä' => CarbonImmutable::createFromDate($year, 12, 6), - 'Joulupäivä' => CarbonImmutable::createFromDate($year, 12, 25), - 'Tapaninpäivä' => CarbonImmutable::createFromDate($year, 12, 26), + 'Uudenvuodenpäivä' => '01-01', + 'Loppiainen' => '01-06', + 'Vappu' => '05-01', + 'Itsenäisyyspäivä' => '12-06', + 'Joulupäivä' => '12-25', + 'Tapaninpäivä' => '12-26' ]; } @@ -36,7 +39,7 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); $midsummerDay = CarbonImmutable::createFromDate($year, 6, 20) - ->next(CarbonImmutable::SATURDAY); + ->next(CarbonInterface::SATURDAY); return [ 'Pitkäperjantai' => $easter->subDays(2), @@ -48,7 +51,7 @@ protected function variableHolidays(int $year): array ? $midsummerDay->subWeek() : $midsummerDay, 'Pyhäinpäivä' => CarbonImmutable::createFromDate($year, 10, 31) - ->next(CarbonImmutable::SATURDAY), + ->next(CarbonInterface::SATURDAY), ]; } } From 1068902d7c16c4dc4adeb579a0a4e4b266eeb233 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:35:16 +0100 Subject: [PATCH 25/50] cleanup Germany --- src/Countries/Germany.php | 78 +++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php index e0b61f282..fda0dc46e 100644 --- a/src/Countries/Germany.php +++ b/src/Countries/Germany.php @@ -16,25 +16,48 @@ public function countryCode(): string return 'de'; } - private function getRepentanceAndPrayerDay(int $year): string + protected function allHolidays(int $year): array + { + return array_merge([ + 'Neujahr' => '01-01', + 'Tag der Arbeit' => '05-01', + '1. Weihnachtstag' => '12-25', + '2. Weihnachtstag' => '12-26', + ], + $this->variableHolidays($year), + $this->historicalHolidays($year), + $this->regionHolidays($year) + ); + } + + /** @return array */ + protected function variableHolidays(int $year): array { - $repentanceAndPrayerDay = new CarbonImmutable('next wednesday '.$year.'-11-15', 'Europe/Berlin'); + $easter = $this->easter($year); - return $repentanceAndPrayerDay->format('m-d'); + return [ + 'Karfreitag' => $easter->subDays(2), + 'Ostermontag' => $easter->addDay(), + 'Himmelfahrt' => $easter->addDays(39), + 'Pfingstmontag' => $easter->addDays(50), + ]; } /** @return array */ protected function historicalHolidays(int $year): array { $historicalHolidays = []; + if ($year >= 1954 && $year <= 1990) { $historicalHolidays['Tag der deutschen Einheit'] = '06-17'; } else { $historicalHolidays['Tag der deutschen Einheit'] = '10-03'; } + if ($year >= 1990 && $year <= 1994) { $historicalHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year); } + if ($year === 2017) { $historicalHolidays['Reformationstag'] = '10-31'; } @@ -42,32 +65,6 @@ protected function historicalHolidays(int $year): array return $historicalHolidays; } - /** @return array */ - protected function allHolidays(int $year): array - { - - return array_merge([ - 'Neujahr' => '01-01', - 'Tag der Arbeit' => '05-01', - '1. Weihnachtstag' => '12-25', - '2. Weihnachtstag' => '12-26', - ], $this->variableHolidays($year), $this->historicalHolidays($year), $this->regionHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - - $easter = $this->easter($year); - - return [ - 'Karfreitag' => $easter->subDays(2), - 'Ostermontag' => $easter->addDay(), - 'Himmelfahrt' => $easter->addDays(39), - 'Pfingstmontag' => $easter->addDays(50), - ]; - } - /** @return array */ protected function regionHolidays(int $year): array { @@ -111,12 +108,12 @@ protected function regionHolidays(int $year): array 'Reformationstag' => '10-31', 'Pfingstsonntag' => $easter->addDays(49), ]; - } else { - return [ - 'Ostersonntag' => $easter, - 'Pfingstsonntag' => $easter->addDays(49), - ]; } + + return [ + 'Ostersonntag' => $easter, + 'Pfingstsonntag' => $easter->addDays(49), + ]; case 'DE-HB': case 'DE-HH': case 'DE-NI': @@ -125,12 +122,10 @@ protected function regionHolidays(int $year): array return [ 'Reformationstag' => '10-31', ]; - } else { - return [ - - ]; } + return []; + case 'DE-HE': return [ 'Ostersonntag' => $easter, @@ -142,6 +137,7 @@ protected function regionHolidays(int $year): array if ($year >= 1990) { $mvHolidays['Reformationstag'] = '10-31'; } + if ($year >= 2023) { $mvHolidays['Internationaler Frauentag'] = '03-08'; } @@ -191,9 +187,13 @@ protected function regionHolidays(int $year): array } return $thHolidays; - } return []; } + + protected function getRepentanceAndPrayerDay(int $year): CarbonImmutable + { + return (new CarbonImmutable('next wednesday '.$year.'-11-15'))->startOfDay(); + } } From b86e83177524ba7b076b2178c49b49c3aa87d0e0 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 10:35:54 +0000 Subject: [PATCH 26/50] Fix styling --- src/Countries/Finland.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 84fcf74a6..bcb2e72cd 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -29,7 +29,7 @@ protected function fixedHolidays(): array 'Vappu' => '05-01', 'Itsenäisyyspäivä' => '12-06', 'Joulupäivä' => '12-25', - 'Tapaninpäivä' => '12-26' + 'Tapaninpäivä' => '12-26', ]; } From 5076e376ae127e009838a2dbc3483259d36e80cc Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:37:36 +0100 Subject: [PATCH 27/50] cleanup Greece --- src/Countries/Greece.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 5a0b0a450..095405980 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -29,32 +29,30 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - // OrthodoxEaster needs to setTimezone $orthodoxEaster = $this->orthodoxEaster($year); - $cleanMonday = $orthodoxEaster->copy()->subDays(48); + $megaliParaskevi = $orthodoxEaster->copy()->subDays(2); - $megaloSavvato = $orthodoxEaster->copy()->subDays(1); + $megaloSavvato = $orthodoxEaster->copy()->subDay(); $deuteraPasha = $orthodoxEaster->copy()->addDay(); - $agiouPneumatos = $orthodoxEaster->copy()->addDays(50); - /** @var CarbonImmutable $protomagia */ $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); $moveProtomagia = [$megaliParaskevi, $megaloSavvato, $orthodoxEaster, $deuteraPasha]; - if (in_array($protomagia, $moveProtomagia)) { + if (in_array($protomagia, $moveProtomagia, true)) { $protomagia = $orthodoxEaster->copy()->addDays(2); } + if ($protomagia->isSunday()) { $protomagia = $protomagia->copy()->addDay(); } return [ - 'Καθαρά Δευτέρα' => $cleanMonday, //always Monday + 'Καθαρά Δευτέρα' => $orthodoxEaster->copy()->subDays(48), //always Monday 'Πρωτομαγιά' => $protomagia, 'Μεγάλη Παρασκευή' => $megaliParaskevi, 'Κυριακή του Πάσχα' => $orthodoxEaster, 'Δευτέρα του Πάσχα' => $deuteraPasha, - 'Αγίου Πνεύματος' => $agiouPneumatos, //always Monday + 'Αγίου Πνεύματος' => $orthodoxEaster->copy()->addDays(50), //always Monday ]; } } From 1de06fde013cb89c6268c8b2ec4df162de23e141 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:43:12 +0100 Subject: [PATCH 28/50] cleanup Ireland --- src/Countries/Ireland.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 527cd487e..5c24fe3fe 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -16,6 +16,10 @@ protected function allHolidays(int $year): array return array_merge([ 'New Year\'s Day' => '01-01', 'Saint Patrick\'s Day' => '03-17', + 'May Public Holiday' => 'first monday of May', + 'June Public Holiday' => 'first monday of June', + 'August Public Holiday' => 'first monday of August', + 'October Public Holiday' => 'last monday of October', 'Christmas Day' => '12-25', 'Saint Stephen\'s Day' => '12-26', ], $this->variableHolidays($year)); @@ -26,26 +30,17 @@ protected function variableHolidays(int $year): array { $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'); - $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, + 'Easter Monday' => $this->easter($year)->addDay(), ]; - // 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'); + $stBrigidsDay = (new CarbonImmutable("$year-02-01"))->startOfDay(); + if (! $stBrigidsDay->isFriday()) { - $stBrigidsDay = new CarbonImmutable("first monday of February $year", 'Europe/Dublin'); + $stBrigidsDay = 'first monday of February'; } + $variableHolidays['St Brigid\'s Day'] = $stBrigidsDay; } From 3b399729c889f4cb27d136870c6c852b8de3c164 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:17:37 +0100 Subject: [PATCH 29/50] cleanup Jamaica --- src/Countries/Ireland.php | 2 +- src/Countries/Jamaica.php | 57 +++++++++++++++------------------ tests/Countries/JamaicaTest.php | 1 - 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 5c24fe3fe..9478a026a 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -25,7 +25,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index 751fb994b..9867a50de 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -14,18 +14,14 @@ public function countryCode(): string protected function allHolidays(int $year): array { - - $holidays = array_merge( - $this->fixedHolidays(), + return array_merge( + $this->fixedHolidays($year), $this->variableHolidays($year), - $this->observedHolidays($year) ); - - return $holidays; } - /** @return array */ - protected function fixedHolidays(): array + /** @return array */ + protected function fixedHolidays(int $year): array { $holidays = [ 'New Year\'s Day' => '01-01', @@ -36,49 +32,46 @@ protected function fixedHolidays(): array 'Boxing Day' => '12-26', ]; + foreach ($holidays as $name => $date) { + $observedDay = $this->observed($name, $date, $year); + + if ($observedDay) { + $holidays[$name . ' Observed'] = $observedDay; + } + } + return $holidays; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $heroesDay = new CarbonImmutable("third monday of October $year"); return [ 'Ash Wednesday' => $easter->subDays(46), 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), - 'National Heroes Day' => $heroesDay, + 'National Heroes Day' => 'third monday of October', ]; } - /** @return array */ - protected function observedHolidays(int $year): array + protected function observed(string $name, string $date, int $year): ?CarbonInterface { + $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $observedHolidays = []; - - foreach ($this->fixedHolidays() as $name => $date) { - $date = CarbonImmutable::parse("$year-$date"); - - // If any holiday falls on a Sunday, then it is observed on Monday - if ($date->dayOfWeek === 0) { - $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); - } + if ($holiday->isSunday()) { + return $holiday->next('monday'); + } - // If Labour Day falls on a Saturday, then it is observed on Monday - if ($name == 'Labour Day' && $date->dayOfWeek === 6) { - $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); - } + if ($name === 'Labour Day' && $holiday->isSaturday()) { + return $holiday->next('monday'); + } - // If Boxing Day falls on a Monday, then it is observed on Tuesday (Christmas Day is observed on Monday) - // https://jis.gov.jm/observance-public-holidays-christmas-day-monday-december-26th-boxing-day-tuesday-december-27th/ - if ($name == 'Boxing Day' && $date->dayOfWeek === 1) { - $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::TUESDAY); - } + if ($name === 'Boxing Day' && $holiday->isMonday()) { + return $holiday->next('tuesday'); } - return $observedHolidays; + return null; } } diff --git a/tests/Countries/JamaicaTest.php b/tests/Countries/JamaicaTest.php index 5b06881f5..2f1a06efd 100644 --- a/tests/Countries/JamaicaTest.php +++ b/tests/Countries/JamaicaTest.php @@ -30,5 +30,4 @@ // Check that there is no Observerd New Year's Day $holidays = Holidays::for(country: 'jm', year: 2024)->get(); expect(array_search('Labour Day Observed', array_column($holidays, 'name')))->toBeFalse(); - }); From 05dfd85ecb8c39a2a8eaa7c7fd6e2b5becf22595 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:19:23 +0100 Subject: [PATCH 30/50] cleanup Japan --- src/Countries/Japan.php | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index a15d890c5..455c9c7b8 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; - class Japan extends Country { public function countryCode(): string @@ -13,8 +11,9 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge([ + return [ '元日' => '01-01', // New Year's Day + '成人の日' => 'second monday of january', '建国記念の日' => '02-11', // Foundation Day '天皇誕生日' => '02-23', // Emperor's Birthday '春分の日' => '03-20', // Vernal Equinox Day *Decided each year; rarely on 03-21 @@ -22,33 +21,14 @@ protected function allHolidays(int $year): array '憲法記念日' => '05-03', // Constitution Day 'みどりの日' => '05-04', // Greenery Day 'こどもの日' => '05-05', // Children's Day + '海の日' => 'third monday of july', '山の日' => '08-11', // Mountain Day + '敬老の日' => 'third monday of september', '秋分の日' => '09-23', // Autumnal Equinox Day *Decided each year; rarely on 09-22 + 'スポーツの日' => 'second monday of october', '文化の日' => '11-03', // Culture Day '勤労感謝の日' => '11-23', // Labor Thanksgiving Day - ], $this->variableHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $comingOfAgeDay = (new CarbonImmutable("second monday of january $year"))->startOfDay(); - - $oceansDay = (new CarbonImmutable("third monday of july $year"))->startOfDay(); - - $respectForTheAgedDay = (new CarbonImmutable("third monday of september $year"))->startOfDay(); - - $sportsDay = (new CarbonImmutable("second monday of october $year"))->startOfDay(); - - $holidays = [ - '成人の日' => $comingOfAgeDay, - '海の日' => $oceansDay, - '敬老の日' => $respectForTheAgedDay, - 'スポーツの日' => $sportsDay, ]; - - return $holidays; - } } From bdcaa57b87134e89d3d64fc8133c4fe1c8ab63f3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:24:39 +0100 Subject: [PATCH 31/50] cleanup --- src/Countries/Latvia.php | 7 ++-- src/Countries/Montenegro.php | 7 ++-- src/Countries/Netherlands.php | 1 - src/Countries/NorthernIreland.php | 58 +++++++++++-------------------- 4 files changed, 28 insertions(+), 45 deletions(-) diff --git a/src/Countries/Latvia.php b/src/Countries/Latvia.php index b5c088605..fb26ede73 100644 --- a/src/Countries/Latvia.php +++ b/src/Countries/Latvia.php @@ -24,7 +24,10 @@ protected function allHolidays(int $year): array 'Pirmie Ziemassvētki' => '12-25', 'Otrie Ziemassvētki' => '12-26', 'Vecgada vakars' => '12-31', - ], $this->variableHolidays($year), $this->postponedHolidays($year)); + ], + $this->variableHolidays($year), + $this->observedHolidays($year) + ); } /** @return array */ @@ -40,7 +43,7 @@ protected function variableHolidays(int $year): array } /** @return array */ - protected function postponedHolidays(int $year): array + protected function observedHolidays(int $year): array { // If the holidays - May 4 and November 18 - fall on a Saturday or Sunday, // the next working day is designated as a holiday. diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php index b653d4a4f..9ff1de06e 100644 --- a/src/Countries/Montenegro.php +++ b/src/Countries/Montenegro.php @@ -35,15 +35,12 @@ public function allHolidays(int $year): array /** @return array */ public function variableHolidays(int $year): array { - // Orthodox Easter calculation needs to be in the same timezone as the country $orthodoxEaster = $this->orthodoxEaster($year); - $goodFriday = $orthodoxEaster->copy()->subDays(2); - $orthodoxEasterMonday = $orthodoxEaster->copy()->addDay(); return [ 'Vaskrs' => $orthodoxEaster, - 'Vaskršnji ponedjeljak' => $orthodoxEasterMonday, - 'Veliki petak' => $goodFriday, + 'Vaskršnji ponedjeljak' => $orthodoxEaster->copy()->addDay(), + 'Veliki petak' => $orthodoxEaster->copy()->subDays(2), ]; } } diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index 44ae6ae7c..34f3b37fc 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -24,7 +24,6 @@ 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()) { diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index cb424980f..4bdbf2c1f 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -12,6 +12,27 @@ public function countryCode(): string return 'gb-nir'; } + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->stPatricksDay($year), + $this->earlyMayBankHoliday($year), + $this->battleOfTheBoyne($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + ], + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + } + /** @return array */ private function stPatricksDay(int $year): array { @@ -51,41 +72,4 @@ protected function oneOffHolidays(int $year): array default => [], }; } - - /** @return array */ - protected function allHolidays(int $year): array - { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->stPatricksDay($year), - $this->earlyMayBankHoliday($year), - $this->battleOfTheBoyne($year), - [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), - ], - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) - ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); - - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $easterSunday = $this->easter($year); - - $goodFriday = $easterSunday->subDays(2); - $easterMonday = $easterSunday->addDay(); - - return [ - 'Good Friday' => $goodFriday, - 'Easter Monday' => $easterMonday, - ]; - } } From bf1c6a52902746b6576bdb5e9e703bad3daa348e Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:29:14 +0100 Subject: [PATCH 32/50] cleanup SouthAfrica --- src/Countries/SouthAfrica.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index 64d404127..1d9cb1379 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; use function in_array; class SouthAfrica extends Country @@ -31,16 +32,10 @@ protected function allHolidays(int $year): array ]; foreach ($holidays as $name => $date) { - $holidayDate = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); - assert($holidayDate instanceof CarbonImmutable); - - // The Public Holidays Act (Act No 36 of 1994) states that whenever a public holiday falls on a Sunday, the Monday following it will be a public holiday. - // https://www.gov.za/documents/public-holidays-act - if ( - $holidayDate->isSunday() && - ! in_array($holidayDate->addDay()->format('m-d'), $holidays, true) // Check that the Monday is not already a holiday - ) { - $holidays[$name.' Observed'] = $holidayDate->addDay(); + $observedDay = $this->observed($date, $year); + + if ($observedDay) { + $holidays[$name . ' Observed'] = $observedDay; } } @@ -57,4 +52,16 @@ protected function variableHolidays(int $year): array 'Family Day' => $easter->addDay(), ]; } + + protected function observed(string $date, int $year): ?CarbonInterface + { + $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + + // https://www.gov.za/documents/public-holidays-act + if ($holiday->isSunday()) { + return $holiday->next('monday'); + } + + return null; + } } From 9d5fcdfc736d1982d9d890f08d0c2417652e380d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:32:34 +0100 Subject: [PATCH 33/50] cleanup --- src/Countries/Spain.php | 4 ++-- src/Countries/UnitedStates.php | 27 +++++++++------------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php index 27a7f166f..46a46e805 100644 --- a/src/Countries/Spain.php +++ b/src/Countries/Spain.php @@ -57,9 +57,9 @@ protected function regionHolidays(int $year): array $method = "regionHolidays{$year}"; if (method_exists($this, $method)) { return $this->$method(); - } else { - throw InvalidYear::range($this->countryCode()." ({$this->region})", 2022, 2024); } + + throw InvalidYear::range($this->countryCode()." ({$this->region})", 2022, 2024); } /** @return array */ diff --git a/src/Countries/UnitedStates.php b/src/Countries/UnitedStates.php index 695103dca..9cccfad73 100644 --- a/src/Countries/UnitedStates.php +++ b/src/Countries/UnitedStates.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; - class UnitedStates extends Country { public function countryCode(): string @@ -18,7 +16,7 @@ protected function allHolidays(int $year): array 'Independence Day' => '07-04', 'Veterans Day' => '11-11', 'Christmas' => '12-25', - ], $this->variableHolidays($year)); + ], $this->variableHolidays()); if ($year >= 2021) { $holidays['Juneteenth National Independence Day'] = '06-19'; @@ -27,23 +25,16 @@ protected function allHolidays(int $year): array return $holidays; } - /** @return array */ - protected function variableHolidays(int $year): array + /** @return array */ + protected function variableHolidays(): array { - $martinLutherKingDay = new CarbonImmutable("third monday of January $year", 'America/Los_Angeles'); - $presidentsDay = new CarbonImmutable("third monday of February $year", 'America/Los_Angeles'); - $memorialDay = new CarbonImmutable("last monday of May $year", 'America/Los_Angeles'); - $laborDay = new CarbonImmutable("first monday of September $year", 'America/Los_Angeles'); - $columbusDay = new CarbonImmutable("second monday of October $year", 'America/Los_Angeles'); - $thanksgiving = new CarbonImmutable("fourth thursday of November $year", 'America/Los_Angeles'); - return [ - 'Martin Luther King Day' => $martinLutherKingDay, - 'Presidents\' Day' => $presidentsDay, - 'Memorial Day' => $memorialDay, - 'Labor Day' => $laborDay, - 'Columbus Day' => $columbusDay, - 'Thanksgiving' => $thanksgiving, + 'Martin Luther King Day' => 'third monday of January', + 'Presidents\' Day' => 'third monday of February', + 'Memorial Day' => 'last monday of May', + 'Labor Day' => 'first monday of September', + 'Columbus Day' => 'second monday of October', + 'Thanksgiving' => 'fourth thursday of November', ]; } } From 4b1740c3234bf47a2f7f4621f99e5adeb72fcc89 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 11:33:08 +0000 Subject: [PATCH 34/50] Fix styling --- src/Countries/Jamaica.php | 2 +- src/Countries/SouthAfrica.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index 9867a50de..801217120 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -36,7 +36,7 @@ protected function fixedHolidays(int $year): array $observedDay = $this->observed($name, $date, $year); if ($observedDay) { - $holidays[$name . ' Observed'] = $observedDay; + $holidays[$name.' Observed'] = $observedDay; } } diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index 1d9cb1379..f85b14255 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -3,9 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; - use Carbon\CarbonInterface; -use function in_array; class SouthAfrica extends Country { @@ -35,7 +33,7 @@ protected function allHolidays(int $year): array $observedDay = $this->observed($date, $year); if ($observedDay) { - $holidays[$name . ' Observed'] = $observedDay; + $holidays[$name.' Observed'] = $observedDay; } } From 09d3f02f6e0d2bbade09328aad505cc8d911f82f Mon Sep 17 00:00:00 2001 From: abdulrhman aboukalam <108075143+abdulrhmanak213@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:37:45 +0300 Subject: [PATCH 35/50] Adding holidays for syria (#201) * Adding holidays for syria * fix language error * Update src/Countries/Syria.php --------- Co-authored-by: abdalrhman ak Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/syria/ar/holidays.json | 16 +++++ src/Countries/Syria.php | 40 +++++++++++++ .../it_can_calculate_syria_holidays.snap | 58 +++++++++++++++++++ ..._translate_syria_holidays_into_arabic.snap | 58 +++++++++++++++++++ tests/Countries/SyriaTest.php | 25 ++++++++ 5 files changed, 197 insertions(+) create mode 100644 lang/syria/ar/holidays.json create mode 100644 src/Countries/Syria.php create mode 100644 tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap create mode 100644 tests/Countries/SyriaTest.php diff --git a/lang/syria/ar/holidays.json b/lang/syria/ar/holidays.json new file mode 100644 index 000000000..0d8232130 --- /dev/null +++ b/lang/syria/ar/holidays.json @@ -0,0 +1,16 @@ +{ + "New Year\n's Day": "يوم رأس السنة", + "Mother\n's Day": "عيد الأم", + "Teacher\n's Day": "عيد المعلم", + "Western Easter": "عيد الفصح الغربي", + "Eid al-Fitr": "عيد الفطر السعيد", + "Syrian Independence Day": "عيد الجلاء واستقلال سورية", + "Labor Day": "عيد العمال", + "Eastern Easter": "عيد الفصح الشرقي", + "Martyrs\n' Day": "عيد الشهداء", + "Eid al-Adha": "عيد الأضحى المبارك", + "Islamic New Year": "عيد رأس السنة الهجرية", + "The commemoration of the birth of the Prophet Muhammad": "عيد مولد الرسول الأعظم", + "The October Liberation War": "ذكرى حرب تشرين التحريرية", + "Merry Christmas": "عيد الميلاد المجيد" +} diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php new file mode 100644 index 000000000..b71845d0b --- /dev/null +++ b/src/Countries/Syria.php @@ -0,0 +1,40 @@ + '01-01', + "Mother\n's Day" => '03-21', + "Teacher\n's Day" => '03-21', + "Western Easter" => '03-31', + "Eid al-Fitr" => '04-10', + "Syrian Independence Day" => '04-17', + "Labor Day" => '05-01', + "Eastern Easter" => '05-05', + "Martyr\n's Day" => '05-06', + "Eid al-Adha" => '06-16', + "Islamic New Year" => '07-07', + "The commemoration of the birth of the Prophet Muhammad" => '09-15', + "The October Liberation War" => '10-06', + "Christmas" => '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/SyriaTest/it_can_calculate_syria_holidays.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap new file mode 100644 index 000000000..ac2f037d4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "New Year\n's Day", + "date": "2024-01-01" + }, + { + "name": "Mother\n's Day", + "date": "2024-03-21" + }, + { + "name": "Teacher\n's Day", + "date": "2024-03-21" + }, + { + "name": "Western Easter", + "date": "2024-03-31" + }, + { + "name": "Eid al-Fitr", + "date": "2024-04-10" + }, + { + "name": "Syrian Independence Day", + "date": "2024-04-17" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Eastern Easter", + "date": "2024-05-05" + }, + { + "name": "Martyr\n's Day", + "date": "2024-05-06" + }, + { + "name": "Eid al-Adha", + "date": "2024-06-16" + }, + { + "name": "Islamic New Year", + "date": "2024-07-07" + }, + { + "name": "The commemoration of the birth of the Prophet Muhammad", + "date": "2024-09-15" + }, + { + "name": "The October Liberation War", + "date": "2024-10-06" + }, + { + "name": "Merry Christmas", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap new file mode 100644 index 000000000..f61ec2e69 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap @@ -0,0 +1,58 @@ +[ + { + "name": "\u064a\u0648\u0645 \u0631\u0623\u0633 \u0627\u0644\u0633\u0646\u0629", + "date": "2024-01-01" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0623\u0645", + "date": "2024-03-21" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0645\u0639\u0644\u0645", + "date": "2024-03-21" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0641\u0635\u062d \u0627\u0644\u063a\u0631\u0628\u064a", + "date": "2024-03-31" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0641\u0637\u0631 \u0627\u0644\u0633\u0639\u064a\u062f", + "date": "2024-04-10" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u062c\u0644\u0627\u0621 \u0648\u0627\u0633\u062a\u0642\u0644\u0627\u0644 \u0633\u0648\u0631\u064a\u0629", + "date": "2024-04-17" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0639\u0645\u0627\u0644", + "date": "2024-05-01" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0641\u0635\u062d \u0627\u0644\u0634\u0631\u0642\u064a", + "date": "2024-05-05" + }, + { + "name": "Martyr\n's Day", + "date": "2024-05-06" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0623\u0636\u062d\u0649 \u0627\u0644\u0645\u0628\u0627\u0631\u0643", + "date": "2024-06-16" + }, + { + "name": "\u0639\u064a\u062f \u0631\u0623\u0633 \u0627\u0644\u0633\u0646\u0629 \u0627\u0644\u0647\u062c\u0631\u064a\u0629", + "date": "2024-07-07" + }, + { + "name": "\u0639\u064a\u062f \u0645\u0648\u0644\u062f \u0627\u0644\u0631\u0633\u0648\u0644 \u0627\u0644\u0623\u0639\u0638\u0645", + "date": "2024-09-15" + }, + { + "name": "\u0630\u0643\u0631\u0649 \u062d\u0631\u0628 \u062a\u0634\u0631\u064a\u0646 \u0627\u0644\u062a\u062d\u0631\u064a\u0631\u064a\u0629", + "date": "2024-10-06" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0645\u064a\u0644\u0627\u062f \u0627\u0644\u0645\u062c\u064a\u062f", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/SyriaTest.php b/tests/Countries/SyriaTest.php new file mode 100644 index 000000000..6bf5ed7df --- /dev/null +++ b/tests/Countries/SyriaTest.php @@ -0,0 +1,25 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); +it('can translate syria holidays into arabic', function () { + $holidays = Holidays::for(country: 'sy', year: 2024, locale: 'ar')->get(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 6d47df35843efd83063a9f9eb80fb0e482b5e8f9 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 11:38:04 +0000 Subject: [PATCH 36/50] Fix styling --- src/Countries/Syria.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php index b71845d0b..86ecd5d38 100644 --- a/src/Countries/Syria.php +++ b/src/Countries/Syria.php @@ -17,17 +17,17 @@ protected function allHolidays(int $year): array "New Year\n's Day" => '01-01', "Mother\n's Day" => '03-21', "Teacher\n's Day" => '03-21', - "Western Easter" => '03-31', - "Eid al-Fitr" => '04-10', - "Syrian Independence Day" => '04-17', - "Labor Day" => '05-01', - "Eastern Easter" => '05-05', + 'Western Easter' => '03-31', + 'Eid al-Fitr' => '04-10', + 'Syrian Independence Day' => '04-17', + 'Labor Day' => '05-01', + 'Eastern Easter' => '05-05', "Martyr\n's Day" => '05-06', - "Eid al-Adha" => '06-16', - "Islamic New Year" => '07-07', - "The commemoration of the birth of the Prophet Muhammad" => '09-15', - "The October Liberation War" => '10-06', - "Christmas" => '12-25', + 'Eid al-Adha' => '06-16', + 'Islamic New Year' => '07-07', + 'The commemoration of the birth of the Prophet Muhammad' => '09-15', + 'The October Liberation War' => '10-06', + 'Christmas' => '12-25', ], $this->variableHolidays($year)); } From b62b7e09b67d2ab0aeb5b133ed49cc2f848b3827 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:39:12 +0100 Subject: [PATCH 37/50] update name --- .../Countries/SyriaTest/it_can_calculate_syria_holidays.snap | 2 +- .../SyriaTest/it_can_translate_syria_holidays_into_arabic.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap index ac2f037d4..4216d3aef 100644 --- a/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap @@ -52,7 +52,7 @@ "date": "2024-10-06" }, { - "name": "Merry Christmas", + "name": "Christmas", "date": "2024-12-25" } ] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap index f61ec2e69..297cf12ab 100644 --- a/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap @@ -52,7 +52,7 @@ "date": "2024-10-06" }, { - "name": "\u0639\u064a\u062f \u0627\u0644\u0645\u064a\u0644\u0627\u062f \u0627\u0644\u0645\u062c\u064a\u062f", + "name": "Christmas", "date": "2024-12-25" } ] \ No newline at end of file From 4dfcad3caa624ce4c13ce764005cbc38096589dc Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 11:40:42 +0000 Subject: [PATCH 38/50] Update CHANGELOG --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc14bbaa3..4e34faae1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to `holidays` will be documented in this file. +## 1.7.0 - 2024-02-08 + +### What's Changed + +* Add Uzbekistan Holidays by @shoxrux1996 in https://github.com/spatie/holidays/pull/81 +* Add Azerbaijan holidays by @kenanaga in https://github.com/spatie/holidays/pull/166 +* Enhanced holiday dates in Ghana by @Ikpeba4ll in https://github.com/spatie/holidays/pull/80 +* Adding holidays for syria by @abdulrhmanak213 in https://github.com/spatie/holidays/pull/201 + +### New Contributors + +* @shoxrux1996 made their first contribution in https://github.com/spatie/holidays/pull/81 +* @kenanaga made their first contribution in https://github.com/spatie/holidays/pull/166 +* @Ikpeba4ll made their first contribution in https://github.com/spatie/holidays/pull/80 +* @abdulrhmanak213 made their first contribution in https://github.com/spatie/holidays/pull/201 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.6.1...1.7.0 + ## 1.6.1 - 2024-02-07 ### What's Changed From aefc29be4479e691a0e026b2e17a83a63513e509 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:47:01 +0100 Subject: [PATCH 39/50] fix typehint --- phpstan-baseline.neon | 4 ---- src/Countries/Country.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dffb82781..7363751c6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,7 +25,3 @@ parameters: 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/Country.php b/src/Countries/Country.php index 34f0284d2..8c0322e21 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -16,7 +16,7 @@ abstract public function countryCode(): string; /** @return array */ abstract protected function allHolidays(int $year): array; - /** @return array */ + /** @return array */ public function get(int $year, ?string $locale = null): array { $this->ensureYearCanBeCalculated($year); From 0e9c3b5e1eca78d778a9bbf2f842c82615856b80 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:48:34 +0100 Subject: [PATCH 40/50] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 69240bf97..ff0482a2b 100644 --- a/README.md +++ b/README.md @@ -109,12 +109,9 @@ Holidays::has('be'); // true Holidays::has('unknown'); // false ``` -### Package limitations -1. Islamic holidays are not supported (yet) - ## Contributing -This is a community driven package. If you find any errors, please create an issue or a pull request. +This is a community driven package. If you find any errors, please create a pull request with the fix, or at least an issue. ## Adding a new country From cfb44ecaf47e849331858a8a430b8bd7e9442158 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:49:01 +0100 Subject: [PATCH 41/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff0482a2b..a695c87d5 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Holidays::has('unknown'); // false ## Contributing -This is a community driven package. If you find any errors, please create a pull request with the fix, or at least an issue. +This is a community driven package. If you find any errors, please create a pull request with the fix, or at least open an issue. ## Adding a new country From 26a8a5996fdb2d3ac05696820482ebe7b53c57ae Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:00:06 +0100 Subject: [PATCH 42/50] change for Ghana --- src/Countries/Ghana.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 1a6f0cab0..1046fa768 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -86,10 +86,8 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $farmersDay = (new CarbonImmutable('first friday of December '.$year))->startOfDay(); - return [ - 'Farmers Day' => $farmersDay, + 'Farmers Day' => 'first friday of December', 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), From 2f9a616fa558f526b1173efcad5ad35362b5d3cb Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:45:04 +0100 Subject: [PATCH 43/50] phpstan fix --- src/Countries/Ghana.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 1046fa768..08951f1a5 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -81,7 +81,7 @@ protected function observedBoxingDay(int $year): CarbonInterface }; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); From a5640531fb1563cdb10854a4a68ce94fa9e37b09 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:31:03 +0100 Subject: [PATCH 44/50] move Observed holiday logic to separate trait --- src/Concerns/Observable.php | 54 +++++++++++++ src/Countries/Ghana.php | 54 +++++-------- src/Countries/Ireland.php | 10 +-- src/Countries/Japan.php | 19 +++-- src/Countries/NorthernIreland.php | 4 +- src/Countries/Wales.php | 130 +++++++++++------------------- 6 files changed, 140 insertions(+), 131 deletions(-) create mode 100644 src/Concerns/Observable.php diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php new file mode 100644 index 000000000..52342c6fe --- /dev/null +++ b/src/Concerns/Observable.php @@ -0,0 +1,54 @@ +startOfDay(); + + return match ($christmasDay->dayName) { + 'Saturday' => $christmasDay->next('monday'), + 'Sunday' => $christmasDay->next('tuesday'), + default => null, + }; + } + + protected function observedBoxingDay(int $year): ?CarbonInterface + { + $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); + $boxingDay = $christmasDay->addDay(); + + return match ($christmasDay->dayName) { + 'Friday' => $boxingDay->next('monday'), + 'Saturday' => $boxingDay->next('tuesday'), + default => null, + }; + } + + protected function weekendToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface + { + if (is_string($date)) { + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + } + + if ($date->isWeekend()) { + return $date->next('monday'); + } + + return null; + } + + protected function sundayToNextMonday(CarbonInterface $date): ?CarbonInterface + { + if ($date->isSunday()) { + return $date->next('monday'); + } + + return null; + } +} diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 08951f1a5..2e9ed2d2d 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -4,9 +4,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class Ghana extends Country { + use Observable; + public function countryCode(): string { return 'gh'; @@ -20,7 +23,7 @@ protected function allHolidays(int $year): array ); } - /** @return array */ + /** @return array */ protected function observedHolidays(int $year): array { $holidays = [ @@ -30,16 +33,23 @@ protected function observedHolidays(int $year): array 'May Day' => '05-01', 'Founder\'s Day' => '08-04', 'Kwame Nkrumah Memorial Day' => '09-21', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', ]; - $holidays = array_map(function ($holiday) use ($year) { - return $this->observed($holiday, $year); - }, $holidays); + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name] = $observedDay; + } + } - return array_merge($holidays, [ - 'Christmas Day' => $this->observedChristmasDay($year), - 'Boxing Day' => $this->observedBoxingDay($year), - ]); + return $holidays; } protected function observed(string $date, int $year): CarbonInterface @@ -53,34 +63,6 @@ protected function observed(string $date, int $year): CarbonInterface return $holiday; } - protected function christmas(int $year): CarbonInterface - { - return (new CarbonImmutable($year.'-12-25'))->startOfDay(); - } - - protected function observedChristmasDay(int $year): CarbonInterface - { - $christmasDay = $this->christmas($year); - - return match ($christmasDay->dayName) { - 'Saturday' => $christmasDay->next('monday'), - 'Sunday' => $christmasDay->next('tuesday'), - default => $christmasDay, - }; - } - - protected function observedBoxingDay(int $year): CarbonInterface - { - $christmasDay = $this->christmas($year); - $boxingDay = new CarbonImmutable($year.'-12-26'); - - return match ($christmasDay->dayName) { - 'Friday' => $boxingDay->next('monday'), - 'Saturday' => $boxingDay->next('tuesday'), - default => $boxingDay, - }; - } - /** @return array */ protected function variableHolidays(int $year): array { diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 9478a026a..092bfdbdc 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -16,10 +16,6 @@ protected function allHolidays(int $year): array return array_merge([ 'New Year\'s Day' => '01-01', 'Saint Patrick\'s Day' => '03-17', - 'May Public Holiday' => 'first monday of May', - 'June Public Holiday' => 'first monday of June', - 'August Public Holiday' => 'first monday of August', - 'October Public Holiday' => 'last monday of October', 'Christmas Day' => '12-25', 'Saint Stephen\'s Day' => '12-26', ], $this->variableHolidays($year)); @@ -28,10 +24,12 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter($year); - $variableHolidays = [ 'Easter Monday' => $this->easter($year)->addDay(), + 'May Public Holiday' => 'first monday of May', + 'June Public Holiday' => 'first monday of June', + 'August Public Holiday' => 'first monday of August', + 'October Public Holiday' => 'last monday of October', ]; if ($year >= 2023) { diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index 455c9c7b8..3f00fdf29 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -2,6 +2,8 @@ namespace Spatie\Holidays\Countries; +use Carbon\CarbonImmutable; + class Japan extends Country { public function countryCode(): string @@ -11,9 +13,8 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return [ + return array_merge([ '元日' => '01-01', // New Year's Day - '成人の日' => 'second monday of january', '建国記念の日' => '02-11', // Foundation Day '天皇誕生日' => '02-23', // Emperor's Birthday '春分の日' => '03-20', // Vernal Equinox Day *Decided each year; rarely on 03-21 @@ -21,14 +22,22 @@ protected function allHolidays(int $year): array '憲法記念日' => '05-03', // Constitution Day 'みどりの日' => '05-04', // Greenery Day 'こどもの日' => '05-05', // Children's Day - '海の日' => 'third monday of july', '山の日' => '08-11', // Mountain Day - '敬老の日' => 'third monday of september', '秋分の日' => '09-23', // Autumnal Equinox Day *Decided each year; rarely on 09-22 - 'スポーツの日' => 'second monday of october', '文化の日' => '11-03', // Culture Day '勤労感謝の日' => '11-23', // Labor Thanksgiving Day + ], $this->variableHolidays()); + } + + /** @return array */ + protected function variableHolidays(): array + { + return [ + '成人の日' => 'second monday of january', + '海の日' => 'third monday of july', + '敬老の日' => 'third monday of september', + 'スポーツの日' => 'second monday of october', ]; } } diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 4bdbf2c1f..c5c30a2c3 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -20,8 +20,8 @@ protected function allHolidays(int $year): array $this->earlyMayBankHoliday($year), $this->battleOfTheBoyne($year), [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + 'Spring bank holiday' => 'last monday of may', + 'Summer bank holiday' => 'last monday of august', ], $this->christmasDay($year), $this->boxingDay($year), diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index 33e1ca3b8..f2ebc8612 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -4,130 +4,96 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class Wales extends Country { + use Observable; + public function countryCode(): string { return 'gb-cym'; } - /** @return array */ - protected function christmasDay(int $year): array + /** @return array */ + protected function allHolidays(int $year): array { - $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); - $key = 'Christmas Day'; - - if ($christmasDay->isSaturday()) { - $key .= ' (substitute day)'; - $christmasDay = $christmasDay->next('monday'); - } - - if ($christmasDay->isSunday()) { - $key .= ' (substitute day)'; - $christmasDay = $christmasDay->next('tuesday'); - } - - return [$key => $christmasDay]; + return array_merge( + $this->observedHolidays($year), + $this->earlyMayBankHoliday($year), + $this->variableHolidays($year), + $this->oneOffHolidays($year), + ); } - /** @return array */ - protected function boxingDay(int $year): array + /** @return array */ + protected function observedHolidays(int $year): array { - $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); - $boxingDay = new CarbonImmutable($year.'-12-26', 'Europe/London'); - $key = 'Boxing Day'; - - if ($christmasDay->isFriday()) { - $key .= ' (substitute day)'; - $boxingDay = $boxingDay->next('monday'); - } + $holidays = [ + 'New Year\'s Day' => '01-01', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; - if ($christmasDay->isSaturday()) { - $key .= ' (substitute day)'; - $boxingDay = $boxingDay->next('tuesday'); + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name.' (substitute day)'] = $observedDay; + unset($holidays[$name]); + } } - return [$key => $boxingDay]; + return $holidays; } - /** @return array */ - protected function newYearsDay(int $year): array + /** @return array */ + protected function variableHolidays(int $year): array { - $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); - $key = 'New Year\'s Day'; + $easterSunday = $this->easter($year); - if ($newYearsDay->isWeekend()) { - $key .= ' (substitute day)'; - $newYearsDay = $newYearsDay->next('monday'); - } + $goodFriday = $easterSunday->subDays(2); + $easterMonday = $easterSunday->addDay(); - return [$key => $newYearsDay]; + return [ + 'Good Friday' => $goodFriday, + 'Easter Monday' => $easterMonday, + 'Spring bank holiday' => 'last monday of may', + 'Summer bank holiday' => 'last monday of august', + ]; } - /** @return array */ + /** @return array */ protected function earlyMayBankHoliday(int $year): array { if ($year === 2020) { return [ - 'Early May bank holiday (VE day)' => new CarbonImmutable('2020-05-08', 'Europe/London'), + 'Early May bank holiday (VE day)' => (new CarbonImmutable('2020-05-08'))->startOfDay(), ]; } if ($year === 2023) { return [ - 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable('2020-05-08', 'Europe/London'), + 'Bank holiday for the coronation of King Charles III' => (new CarbonImmutable('2020-05-08'))->startOfDay(), ]; } - return ['Early May bank holiday' => new CarbonImmutable("first monday of may {$year}", 'Europe/London')]; + return ['Early May bank holiday' => 'first monday of may']; } - /** - * @return array|CarbonImmutable[] - */ + /** @return array */ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), + 'Platinum Jubilee bank holiday' => (new CarbonImmutable('2022-06-03'))->startOfDay(), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => (new CarbonImmutable('2022-09-19'))->startOfDay(), ], default => [], }; } - - /** @return array */ - protected function allHolidays(int $year): array - { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->earlyMayBankHoliday($year), - [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), - ], - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) - ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $easterSunday = $this->easter($year); - - $goodFriday = $easterSunday->subDays(2); - $easterMonday = $easterSunday->addDay(); - - return [ - 'Good Friday' => $goodFriday, - 'Easter Monday' => $easterMonday, - ]; - } } From 8e8a4a15e30ab0e14119b2010dc457294f52796a Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:55:53 +0100 Subject: [PATCH 45/50] cleanup Wales related countries --- src/Countries/NorthernIreland.php | 76 +++++++-------------- src/Countries/Scotland.php | 109 ++++++++++++------------------ 2 files changed, 71 insertions(+), 114 deletions(-) diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index c5c30a2c3..1d3779dfb 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -14,62 +14,38 @@ public function countryCode(): string protected function allHolidays(int $year): array { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->stPatricksDay($year), + return array_merge( + $this->observedHolidays($year), $this->earlyMayBankHoliday($year), - $this->battleOfTheBoyne($year), - [ - 'Spring bank holiday' => 'last monday of may', - 'Summer bank holiday' => 'last monday of august', - ], - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) + $this->variableHolidays($year), + $this->oneOffHolidays($year), ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); - } - - /** @return array */ - private function stPatricksDay(int $year): array - { - $stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London'); - $key = 'St Patrick\'s Day'; - - if ($stPatricksDay->isWeekend()) { - $key .= ' (substitute day)'; - $stPatricksDay = $stPatricksDay->next('monday'); - } - - return [$key => $stPatricksDay]; } - /** @return array */ - private function battleOfTheBoyne(int $year): array + /** @return array */ + protected function observedHolidays(int $year): array { - $battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London'); - $key = 'Battle of the Boyne (Orangemen\'s Day)'; - - if ($battleOfTheBoyne->isWeekend()) { - $key .= ' (substitute day)'; - $battleOfTheBoyne = $battleOfTheBoyne->next('monday'); + $holidays = [ + 'New Year\'s Day' => '01-01', + 'St Patrick\'s Day' => '03-17', + 'Battle of the Boyne (Orangemen\'s Day)' => '07-12', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; + + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name.' (substitute day)'] = $observedDay; + unset($holidays[$name]); + } } - return [$key => $battleOfTheBoyne]; - } - - /** @return array */ - protected function oneOffHolidays(int $year): array - { - return match ($year) { - 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), - ], - default => [], - }; + return $holidays; } } diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index f70145325..662c0ea06 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -12,84 +12,65 @@ public function countryCode(): string return 'gb-sct'; } - /** @return array */ - protected function secondOfJanuary(int $year): array + protected function allHolidays(int $year): array { - $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); - $secondOfJanuary = new CarbonImmutable($year.'-01-02', 'Europe/London'); - $key = '2nd January'; - - if ($newYearsDay->isFriday()) { - $key .= ' (substitute day)'; - $secondOfJanuary = $secondOfJanuary->next('monday'); - } - - if ($newYearsDay->isWeekend()) { - $key .= ' (substitute day)'; - $secondOfJanuary = $secondOfJanuary->next('tuesday'); - } - - return [$key => $secondOfJanuary]; + return array_merge( + $this->observedHolidays($year), + $this->earlyMayBankHoliday($year), + $this->variableHolidays($year), + $this->oneOffHolidays($year), + ); } - /** @return array */ - private function stAndrewsDay(int $year): array + /** @return array */ + protected function observedHolidays(int $year): array { - $stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London'); - $key = 'St Andrew\'s Day'; + $holidays = [ + 'New Year\'s Day' => '01-01', + '2nd January' => '01-02', + 'St Andrew\'s Day' => '11-30', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; - if ($stAndrewsDay->isWeekend()) { - $key .= ' (substitute day)'; - $stAndrewsDay = $stAndrewsDay->next('monday'); + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + '2nd January' => $this->secondOfJanuary($year), + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name.' (substitute day)'] = $observedDay; + unset($holidays[$name]); + } } - return [$key => $stAndrewsDay]; - } - - /** @return array */ - protected function oneOffHolidays(int $year): array - { - return match ($year) { - 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), - ], - default => [], - }; + return $holidays; } - /** @return array */ - protected function allHolidays(int $year): array + /** @return array */ + protected function variableHolidays(int $year): array { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->secondOfJanuary($year), - $this->earlyMayBankHoliday($year), - [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("first monday of august {$year}", 'Europe/London'), - ], - $this->stAndrewsDay($year), - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) - ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); + $easter = $this->easter($year); + return [ + 'Good Friday' => $easter->subDays(2), + 'Spring bank holiday' => 'last monday of may', + 'Summer bank holiday' => 'first monday of august', + ]; } - /** @return array */ - protected function variableHolidays(int $year): array + protected function secondOfJanuary(int $year): ?CarbonInterface { - $easterSunday = $this->easter($year); - - $goodFriday = $easterSunday->subDays(2); + $newYearsDay = (new CarbonImmutable($year.'-01-01'))->startOfDay(); + $secondOfJanuary = $newYearsDay->addDay(); - return [ - 'Good Friday' => $goodFriday, - ]; + return match ($newYearsDay->dayName) { + 'Friday' => $secondOfJanuary->next('monday'), + 'Saturday', 'Sunday' => $secondOfJanuary->next('tuesday'), + default => null, + }; } } From 073efe7e7da321faabab00585cbce4f4a528b679 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 9 Feb 2024 10:56:26 +0000 Subject: [PATCH 46/50] Fix styling --- src/Countries/Japan.php | 2 -- src/Countries/NorthernIreland.php | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index 3f00fdf29..879238b2b 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; - class Japan extends Country { public function countryCode(): string diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 1d3779dfb..0b6a7575c 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -2,7 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; use Carbon\CarbonInterface; class NorthernIreland extends Wales From df9d4d652487b9671a876f0c816a6eb8d1b3ebeb Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:11:30 +0100 Subject: [PATCH 47/50] use Observable trait where possible --- src/Concerns/Observable.php | 6 +++++- src/Countries/Jamaica.php | 12 +++++++----- src/Countries/Latvia.php | 28 +++++++++++++++++----------- src/Countries/SouthAfrica.php | 17 ++++------------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php index 52342c6fe..686c11b6d 100644 --- a/src/Concerns/Observable.php +++ b/src/Concerns/Observable.php @@ -43,8 +43,12 @@ protected function weekendToNextMonday(string|CarbonInterface $date, int $year): return null; } - protected function sundayToNextMonday(CarbonInterface $date): ?CarbonInterface + protected function sundayToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface { + if (is_string($date)) { + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + } + if ($date->isSunday()) { return $date->next('monday'); } diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index 801217120..96472e60f 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -4,9 +4,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class Jamaica extends Country { + use Observable; + public function countryCode(): string { return 'jm'; @@ -33,7 +36,10 @@ protected function fixedHolidays(int $year): array ]; foreach ($holidays as $name => $date) { - $observedDay = $this->observed($name, $date, $year); + $observedDay = match ($name) { + 'Labour Day', 'Boxing Day' => $this->observed($name, $date, $year), + default => $this->sundayToNextMonday($date, $year), + }; if ($observedDay) { $holidays[$name.' Observed'] = $observedDay; @@ -60,10 +66,6 @@ protected function observed(string $name, string $date, int $year): ?CarbonInter { $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - if ($holiday->isSunday()) { - return $holiday->next('monday'); - } - if ($name === 'Labour Day' && $holiday->isSaturday()) { return $holiday->next('monday'); } diff --git a/src/Countries/Latvia.php b/src/Countries/Latvia.php index fb26ede73..ff6ac9346 100644 --- a/src/Countries/Latvia.php +++ b/src/Countries/Latvia.php @@ -3,9 +3,12 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Observable; class Latvia extends Country { + use Observable; + public function countryCode(): string { return 'lv'; @@ -45,20 +48,23 @@ protected function variableHolidays(int $year): array /** @return array */ protected function observedHolidays(int $year): array { - // If the holidays - May 4 and November 18 - fall on a Saturday or Sunday, - // the next working day is designated as a holiday. - $holidays = []; + $holidays = [ + 'Latvijas Republikas Neatkarības deklarācijas pasludināšanas diena' => '05-04', + 'Latvijas Republikas proklamēšanas diena' => '11-18', + ]; - $date = new CarbonImmutable(); + foreach ($holidays as $name => $date) { + $observedDay = $this->weekendToNextMonday($date, $year); - $date = $date->setDate($year, 5, 4); - if ($date->isWeekend()) { - $holidays['Pārceltā 4. maija brīvdiena'] = $date->nextWeekday()->format('m-d'); - } + if ($observedDay) { + if ($name === 'Latvijas Republikas Neatkarības deklarācijas pasludināšanas diena') { + $holidays['Pārceltā 4. maija brīvdiena'] = $observedDay; + } - $date = $date->setDate($year, 11, 18); - if ($date->isWeekend()) { - $holidays['Pārceltā 18. novembra brīvdiena'] = $date->nextWeekday()->format('m-d'); + if ($name === 'Latvijas Republikas proklamēšanas diena') { + $holidays['Pārceltā 18. novembra brīvdiena'] = $observedDay; + } + } } return $holidays; diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index f85b14255..8ef21ac51 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -4,9 +4,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class SouthAfrica extends Country { + use Observable; + public function countryCode(): string { return 'za'; @@ -30,7 +33,7 @@ protected function allHolidays(int $year): array ]; foreach ($holidays as $name => $date) { - $observedDay = $this->observed($date, $year); + $observedDay = $this->sundayToNextMonday($date, $year); if ($observedDay) { $holidays[$name.' Observed'] = $observedDay; @@ -50,16 +53,4 @@ protected function variableHolidays(int $year): array 'Family Day' => $easter->addDay(), ]; } - - protected function observed(string $date, int $year): ?CarbonInterface - { - $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - - // https://www.gov.za/documents/public-holidays-act - if ($holiday->isSunday()) { - return $holiday->next('monday'); - } - - return null; - } } From 6a2c268abacbd72d881d60edf3b7af0071444b14 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 9 Feb 2024 12:12:26 +0000 Subject: [PATCH 48/50] Fix styling --- src/Countries/SouthAfrica.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index 8ef21ac51..81cf73979 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use Carbon\CarbonInterface; use Spatie\Holidays\Concerns\Observable; class SouthAfrica extends Country From 289a130ef6c9b1173ba25ce8088261b9be308c53 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:14:03 +0100 Subject: [PATCH 49/50] reorganise --- src/Concerns/Observable.php | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php index 686c11b6d..aa7254ff7 100644 --- a/src/Concerns/Observable.php +++ b/src/Concerns/Observable.php @@ -7,29 +7,6 @@ trait Observable { - protected function observedChristmasDay(int $year): ?CarbonInterface - { - $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); - - return match ($christmasDay->dayName) { - 'Saturday' => $christmasDay->next('monday'), - 'Sunday' => $christmasDay->next('tuesday'), - default => null, - }; - } - - protected function observedBoxingDay(int $year): ?CarbonInterface - { - $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); - $boxingDay = $christmasDay->addDay(); - - return match ($christmasDay->dayName) { - 'Friday' => $boxingDay->next('monday'), - 'Saturday' => $boxingDay->next('tuesday'), - default => null, - }; - } - protected function weekendToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface { if (is_string($date)) { @@ -55,4 +32,27 @@ protected function sundayToNextMonday(string|CarbonInterface $date, int $year): return null; } + + protected function observedChristmasDay(int $year): ?CarbonInterface + { + $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); + + return match ($christmasDay->dayName) { + 'Saturday' => $christmasDay->next('monday'), + 'Sunday' => $christmasDay->next('tuesday'), + default => null, + }; + } + + protected function observedBoxingDay(int $year): ?CarbonInterface + { + $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); + $boxingDay = $christmasDay->addDay(); + + return match ($christmasDay->dayName) { + 'Friday' => $boxingDay->next('monday'), + 'Saturday' => $boxingDay->next('tuesday'), + default => null, + }; + } } From 8bea6acc3cc50f12617f0c1b612efe6aed486244 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:28:00 +0100 Subject: [PATCH 50/50] use unique name for carbon on ci --- .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 80a2047bf..e12602421 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,7 +14,7 @@ jobs: stability: [prefer-lowest, prefer-stable] carbon: [2.72, 3.0] - name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} - Carbon ${{ matrix.carbon }} steps: - name: Checkout code