From 968f48390ed19382275a1abeb052910df0e3e2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20Filipic=CC=8C?= Date: Wed, 17 Jan 2024 23:08:16 +0100 Subject: [PATCH 01/95] Slovenian holidays --- src/Countries/Slovenia.php | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Countries/Slovenia.php diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php new file mode 100644 index 00000000..d4e434ee --- /dev/null +++ b/src/Countries/Slovenia.php @@ -0,0 +1,43 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Novo leto' => '01-01', // New Year's Day + 'Novo leto 2' => '02-01', // New Year's Day, yes it's a second day + 'Prešernov dan, slovenski kulturni praznik' => '08-02', // Prešeren Day, Slovenian Cultural Holiday + 'Dan upora proti okupatorju' => '04-27', // Day of Uprising Against Occupation + 'Praznik dela' => '05-01', // Labour Day + 'Praznik dela 2' => '05-02', // Labour Day, yes it's a second day + 'Dan državnosti' => '06-25', // Statehood Day + 'Marijino vnebovzetje' => '08-15', // Assumption of Mary + 'Dan reformacije' => '10-31', // Reformation Day + 'Dan spomina na mrtve' => '11-01', // Remembrance Day + 'Božič' => '12-25', // Christmas Day + 'Dan samostojnosti in enotnosti' => '12-26', // Independence and Unity Day + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Ljubljana'); + + return [ + 'Velikonočni ponedeljek' => $easter->addDay(1), // Easter Monday + ]; + } +} From a01e1323334b875075ca189081fd9bf9c5e9894a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20Filipic=CC=8C?= Date: Wed, 17 Jan 2024 23:22:13 +0100 Subject: [PATCH 02/95] Slovenian holidays tests --- .../it_can_calculate_slovenian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/SloveniaTest.php | 18 +++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap create mode 100644 tests/Countries/SloveniaTest.php diff --git a/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap b/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap new file mode 100644 index 00000000..9645cd6a --- /dev/null +++ b/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Novo leto", + "date": "2024-01-01" + }, + { + "name": "Novo leto 2", + "date": "2024-02-01" + }, + { + "name": "Velikono\u010dni ponedeljek", + "date": "2024-04-01" + }, + { + "name": "Dan upora proti okupatorju", + "date": "2024-04-27" + }, + { + "name": "Praznik dela", + "date": "2024-05-01" + }, + { + "name": "Praznik dela 2", + "date": "2024-05-02" + }, + { + "name": "Dan dr\u017eavnosti", + "date": "2024-06-25" + }, + { + "name": "Pre\u0161ernov dan, slovenski kulturni praznik", + "date": "2024-08-02" + }, + { + "name": "Marijino vnebovzetje", + "date": "2024-08-15" + }, + { + "name": "Dan reformacije", + "date": "2024-10-31" + }, + { + "name": "Dan spomina na mrtve", + "date": "2024-11-01" + }, + { + "name": "Bo\u017ei\u010d", + "date": "2024-12-25" + }, + { + "name": "Dan samostojnosti in enotnosti", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/SloveniaTest.php b/tests/Countries/SloveniaTest.php new file mode 100644 index 00000000..d1231906 --- /dev/null +++ b/tests/Countries/SloveniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 587e5dc08d989d7ff8307f5696a92fcc0ae06005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20Filipic=CC=8C?= Date: Thu, 18 Jan 2024 10:03:34 +0100 Subject: [PATCH 03/95] Mistyped second new year date. --- src/Countries/Slovenia.php | 2 +- .../SloveniaTest/it_can_calculate_slovenian_holidays.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php index d4e434ee..788c4d7d 100644 --- a/src/Countries/Slovenia.php +++ b/src/Countries/Slovenia.php @@ -16,7 +16,7 @@ protected function allHolidays(int $year): array { return array_merge([ 'Novo leto' => '01-01', // New Year's Day - 'Novo leto 2' => '02-01', // New Year's Day, yes it's a second day + 'Novo leto 2' => '01-02', // New Year's Day, yes it's a second day 'Prešernov dan, slovenski kulturni praznik' => '08-02', // Prešeren Day, Slovenian Cultural Holiday 'Dan upora proti okupatorju' => '04-27', // Day of Uprising Against Occupation 'Praznik dela' => '05-01', // Labour Day diff --git a/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap b/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap index 9645cd6a..b869f39b 100644 --- a/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap +++ b/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Novo leto 2", - "date": "2024-02-01" + "date": "2024-01-02" }, { "name": "Velikono\u010dni ponedeljek", From 76410782e694e8caa1acce44efbcd934fd7b9ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20Filipic=CC=8C?= Date: Thu, 18 Jan 2024 23:07:21 +0100 Subject: [PATCH 04/95] Method call is provided 1 parameters, but the method signature uses 0 parameters fixed --- src/Countries/Slovenia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php index 788c4d7d..98e7ac84 100644 --- a/src/Countries/Slovenia.php +++ b/src/Countries/Slovenia.php @@ -37,7 +37,7 @@ protected function variableHolidays(int $year): array ->setTimezone('Europe/Ljubljana'); return [ - 'Velikonočni ponedeljek' => $easter->addDay(1), // Easter Monday + 'Velikonočni ponedeljek' => $easter->addDay(), // Easter Monday ]; } } From d3a6abc6531665193352258c1e98c771cbf70971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20Filipic=CC=8C?= Date: Thu, 18 Jan 2024 23:09:25 +0100 Subject: [PATCH 05/95] Method call is provided 1 parameter, but the method signature uses 0 parameters fixed --- src/Countries/Slovenia.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php index 98e7ac84..d84fff3d 100644 --- a/src/Countries/Slovenia.php +++ b/src/Countries/Slovenia.php @@ -14,7 +14,8 @@ public function countryCode(): string /** @return array */ protected function allHolidays(int $year): array { - return array_merge([ + + return array_merge([ 'Novo leto' => '01-01', // New Year's Day 'Novo leto 2' => '01-02', // New Year's Day, yes it's a second day 'Prešernov dan, slovenski kulturni praznik' => '08-02', // Prešeren Day, Slovenian Cultural Holiday From 6e799102f262ef3fec23254e37518150861f66e4 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Thu, 18 Jan 2024 16:52:47 +0100 Subject: [PATCH 06/95] make tests faster --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 14315473..ee8a13ea 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] php: [8.3, 8.2, 8.1] stability: [prefer-lowest, prefer-stable] From d0598ae99e2cc7ca909d5a86893eda660e225acb Mon Sep 17 00:00:00 2001 From: BurtDS Date: Wed, 17 Jan 2024 21:12:54 +0100 Subject: [PATCH 07/95] Add Andorra Holidays --- src/Countries/Andorra.php | 43 +++++++++++++++ .../it_can_calculate_andorra_holidays.snap | 54 +++++++++++++++++++ tests/Countries/AndorraTest.php | 18 +++++++ 3 files changed, 115 insertions(+) create mode 100644 src/Countries/Andorra.php create mode 100644 tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap create mode 100644 tests/Countries/AndorraTest.php diff --git a/src/Countries/Andorra.php b/src/Countries/Andorra.php new file mode 100644 index 00000000..19e342ca --- /dev/null +++ b/src/Countries/Andorra.php @@ -0,0 +1,43 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Any nou' => '01-01', + 'Reis' => '01-06', + 'Dia de la Constitució' => '03-14', + 'Festa del Treball' => '05-01', + 'Assumpció' => '08-15', + 'Mare de Déu de Meritxell' => '09-08', + 'Tots Sants' => '11-01', + 'Immaculada Concepció' => '11-08', + 'Nadal' => '12-25', + 'Sant Esteve' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Brussels'); + + return [ + 'Divendres Sant' => $easter->subDays(2), + 'Dilluns de Pasqua' => $easter->addDay(), + 'Dilluns de Pentecosta' => $easter->addDays(50), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap b/tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap new file mode 100644 index 00000000..b46fb624 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AndorraTest/it_can_calculate_andorra_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Any nou", + "date": "2024-01-01" + }, + { + "name": "Reis", + "date": "2024-01-06" + }, + { + "name": "Dia de la Constituci\u00f3", + "date": "2024-03-14" + }, + { + "name": "Divendres Sant", + "date": "2024-03-29" + }, + { + "name": "Dilluns de Pasqua", + "date": "2024-04-01" + }, + { + "name": "Festa del Treball", + "date": "2024-05-01" + }, + { + "name": "Dilluns de Pentecosta", + "date": "2024-05-20" + }, + { + "name": "Assumpci\u00f3", + "date": "2024-08-15" + }, + { + "name": "Mare de D\u00e9u de Meritxell", + "date": "2024-09-08" + }, + { + "name": "Tots Sants", + "date": "2024-11-01" + }, + { + "name": "Immaculada Concepci\u00f3", + "date": "2024-11-08" + }, + { + "name": "Nadal", + "date": "2024-12-25" + }, + { + "name": "Sant Esteve", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/AndorraTest.php b/tests/Countries/AndorraTest.php new file mode 100644 index 00000000..6ab6d869 --- /dev/null +++ b/tests/Countries/AndorraTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); \ No newline at end of file From d5cf084a572145ae1f35e41210d14975d8e41cad Mon Sep 17 00:00:00 2001 From: freekmurze Date: Wed, 17 Jan 2024 22:49:55 +0000 Subject: [PATCH 08/95] Fix styling --- tests/Countries/AndorraTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Countries/AndorraTest.php b/tests/Countries/AndorraTest.php index 6ab6d869..43f1c49c 100644 --- a/tests/Countries/AndorraTest.php +++ b/tests/Countries/AndorraTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); \ No newline at end of file +}); From ed0c3877325ce2f2d09c8039710d04a28b6ad6cd Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:38:15 +0100 Subject: [PATCH 09/95] add docs for contributing + add example for regions --- README.md | 45 ++++++++++++---- src/Countries/Austria.php | 5 ++ src/Countries/Country.php | 2 +- ...ustrian_holidays_with_region_holidays.snap | 54 +++++++++++++++++++ tests/Countries/AustriaTest.php | 13 +++++ 5 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap diff --git a/README.md b/README.md index 12f5b0ff..e41ea2ff 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ use Spatie\Holidays\Holidays; // returns an array of Belgian holidays // for the current year -$holidays = Holidays::for('be')->get(); +$holidays = Holidays::for('be')->get(); ``` ## Support us @@ -40,21 +40,22 @@ You can get all holidays for a country by using the `get` method. ```php use Spatie\Holidays\Holidays; +use Spatie\Holidays\Countries\Belgium; // returns an array of Belgian holidays // for the current year -$holidays = Holidays::for('be')->get(); +$holidays = Holidays::for(Belgium::make())->get(); ``` -Alternatively, you could also pass an instance of `Country` to the `for` method. +Alternatively, you could also pass an ISO code to the `for` method. +But region specific holidays will not be included. ```php use Spatie\Holidays\Holidays; -use Spatie\Holidays\Countries\Belgium; // returns an array of Belgian holidays // for the current year -$holidays = Holidays::for(Belgium::make())->get(); +$holidays = Holidays::for('be')->get(); ``` ### Getting holidays for a specific year @@ -87,6 +88,36 @@ use Spatie\Holidays\Holidays; Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar ``` +## Contributing a new country + +If you want to add a new country, you can create a pull request. + +1. Create a new class in the `Countries` directory. It should extend the `Country` class. +2. Add a test for the new country in the `tests` directory. + +In case your country has specific rules for calculating holidays, +for example region specific holidays, you can pass this to the constructor of your country class. + +```php +$holidays = Holidays::for(Austria::make('de-bw'))->get(); + +class Austria extends Country +{ + protected function __construct( + protected ?string $region = null, + ) { + } + + protected function allHolidays(int $year): array + { + // Here you can use $this->region (or other variables) to calculate holidays + } +``` + +Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for more details. + + + ## Testing ```bash @@ -97,10 +128,6 @@ composer test Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. -## Contributing - -Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. - ## Security Vulnerabilities Please review [our security policy](../../security/policy) on how to report security vulnerabilities. diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index c8eea5d6..b03a22e5 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -6,6 +6,11 @@ class Austria extends Country { + protected function __construct( + public ?string $region = null + ) { + } + public function countryCode(): string { return 'at'; diff --git a/src/Countries/Country.php b/src/Countries/Country.php index b99262a5..2c875aa7 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -37,7 +37,7 @@ public function get(int $year): array public static function make(): static { - return new static(); + return new static(...func_get_args()); } public static function find(string $countryCode): ?Country diff --git a/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap b/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap new file mode 100644 index 00000000..67cda42e --- /dev/null +++ b/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Heilige Drei K\u00f6nige", + "date": "2024-01-06" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Staatsfeiertag", + "date": "2024-05-01" + }, + { + "name": "Christi Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Fronleichnam", + "date": "2024-05-30" + }, + { + "name": "Mari\u00e4 Himmelfahrt", + "date": "2024-08-15" + }, + { + "name": "Nationalfeiertag", + "date": "2024-10-26" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "Mari\u00e4 Empf\u00e4ngnis", + "date": "2024-12-08" + }, + { + "name": "Christtag", + "date": "2024-12-25" + }, + { + "name": "Stefanitag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 9018307f..3473abef 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Countries\Austria; use Spatie\Holidays\Holidays; it('can calculate austrian holidays', function () { @@ -16,3 +17,15 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('can calculate austrian holidays with region holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(Austria::make('bg'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +})->skip('Austria class has to be extended with regions first.'); From 5d46b08dac91cd06012649e75cf02fd2bcbbad01 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:49:17 +0100 Subject: [PATCH 10/95] remove skipped test --- ...ustrian_holidays_with_region_holidays.snap | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap diff --git a/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap b/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap deleted file mode 100644 index 67cda42e..00000000 --- a/tests/.pest/snapshots/Countries/AustriaTest/it_can_calculate_austrian_holidays_with_region_holidays.snap +++ /dev/null @@ -1,54 +0,0 @@ -[ - { - "name": "Neujahr", - "date": "2024-01-01" - }, - { - "name": "Heilige Drei K\u00f6nige", - "date": "2024-01-06" - }, - { - "name": "Ostermontag", - "date": "2024-04-01" - }, - { - "name": "Staatsfeiertag", - "date": "2024-05-01" - }, - { - "name": "Christi Himmelfahrt", - "date": "2024-05-09" - }, - { - "name": "Pfingstmontag", - "date": "2024-05-20" - }, - { - "name": "Fronleichnam", - "date": "2024-05-30" - }, - { - "name": "Mari\u00e4 Himmelfahrt", - "date": "2024-08-15" - }, - { - "name": "Nationalfeiertag", - "date": "2024-10-26" - }, - { - "name": "Allerheiligen", - "date": "2024-11-01" - }, - { - "name": "Mari\u00e4 Empf\u00e4ngnis", - "date": "2024-12-08" - }, - { - "name": "Christtag", - "date": "2024-12-25" - }, - { - "name": "Stefanitag", - "date": "2024-12-26" - } -] \ No newline at end of file From 52ebbeff8f6116fb65d5051472a14d0308b33717 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:55:07 +0100 Subject: [PATCH 11/95] edit readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e41ea2ff..09dec13f 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,9 @@ for example region specific holidays, you can pass this to the constructor of yo ```php $holidays = Holidays::for(Austria::make('de-bw'))->get(); +``` +```php class Austria extends Country { protected function __construct( From 977717e8257e124952328e94f67b6c3e6b8d5112 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Thu, 18 Jan 2024 11:00:05 +0100 Subject: [PATCH 12/95] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 09dec13f..479ae549 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,6 @@ $holidays = Holidays::for(Belgium::make())->get(); ``` Alternatively, you could also pass an ISO code to the `for` method. -But region specific holidays will not be included. ```php use Spatie\Holidays\Holidays; @@ -94,14 +93,18 @@ If you want to add a new country, you can create a pull request. 1. Create a new class in the `Countries` directory. It should extend the `Country` class. 2. Add a test for the new country in the `tests` directory. +3. Run the tests so a snapshot gets created. +4. Verify the result in the newly created snapshot is correct. In case your country has specific rules for calculating holidays, for example region specific holidays, you can pass this to the constructor of your country class. ```php -$holidays = Holidays::for(Austria::make('de-bw'))->get(); +$holidays = Holidays::for(Austria::make(region: 'de-bw'))->get(); ``` +The value, `de-bw`, will be passed the region parameter of the contructor of a country. + ```php class Austria extends Country { @@ -118,8 +121,6 @@ class Austria extends Country Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for more details. - - ## Testing ```bash From ccbe257d4fd0d43e37bd022c90349f6a140103af Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:05:56 +0100 Subject: [PATCH 13/95] fixes for phpstan --- phpstan-baseline.neon | 17 ++++++----------- src/Countries/Andorra.php | 1 - src/Countries/Austria.php | 3 +-- src/Countries/Belgium.php | 1 - src/Countries/Brazil.php | 1 - src/Countries/Country.php | 2 +- src/Countries/Hungary.php | 1 - src/Countries/Netherlands.php | 1 - 8 files changed, 8 insertions(+), 19 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 40f94f7e..1d1a8ab5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,17 +1,12 @@ parameters: ignoreErrors: - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Belgium\\:\\:allHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Belgium.php - - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 path: src/Countries/Country.php - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\ but returns array\\\\.$#" + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\ but returns array\\\\.$#" count: 1 path: src/Countries/Country.php @@ -20,11 +15,6 @@ parameters: count: 1 path: src/Countries/Country.php - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Hungary\\:\\:allHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Hungary.php - - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 @@ -44,3 +34,8 @@ parameters: message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Carbon\\\\CarbonImmutable\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#" count: 1 path: src/Holidays.php + + - + message: "#^Property Spatie\\\\Holidays\\\\Holidays\\:\\:\\$holidays \\(array\\\\) does not accept array\\\\.$#" + count: 1 + path: src/Holidays.php diff --git a/src/Countries/Andorra.php b/src/Countries/Andorra.php index 19e342ca..51615e69 100644 --- a/src/Countries/Andorra.php +++ b/src/Countries/Andorra.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'ad'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index b03a22e5..73fb6128 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -16,7 +16,6 @@ public function countryCode(): string return 'at'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -39,7 +38,7 @@ protected function variableHolidays(int $year): array ->setTimezone('Europe/Vienna'); return [ - 'Ostermontag' => $easter->addDay(1), + 'Ostermontag' => $easter->addDay(), 'Christi Himmelfahrt' => $easter->addDays(39), 'Pfingstmontag' => $easter->addDays(50), 'Fronleichnam' => $easter->addDays(60), diff --git a/src/Countries/Belgium.php b/src/Countries/Belgium.php index f5d268db..af52b681 100644 --- a/src/Countries/Belgium.php +++ b/src/Countries/Belgium.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'be'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index 4c93f100..479d7836 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'br'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 2c875aa7..8b75b8df 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -13,7 +13,7 @@ abstract public function countryCode(): string; /** @return array */ abstract protected function allHolidays(int $year): array; - /** @return array */ + /** @return array */ public function get(int $year): array { $this->ensureYearCanBeCalculated($year); diff --git a/src/Countries/Hungary.php b/src/Countries/Hungary.php index 8a646745..15a46e99 100644 --- a/src/Countries/Hungary.php +++ b/src/Countries/Hungary.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'hu'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index c79223dd..427c670d 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'nl'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From a882bca0180e1085093d6f68c3cbcc1466bd0d2f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:10:05 +0100 Subject: [PATCH 14/95] ci changes --- .github/workflows/phpstan.yml | 2 +- .github/workflows/run-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 60ce66b6..e171b046 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,6 +1,6 @@ name: PHPStan -on: [push] +on: [push, pull_request] jobs: phpstan: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ee8a13ea..6a56069f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -4,7 +4,7 @@ on: push: paths: - '**.php' - - '.github/workflows/run-tests-pest.yml' + - '.github/workflows/run-tests.yml' - 'phpunit.xml.dist' - 'composer.json' - 'composer.lock' From 7b1b2ee449facfe1e03eaad4576f665c1fc4621c Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:14:59 +0100 Subject: [PATCH 15/95] run ci for every PR --- .github/workflows/fix-php-code-style-issues.yml | 5 +---- .github/workflows/run-tests.yml | 9 +-------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index cd4239c2..30e62c77 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -1,9 +1,6 @@ name: Fix PHP code style issues -on: - push: - paths: - - '**.php' +on: [push] permissions: contents: write diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6a56069f..780a7442 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,13 +1,6 @@ name: Tests -on: - push: - paths: - - '**.php' - - '.github/workflows/run-tests.yml' - - 'phpunit.xml.dist' - - 'composer.json' - - 'composer.lock' +on: [push, pull_request] jobs: test: From b092aa9334eab2dfacfb1b659c0aa0fad003ca70 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:17:03 +0100 Subject: [PATCH 16/95] skip Brazil implementation returned bad dates --- src/Countries/Brazil.php | 2 ++ tests/Countries/BrazilTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index 479d7836..19b9af7a 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -13,6 +13,8 @@ public function countryCode(): string protected function allHolidays(int $year): array { + throw new \Exception('Not implemented yet.'); + return array_merge([ 'Dia de Ano Novo' => '01-01', 'Dia de Tiradentes' => '04-21', diff --git a/tests/Countries/BrazilTest.php b/tests/Countries/BrazilTest.php index 91be74d4..a91509ff 100644 --- a/tests/Countries/BrazilTest.php +++ b/tests/Countries/BrazilTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); +})->skip('Still an issue'); From 157666d6adac185f00b585ff1b480219de44c0e3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 11:19:43 +0100 Subject: [PATCH 17/95] ignore issue --- phpstan-baseline.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1d1a8ab5..51b9330f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: src/Countries/Brazil.php + - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 From 7502ee70d8d0c59a002e3f6669cad803d3354647 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:08:40 +0100 Subject: [PATCH 18/95] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 479ae549..44af97b7 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ for example region specific holidays, you can pass this to the constructor of yo $holidays = Holidays::for(Austria::make(region: 'de-bw'))->get(); ``` -The value, `de-bw`, will be passed the region parameter of the contructor of a country. +The value, `de-bw`, will be passed to the region parameter of the contructor of a country. ```php class Austria extends Country From 04a5a2ecbe6f5cbe64bbd06df72c6f0b0d10e90d Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:42:45 +0100 Subject: [PATCH 19/95] Added Danish holidays. --- src/Countries/Denmark.php | 39 +++++++++++++++++++++++++++++++++++++++ tests/DenmarkTest.php | 18 ++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/Countries/Denmark.php create mode 100644 tests/DenmarkTest.php diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php new file mode 100644 index 00000000..e1d62510 --- /dev/null +++ b/src/Countries/Denmark.php @@ -0,0 +1,39 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Nytår' => '01-01', + 'Juleaften' => '24-12', + 'Juledag' => '25-12', + 'Anden Juledag' => '26-12' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Copenhagen'); + + return [ + 'Påskedag' => $easter->addDay(), + 'Anden påskedag' => $easter->addDays(2), + 'Kristi Himmelfartsdag' => $easter->addDays(39), + 'Pinse' => $easter->addDays(49), + 'Anden pisedag' => $easter->addDays(50), + ]; + } +} diff --git a/tests/DenmarkTest.php b/tests/DenmarkTest.php new file mode 100644 index 00000000..dc01757c --- /dev/null +++ b/tests/DenmarkTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From eb167fbdd7f788cd24f9bdeb745e3683bb0abae1 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:49:40 +0100 Subject: [PATCH 20/95] Added missing holidays. --- src/Countries/Denmark.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index e1d62510..152bf229 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -30,6 +30,8 @@ protected function variableHolidays(int $year): array return [ 'Påskedag' => $easter->addDay(), + 'Skærtorsdag' => $easter->subDays(3), + 'Langfredag' => $easter->subDays(2), 'Anden påskedag' => $easter->addDays(2), 'Kristi Himmelfartsdag' => $easter->addDays(39), 'Pinse' => $easter->addDays(49), From 6e254c942291324deb368ff136fee5e4bc0e6820 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:58:16 +0100 Subject: [PATCH 21/95] Fixed spelling mistake. --- src/Countries/Denmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 152bf229..0852bfeb 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -32,10 +32,10 @@ protected function variableHolidays(int $year): array 'Påskedag' => $easter->addDay(), 'Skærtorsdag' => $easter->subDays(3), 'Langfredag' => $easter->subDays(2), - 'Anden påskedag' => $easter->addDays(2), + 'Anden Påskedag' => $easter->addDays(2), 'Kristi Himmelfartsdag' => $easter->addDays(39), 'Pinse' => $easter->addDays(49), - 'Anden pisedag' => $easter->addDays(50), + 'Anden Pinsedag' => $easter->addDays(50), ]; } } From 8f3ac5e26925668feac718d7fdc525655eeeebba Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 15:02:15 +0100 Subject: [PATCH 22/95] Added generated snapshot. --- .../it_can_calculate_danish_holidays.snap | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap diff --git a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap new file mode 100644 index 00000000..7fa897a9 --- /dev/null +++ b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Nyt\u00e5r", + "date": "2024-01-01" + }, + { + "name": "Sk\u00e6rtorsdag", + "date": "2024-03-28" + }, + { + "name": "Langfredag", + "date": "2024-03-29" + }, + { + "name": "P\u00e5skedag", + "date": "2024-04-01" + }, + { + "name": "Anden P\u00e5skedag", + "date": "2024-04-02" + }, + { + "name": "Kristi Himmelfartsdag", + "date": "2024-05-09" + }, + { + "name": "Pinse", + "date": "2024-05-19" + }, + { + "name": "Anden Pinsedag", + "date": "2024-05-20" + }, + { + "name": "Juleaften", + "date": "2025-12-12" + }, + { + "name": "Juledag", + "date": "2026-01-12" + }, + { + "name": "Anden Juledag", + "date": "2026-02-12" + } +] \ No newline at end of file From 6ebb998277ee0b7302b221ce1a6813e080eb9caa Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 18 Jan 2024 09:15:59 +0100 Subject: [PATCH 23/95] Fixed errors regarding the order of day/month and took into account that Great Prayer Day is no longer a public holiday in 2024. --- src/Countries/Denmark.php | 14 ++++++++++---- .../it_can_calculate_danish_holidays.snap | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 0852bfeb..3c8a6976 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -16,9 +16,9 @@ protected function allHolidays(int $year): array { return array_merge([ 'Nytår' => '01-01', - 'Juleaften' => '24-12', - 'Juledag' => '25-12', - 'Anden Juledag' => '26-12' + 'Juleaften' => '12-24', + 'Juledag' => '12-25', + 'Anden Juledag' => '12-26' ], $this->variableHolidays($year)); } @@ -28,7 +28,7 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Europe/Copenhagen'); - return [ + $holidays = [ 'Påskedag' => $easter->addDay(), 'Skærtorsdag' => $easter->subDays(3), 'Langfredag' => $easter->subDays(2), @@ -37,5 +37,11 @@ protected function variableHolidays(int $year): array 'Pinse' => $easter->addDays(49), 'Anden Pinsedag' => $easter->addDays(50), ]; + + if ($year < 2024) { + $holidays['Store Bededag'] = $easter->addDays(26); + } + + return $holidays; } } diff --git a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap index 7fa897a9..b19f23c2 100644 --- a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap +++ b/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap @@ -33,14 +33,14 @@ }, { "name": "Juleaften", - "date": "2025-12-12" + "date": "2024-12-24" }, { "name": "Juledag", - "date": "2026-01-12" + "date": "2024-12-25" }, { "name": "Anden Juledag", - "date": "2026-02-12" + "date": "2024-12-26" } ] \ No newline at end of file From f509cbc97fd1c7936b170f4b70e847d7b28d94ed Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 18 Jan 2024 09:24:01 +0100 Subject: [PATCH 24/95] Moved test to correct folder. --- .../DenmarkTest/it_can_calculate_danish_holidays.snap | 0 tests/{ => Countries}/DenmarkTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/.pest/snapshots/{ => Countries}/DenmarkTest/it_can_calculate_danish_holidays.snap (100%) rename tests/{ => Countries}/DenmarkTest.php (100%) diff --git a/tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap similarity index 100% rename from tests/.pest/snapshots/DenmarkTest/it_can_calculate_danish_holidays.snap rename to tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap diff --git a/tests/DenmarkTest.php b/tests/Countries/DenmarkTest.php similarity index 100% rename from tests/DenmarkTest.php rename to tests/Countries/DenmarkTest.php From 14ddf2326c0c6b076fb06d0016610a8b42096358 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 18 Jan 2024 11:15:02 +0000 Subject: [PATCH 25/95] Fix styling --- src/Countries/Denmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 3c8a6976..4e7ef6f7 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -18,7 +18,7 @@ protected function allHolidays(int $year): array 'Nytår' => '01-01', 'Juleaften' => '12-24', 'Juledag' => '12-25', - 'Anden Juledag' => '12-26' + 'Anden Juledag' => '12-26', ], $this->variableHolidays($year)); } From c8983398a8a1efb91fbb9a59f55cf6db717df5e3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:15:11 +0100 Subject: [PATCH 26/95] remove annotation --- src/Countries/Denmark.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 4e7ef6f7..66d2113a 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'da'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 36b04bebb2f686ec4c2ddc6f58995a13dca5e9f1 Mon Sep 17 00:00:00 2001 From: AJ <60591772+devajmeireles@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:18:35 -0300 Subject: [PATCH 27/95] introducing playground --- composer.json | 4 +++- playground.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 playground.php diff --git a/composer.json b/composer.json index aa1da046..91002ed8 100644 --- a/composer.json +++ b/composer.json @@ -25,9 +25,11 @@ "ext-calendar": "*" }, "require-dev": { + "laravel/prompts": "^0.1.15", "pestphp/pest": "^2.31", "phpstan/phpstan": "^1.10.56", - "spatie/ray": "^1.40.1" + "spatie/ray": "^1.40.1", + "symfony/var-dumper": "^6.4" }, "autoload": { "psr-4": { diff --git a/playground.php b/playground.php new file mode 100644 index 00000000..16d5e472 --- /dev/null +++ b/playground.php @@ -0,0 +1,30 @@ +get()) + ->map(fn (array $holiday) => [ + 'name' => $holiday['name'], + 'date' => $holiday['date']->format('Y-m-d'), // @phpstan-ignore-line + ])->toArray(); + +dd($result); From 922a3f2076c5aff94fa6761ef03f20878007f9fd Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 18 Jan 2024 12:49:50 +0000 Subject: [PATCH 28/95] Fix styling --- playground.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/playground.php b/playground.php index 16d5e472..c53856a2 100644 --- a/playground.php +++ b/playground.php @@ -2,14 +2,15 @@ use Spatie\Holidays\Countries\Country; use Spatie\Holidays\Holidays; + use function Laravel\Prompts\select; -require __DIR__ . '/vendor/autoload.php'; +require __DIR__.'/vendor/autoload.php'; $countries = []; foreach (glob(__DIR__.'/src/Countries/*.php') as $filename) { // @phpstan-ignore-line - $countryClass = '\\Spatie\\Holidays\\Countries\\' . basename($filename, '.php'); + $countryClass = '\\Spatie\\Holidays\\Countries\\'.basename($filename, '.php'); if (basename($filename) === 'Country.php') { continue; From 49d0ee6b59ef4d28a254bcb493fa534d61c5cf93 Mon Sep 17 00:00:00 2001 From: Rick de Boer Date: Thu, 18 Jan 2024 08:51:32 +0100 Subject: [PATCH 29/95] Update Netherlands.php --- src/Countries/Netherlands.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index 427c670d..b694c25c 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -18,7 +18,6 @@ protected function allHolidays(int $year): array 'Bevrijdingsdag' => '05-05', '1e Kerstdag' => '12-25', '2e Kerstdag' => '12-26', - 'Oudejaarsdag' => '12-31', ], $this->variableHolidays($year)); } From 37c5e6e3cfd165864650c9172fd7d4ff1bae59a3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 15:15:22 +0100 Subject: [PATCH 30/95] update nl snapshot --- .../NetherlandsTest/it_can_calculate_dutch_holidays.snap | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap b/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap index 3257dd42..7ba840be 100644 --- a/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap +++ b/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap @@ -42,9 +42,5 @@ { "name": "2e Kerstdag", "date": "2024-12-26" - }, - { - "name": "Oudejaarsdag", - "date": "2024-12-31" } ] \ No newline at end of file From e7ef9482219e71762e3c56345107cb37268d0a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Wed, 17 Jan 2024 14:19:56 +0000 Subject: [PATCH 31/95] Added portuguese holidays --- src/Countries/Portugal.php | 44 ++++++++++++++ .../it_can_calculate_portuguese_holidays.snap | 58 +++++++++++++++++++ tests/Countries/PortugalTest.php | 19 ++++++ 3 files changed, 121 insertions(+) create mode 100644 src/Countries/Portugal.php create mode 100644 tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap create mode 100644 tests/Countries/PortugalTest.php diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php new file mode 100644 index 00000000..65f87ab5 --- /dev/null +++ b/src/Countries/Portugal.php @@ -0,0 +1,44 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Dia de Ano Novo' => '01-01', + 'Dia da Liberdade' => '04-25', + 'Dia do Trabalhador' => '05-01', + 'Dia do Portugal' => '06-10', + 'Assunção da Nossa Senhora' => '08-15', + 'Implantação da República' => '10-05', + 'Dia de Todos os Santos' => '11-01', + 'Restauração da Independência' => '12-01', + 'Imaculada Conceição' => '12-08', + 'Natal' => '12-25' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Brussels'); + + return [ + 'Páscoa' => $easter, + 'Carnaval' => $easter->subDays(47), + 'Sexta-feira Santa' => $easter->subDays(2), + 'Corpo de Deus' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap new file mode 100644 index 00000000..7e409c71 --- /dev/null +++ b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "Dia de Ano Novo", + "date": "2024-01-01" + }, + { + "name": "Carnaval", + "date": "2024-02-13" + }, + { + "name": "Sexta-feira Santa", + "date": "2024-03-29" + }, + { + "name": "P\u00e1scoa", + "date": "2024-03-31" + }, + { + "name": "Dia da Liberdade", + "date": "2024-04-25" + }, + { + "name": "Dia do Trabalhador", + "date": "2024-05-01" + }, + { + "name": "Corpo de Deus", + "date": "2024-05-30" + }, + { + "name": "Dia do Portugal", + "date": "2024-06-10" + }, + { + "name": "Assun\u00e7\u00e3o da Nossa Senhora", + "date": "2024-08-15" + }, + { + "name": "Implanta\u00e7\u00e3o da Rep\u00fablica", + "date": "2024-10-05" + }, + { + "name": "Dia de Todos os Santos", + "date": "2024-11-01" + }, + { + "name": "Restaura\u00e7\u00e3o da Independ\u00eancia", + "date": "2024-12-01" + }, + { + "name": "Imaculada Concei\u00e7\u00e3o", + "date": "2024-12-08" + }, + { + "name": "Natal", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/PortugalTest.php b/tests/Countries/PortugalTest.php new file mode 100644 index 00000000..7c2ed381 --- /dev/null +++ b/tests/Countries/PortugalTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 85db67e079d277afc7b91279c5f518a88a489948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Wed, 17 Jan 2024 14:24:53 +0000 Subject: [PATCH 32/95] Use proper timezone --- src/Countries/Portugal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 65f87ab5..3bbf9384 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -32,7 +32,7 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + ->setTimezone('Europe/Lisbon'); return [ 'Páscoa' => $easter, From b17f18b919789ac25561641ce49841df14e84418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Wed, 17 Jan 2024 14:27:49 +0000 Subject: [PATCH 33/95] Fixes small typo --- src/Countries/Portugal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 3bbf9384..00fbad8a 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -18,7 +18,7 @@ protected function allHolidays(int $year): array 'Dia de Ano Novo' => '01-01', 'Dia da Liberdade' => '04-25', 'Dia do Trabalhador' => '05-01', - 'Dia do Portugal' => '06-10', + 'Dia de Portugal' => '06-10', 'Assunção da Nossa Senhora' => '08-15', 'Implantação da República' => '10-05', 'Dia de Todos os Santos' => '11-01', From 22bd2b37e71e861c1b3f20c42db0fc1afe14b9f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Thu, 18 Jan 2024 10:49:28 +0000 Subject: [PATCH 34/95] Removing Carnaval as it is not an official holiday. --- src/Countries/Portugal.php | 1 - .../PortugalTest/it_can_calculate_portuguese_holidays.snap | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 00fbad8a..769800ea 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -36,7 +36,6 @@ protected function variableHolidays(int $year): array return [ 'Páscoa' => $easter, - 'Carnaval' => $easter->subDays(47), 'Sexta-feira Santa' => $easter->subDays(2), 'Corpo de Deus' => $easter->addDays(60), ]; diff --git a/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap index 7e409c71..13513781 100644 --- a/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap +++ b/tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_holidays.snap @@ -3,10 +3,6 @@ "name": "Dia de Ano Novo", "date": "2024-01-01" }, - { - "name": "Carnaval", - "date": "2024-02-13" - }, { "name": "Sexta-feira Santa", "date": "2024-03-29" @@ -28,7 +24,7 @@ "date": "2024-05-30" }, { - "name": "Dia do Portugal", + "name": "Dia de Portugal", "date": "2024-06-10" }, { From 030531b80929617e87b8c81fec8ab02e32e194d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Lamelas?= Date: Thu, 18 Jan 2024 15:20:33 +0000 Subject: [PATCH 35/95] Fix for phpstan --- src/Countries/Portugal.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 769800ea..c27489e5 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'pt'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 52af88ddb498cd9379ddb68a3fd4d10b3796f3a8 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Thu, 18 Jan 2024 15:50:25 +0000 Subject: [PATCH 36/95] Fix styling --- src/Countries/Portugal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index c27489e5..4525591d 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -23,7 +23,7 @@ protected function allHolidays(int $year): array 'Dia de Todos os Santos' => '11-01', 'Restauração da Independência' => '12-01', 'Imaculada Conceição' => '12-08', - 'Natal' => '12-25' + 'Natal' => '12-25', ], $this->variableHolidays($year)); } From ce111663c01a0fb7b5b9a15268109e3bf8e8ec88 Mon Sep 17 00:00:00 2001 From: chandachewe10 Date: Thu, 18 Jan 2024 16:12:26 +0200 Subject: [PATCH 37/95] Added Zambian Holidays --- src/Countries/Zambia.php | 44 ++++++++++++++ .../it_can_calculate_zambian_holidays.snap | 58 +++++++++++++++++++ tests/Countries/ZambiaTest.php | 18 ++++++ 3 files changed, 120 insertions(+) create mode 100644 src/Countries/Zambia.php create mode 100644 tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap create mode 100644 tests/Countries/ZambiaTest.php diff --git a/src/Countries/Zambia.php b/src/Countries/Zambia.php new file mode 100644 index 00000000..324567df --- /dev/null +++ b/src/Countries/Zambia.php @@ -0,0 +1,44 @@ + '01-01', + 'International Womens Day' => '03-08', + 'Youth Day' => '03-12', + 'Birthday of Kenneth Kaunda' => '04-28', + 'Labour Day' => '05-01', + 'Africa Day' => '05-25', + 'Heroes Day' => '07-01', + 'Unity Day' => '07-02', + 'Farmers Day' => '08-01', + 'National Prayer Day' => '10-18', + 'Independence Day' => '10-24', + 'Christmas Day' => '12-25', + + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Lusaka'); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap b/tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap new file mode 100644 index 00000000..8cec8422 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ZambiaTest/it_can_calculate_zambian_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "New Year", + "date": "2024-01-01" + }, + { + "name": "International Womens Day", + "date": "2024-03-08" + }, + { + "name": "Youth Day", + "date": "2024-03-12" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Birthday of Kenneth Kaunda", + "date": "2024-04-28" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Africa Day", + "date": "2024-05-25" + }, + { + "name": "Heroes Day", + "date": "2024-07-01" + }, + { + "name": "Unity Day", + "date": "2024-07-02" + }, + { + "name": "Farmers Day", + "date": "2024-08-01" + }, + { + "name": "National Prayer Day", + "date": "2024-10-18" + }, + { + "name": "Independence Day", + "date": "2024-10-24" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ZambiaTest.php b/tests/Countries/ZambiaTest.php new file mode 100644 index 00000000..83e73225 --- /dev/null +++ b/tests/Countries/ZambiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 2dff651032b141869059248cdce3d5f6ba2adb84 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Thu, 18 Jan 2024 15:54:00 +0000 Subject: [PATCH 38/95] Fix styling --- src/Countries/Zambia.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Zambia.php b/src/Countries/Zambia.php index 324567df..14112e6e 100644 --- a/src/Countries/Zambia.php +++ b/src/Countries/Zambia.php @@ -26,7 +26,7 @@ protected function allHolidays(int $year): array 'National Prayer Day' => '10-18', 'Independence Day' => '10-24', 'Christmas Day' => '12-25', - + ], $this->variableHolidays($year)); } @@ -37,7 +37,7 @@ protected function variableHolidays(int $year): array ->setTimezone('Africa/Lusaka'); return [ - 'Good Friday' => $easter->subDays(2), + 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), ]; } From 692bbbcf7a40b36c3feba9b34443581459def8b4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:03:01 +0100 Subject: [PATCH 39/95] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 44af97b7..1e0ecdef 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ use Spatie\Holidays\Countries\Belgium; $holidays = Holidays::for(Belgium::make())->get(); ``` -Alternatively, you could also pass an ISO code to the `for` method. +Alternatively, you could also pass an [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) code to the `for` method. ```php use Spatie\Holidays\Holidays; From f7878ffa35fa91dc562570e91250a38ee1558b36 Mon Sep 17 00:00:00 2001 From: mauricius Date: Wed, 17 Jan 2024 18:02:34 +0100 Subject: [PATCH 40/95] add: italian holidays --- src/Countries/Italy.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Countries/Italy.php diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php new file mode 100644 index 00000000..abfc530e --- /dev/null +++ b/src/Countries/Italy.php @@ -0,0 +1,41 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Capodanno' => '01-01', + 'Epifania' => '01-06', + 'Liberazione dal nazifascismo' => '04-25', + 'Festa del lavoro' => '05-01', + 'Festa della Repubblica' => '06-02', + 'Assunzione di Maria' => '08-15', + 'Ognissanti' => '11-01', + 'Immacolata Concezione' => '12-08', + 'Natale di Gesù' => '12-25', + 'Santo Stefano' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Rome'); + + return [ + 'Lunedì di Pasqua' => $easter->addDay(1), + ]; + } +} From 24779055f71d3f7c179e2f5a9b41fb280078e503 Mon Sep 17 00:00:00 2001 From: mauricius Date: Wed, 17 Jan 2024 18:02:58 +0100 Subject: [PATCH 41/95] add: italian tests --- .../it_can_calculate_italian_holidays.snap | 46 +++++++++++++++++++ tests/Countries/ItalyTest.php | 18 ++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap create mode 100644 tests/Countries/ItalyTest.php diff --git a/tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap b/tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap new file mode 100644 index 00000000..b390d06e --- /dev/null +++ b/tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Capodanno", + "date": "2024-01-01" + }, + { + "name": "Epifania", + "date": "2024-01-06" + }, + { + "name": "Luned\u00ec di Pasqua", + "date": "2024-04-01" + }, + { + "name": "Liberazione dal nazifascismo", + "date": "2024-04-25" + }, + { + "name": "Festa del lavoro", + "date": "2024-05-01" + }, + { + "name": "Festa della Repubblica", + "date": "2024-06-02" + }, + { + "name": "Assunzione di Maria", + "date": "2024-08-15" + }, + { + "name": "Ognissanti", + "date": "2024-11-01" + }, + { + "name": "Immacolata Concezione", + "date": "2024-12-08" + }, + { + "name": "Natale di Ges\u00f9", + "date": "2024-12-25" + }, + { + "name": "Santo Stefano", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/ItalyTest.php b/tests/Countries/ItalyTest.php new file mode 100644 index 00000000..bd42933b --- /dev/null +++ b/tests/Countries/ItalyTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 96ad08cc082b1a7d55273025e1cac03c53ceebf8 Mon Sep 17 00:00:00 2001 From: mauricius Date: Thu, 18 Jan 2024 14:20:51 +0100 Subject: [PATCH 42/95] remove: phpdoc --- src/Countries/Italy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php index abfc530e..d302f94d 100644 --- a/src/Countries/Italy.php +++ b/src/Countries/Italy.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'it'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 638f45cf812a0e7ce46e7bd66422a181978c85ba Mon Sep 17 00:00:00 2001 From: mauricius Date: Thu, 18 Jan 2024 17:43:23 +0100 Subject: [PATCH 43/95] fix: fix phpstan --- src/Countries/Italy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php index d302f94d..169533ae 100644 --- a/src/Countries/Italy.php +++ b/src/Countries/Italy.php @@ -34,7 +34,7 @@ protected function variableHolidays(int $year): array ->setTimezone('Europe/Rome'); return [ - 'Lunedì di Pasqua' => $easter->addDay(1), + 'Lunedì di Pasqua' => $easter->addDay(), ]; } } From 29175683acc87b3bd718177e5317825c22a37a05 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:12:30 +0100 Subject: [PATCH 44/95] Create pull_request_template.md --- .github/pull_request_template.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..fa520ece --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,8 @@ +# Contributing a new country ? + +* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same country? + +1. Create a new class in the Countries directory. It should extend the Country class. +2. Add a test for the new country in the tests directory. +3. Run the tests so a snapshot gets created. +4. Verify the result in the newly created snapshot is correct. From 33839fa881be86536058adbe2424359259c3f5ee Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:14:24 +0100 Subject: [PATCH 45/95] Update pull_request_template.md --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index fa520ece..9fb40912 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,6 @@ # Contributing a new country ? -* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same country? +* [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/spatie/holidays/pulls) for the same country? 1. Create a new class in the Countries directory. It should extend the Country class. 2. Add a test for the new country in the tests directory. From de0450c9cd198cd0d1d45cb30c91573d75639725 Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 15:47:45 +0100 Subject: [PATCH 46/95] Create France.php --- src/Countries/France.php | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Countries/France.php diff --git a/src/Countries/France.php b/src/Countries/France.php new file mode 100644 index 00000000..3c7a488e --- /dev/null +++ b/src/Countries/France.php @@ -0,0 +1,41 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Jour de l\'An' => '01-01', + 'Fête du Travail' => '05-01', + 'Victoire 1945' => '05-08' + 'Fête Nationale' => '07-14', + 'Assomption' => '08-15', + 'Toussaint' => '11-01', + 'Armistice 1918' => '11-11', + 'Noël' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Brussels'); + + return [ + 'Lundi de Pâques' => $easter->addDay(), + 'Ascension' => $easter->addDays(39), + 'Lundi de Pentecôte' => $easter->addDays(50), + ]; + } +} From 7e7412268a436a4ad23c6467357d36318c9363fc Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 15:49:49 +0100 Subject: [PATCH 47/95] Create FranceTest.php --- tests/Countries/FranceTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/Countries/FranceTest.php diff --git a/tests/Countries/FranceTest.php b/tests/Countries/FranceTest.php new file mode 100644 index 00000000..6b69bbf2 --- /dev/null +++ b/tests/Countries/FranceTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 73e993b2775afe65830f97c4e34f735307ecc05f Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 15:55:02 +0100 Subject: [PATCH 48/95] Fix France.php --- src/Countries/France.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 3c7a488e..632552f4 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -17,7 +17,7 @@ protected function allHolidays(int $year): array return array_merge([ 'Jour de l\'An' => '01-01', 'Fête du Travail' => '05-01', - 'Victoire 1945' => '05-08' + 'Victoire 1945' => '05-08', 'Fête Nationale' => '07-14', 'Assomption' => '08-15', 'Toussaint' => '11-01', From 0abc4f6584f8074ada52d0023fec982fb1ccf75f Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 16:01:43 +0100 Subject: [PATCH 49/95] Create it_can_calculate_french_holidays.snap --- .../it_can_calculate_french_holidays.snap | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap new file mode 100644 index 00000000..aef1f0ea --- /dev/null +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Jour de l'An", + "date": "2024-01-01" + }, + { + "name": "Lundi de Pâques", + "date": "2024-04-01" + }, + { + "name": "Fête du Travail", + "date": "2024-05-01" + }, + { + "name": "Victoire 1945", + "date": "2024-05-08" + }, + { + "name": "Ascension", + "date": "2024-05-09" + }, + { + "name": "Lundi de Pentecôte", + "date": "2024-05-20" + }, + { + "name": "Fête Nationale", + "date": "2024-07-14" + }, + { + "name": "Assomption", + "date": "2024-08-15" + }, + { + "name": "Toussaint", + "date": "2024-11-01" + }, + { + "name": "Armistice 1918", + "date": "2024-11-11" + }, + { + "name": "Noël", + "date": "2024-12-25" + } +] From a219ea1aab3203c92cf90c048afed9a3c1f79af4 Mon Sep 17 00:00:00 2001 From: Loup Date: Wed, 17 Jan 2024 16:09:40 +0100 Subject: [PATCH 50/95] tests --- .../FranceTest/it_can_calculate_french_holidays.snap | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap index aef1f0ea..f89d1730 100644 --- a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_holidays.snap @@ -4,11 +4,11 @@ "date": "2024-01-01" }, { - "name": "Lundi de Pâques", + "name": "Lundi de P\u00e2ques", "date": "2024-04-01" }, { - "name": "Fête du Travail", + "name": "F\u00eate du Travail", "date": "2024-05-01" }, { @@ -20,11 +20,11 @@ "date": "2024-05-09" }, { - "name": "Lundi de Pentecôte", + "name": "Lundi de Pentec\u00f4te", "date": "2024-05-20" }, { - "name": "Fête Nationale", + "name": "F\u00eate Nationale", "date": "2024-07-14" }, { @@ -40,7 +40,7 @@ "date": "2024-11-11" }, { - "name": "Noël", + "name": "No\u00ebl", "date": "2024-12-25" } -] +] \ No newline at end of file From f4095e3f266c6c7bc896fb850bc088bd948d776f Mon Sep 17 00:00:00 2001 From: levrailoup Date: Wed, 17 Jan 2024 19:02:22 +0100 Subject: [PATCH 51/95] Update src/Countries/France.php Co-authored-by: Hugo Alliaume --- src/Countries/France.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 632552f4..3b1813b4 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + ->setTimezone('Europe/Paris'); return [ 'Lundi de Pâques' => $easter->addDay(), From eb3da65d46619e44fe21187906124fc967b71ebc Mon Sep 17 00:00:00 2001 From: levrailoup Date: Thu, 18 Jan 2024 14:04:47 +0100 Subject: [PATCH 52/95] Removed typehint from France::allHolidays() --- src/Countries/France.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 3b1813b4..1aadad48 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'fr'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From 6c0f232e5ac97284034a08e26e588b8690aa3aa7 Mon Sep 17 00:00:00 2001 From: Loup Date: Thu, 18 Jan 2024 18:39:03 +0100 Subject: [PATCH 53/95] Added region-specific ISO 3166-2 codes --- src/Countries/France.php | 42 ++++++++++++++- ...e_french_date_based_regional_holidays.snap | 50 +++++++++++++++++ ...e_french_easter_based_region_holidays.snap | 54 +++++++++++++++++++ tests/Countries/FranceTest.php | 25 +++++++++ 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap diff --git a/src/Countries/France.php b/src/Countries/France.php index 1aadad48..977e26a1 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -6,6 +6,11 @@ class France extends Country { + protected function __construct( + protected ?string $region = null, + ) { + } + public function countryCode(): string { return 'fr'; @@ -22,7 +27,9 @@ protected function allHolidays(int $year): array 'Toussaint' => '11-01', 'Armistice 1918' => '11-11', 'Noël' => '12-25', - ], $this->variableHolidays($year)); + ], + $this->variableHolidays($year), + $this->regionHolidays()); } /** @return array */ @@ -31,10 +38,41 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Europe/Paris'); - return [ + $holidays = [ 'Lundi de Pâques' => $easter->addDay(), 'Ascension' => $easter->addDays(39), 'Lundi de Pentecôte' => $easter->addDays(50), ]; + + if (in_array($this->region, ['FR-57', 'FR-67', 'FR-68'])) { + $holidays['Vendredi Saint'] = $easter->subDays(2); + } + + return $holidays; + } + + protected function regionHolidays(): array + { + switch ($this->region) { + case 'FR-57': + case 'FR-67': + case 'FR-68': + return ['Saint-Étienne' => '12-26']; + case 'FR-971': + case 'FR-MF': + return ['Abolition de l\'esclavage' => '05-27']; + case 'FR-972': + return ['Abolition de l\'esclavage' => '05-22']; + case 'FR-973': + return ['Abolition de l\'esclavage' => '06-10']; + case 'FR-974': + return ['Abolition de l\'esclavage' => '12-20']; + case 'FR-976': + return ['Abolition de l\'esclavage' => '04-27']; + case 'FR-BL': + return ['Abolition de l\'esclavage' => '10-09']; + } + + return []; } } diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap new file mode 100644 index 00000000..5256f894 --- /dev/null +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_date_based_regional_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Jour de l'An", + "date": "2024-01-01" + }, + { + "name": "Lundi de P\u00e2ques", + "date": "2024-04-01" + }, + { + "name": "F\u00eate du Travail", + "date": "2024-05-01" + }, + { + "name": "Victoire 1945", + "date": "2024-05-08" + }, + { + "name": "Ascension", + "date": "2024-05-09" + }, + { + "name": "Lundi de Pentec\u00f4te", + "date": "2024-05-20" + }, + { + "name": "F\u00eate Nationale", + "date": "2024-07-14" + }, + { + "name": "Assomption", + "date": "2024-08-15" + }, + { + "name": "Abolition de l'esclavage", + "date": "2024-10-09" + }, + { + "name": "Toussaint", + "date": "2024-11-01" + }, + { + "name": "Armistice 1918", + "date": "2024-11-11" + }, + { + "name": "No\u00ebl", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap new file mode 100644 index 00000000..4dd52f18 --- /dev/null +++ b/tests/.pest/snapshots/Countries/FranceTest/it_can_calculate_french_easter_based_region_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Jour de l'An", + "date": "2024-01-01" + }, + { + "name": "Vendredi Saint", + "date": "2024-03-29" + }, + { + "name": "Lundi de P\u00e2ques", + "date": "2024-04-01" + }, + { + "name": "F\u00eate du Travail", + "date": "2024-05-01" + }, + { + "name": "Victoire 1945", + "date": "2024-05-08" + }, + { + "name": "Ascension", + "date": "2024-05-09" + }, + { + "name": "Lundi de Pentec\u00f4te", + "date": "2024-05-20" + }, + { + "name": "F\u00eate Nationale", + "date": "2024-07-14" + }, + { + "name": "Assomption", + "date": "2024-08-15" + }, + { + "name": "Toussaint", + "date": "2024-11-01" + }, + { + "name": "Armistice 1918", + "date": "2024-11-11" + }, + { + "name": "No\u00ebl", + "date": "2024-12-25" + }, + { + "name": "Saint-\u00c9tienne", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/FranceTest.php b/tests/Countries/FranceTest.php index 6b69bbf2..e70d919b 100644 --- a/tests/Countries/FranceTest.php +++ b/tests/Countries/FranceTest.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; +use Spatie\Holidays\Countries\France; it('can calculate french holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); @@ -16,3 +17,27 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('can calculate french easter based region holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(France::make('FR-57'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate french date based regional holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(France::make('FR-BL'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From e2d8fc35c0d2ddfd734f7aa975964e4371d56da1 Mon Sep 17 00:00:00 2001 From: Loup Date: Thu, 18 Jan 2024 18:57:23 +0100 Subject: [PATCH 54/95] Added regionHolidays return value type --- src/Countries/France.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Countries/France.php b/src/Countries/France.php index 977e26a1..449d13f5 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -51,6 +51,7 @@ protected function variableHolidays(int $year): array return $holidays; } + /** @return array */ protected function regionHolidays(): array { switch ($this->region) { From 062ca3324744f75d098d124a662f636ca93e351e Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 12:22:16 +0000 Subject: [PATCH 55/95] Fix styling --- src/Countries/France.php | 4 ++-- tests/Countries/FranceTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Countries/France.php b/src/Countries/France.php index 449d13f5..c948556f 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -28,8 +28,8 @@ protected function allHolidays(int $year): array 'Armistice 1918' => '11-11', 'Noël' => '12-25', ], - $this->variableHolidays($year), - $this->regionHolidays()); + $this->variableHolidays($year), + $this->regionHolidays()); } /** @return array */ diff --git a/tests/Countries/FranceTest.php b/tests/Countries/FranceTest.php index e70d919b..358f8b1c 100644 --- a/tests/Countries/FranceTest.php +++ b/tests/Countries/FranceTest.php @@ -3,8 +3,8 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Holidays; use Spatie\Holidays\Countries\France; +use Spatie\Holidays\Holidays; it('can calculate french holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); From 71b36dfa51cdcbf5482313d0ffc30983973103de Mon Sep 17 00:00:00 2001 From: vrerabek Date: Fri, 19 Jan 2024 13:23:20 +0100 Subject: [PATCH 56/95] Add Czech holidays (#22) * add: czech holidays * add: czechia test * remove: docblock --------- Co-authored-by: Vojtech Rerabek --- src/Countries/Czechia.php | 42 +++++++++++++++ .../it_can_calculate_czech_holidays.snap | 54 +++++++++++++++++++ tests/Countries/CzechiaTest.php | 18 +++++++ 3 files changed, 114 insertions(+) create mode 100644 src/Countries/Czechia.php create mode 100644 tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap create mode 100644 tests/Countries/CzechiaTest.php diff --git a/src/Countries/Czechia.php b/src/Countries/Czechia.php new file mode 100644 index 00000000..f0cce6f0 --- /dev/null +++ b/src/Countries/Czechia.php @@ -0,0 +1,42 @@ + '01-01', + 'Svátek práce' => '05-01', + 'Den vítězství' => '05-08', + 'Den slovanských věrozvěstů Cyrila a Metoděje' => '07-05', + 'Den upálení mistra Jana Husa' => '07-06', + 'Den české státnosti' => '09-28', + 'Den vzniku samostatného československého státu' => '10-28', + 'Den boje za svobodu a demokracii a Mezinárodní den studentstva' => '11-17', + 'Štědrý den' => '12-24', + '1. svátek vánoční' => '12-25', + '2. svátek vánoční' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Prague'); + + return [ + 'Velikonoční pondělí' => $easter->addDay(), + 'Velký pátek' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap b/tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap new file mode 100644 index 00000000..9e3ba56a --- /dev/null +++ b/tests/.pest/snapshots/Countries/CzechiaTest/it_can_calculate_czech_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Den obnovy samostatn\u00e9ho \u010desk\u00e9ho st\u00e1tu", + "date": "2024-01-01" + }, + { + "name": "Velk\u00fd p\u00e1tek", + "date": "2024-03-29" + }, + { + "name": "Velikono\u010dn\u00ed pond\u011bl\u00ed", + "date": "2024-04-01" + }, + { + "name": "Sv\u00e1tek pr\u00e1ce", + "date": "2024-05-01" + }, + { + "name": "Den v\u00edt\u011bzstv\u00ed", + "date": "2024-05-08" + }, + { + "name": "Den slovansk\u00fdch v\u011brozv\u011bst\u016f Cyrila a Metod\u011bje", + "date": "2024-07-05" + }, + { + "name": "Den up\u00e1len\u00ed mistra Jana Husa", + "date": "2024-07-06" + }, + { + "name": "Den \u010desk\u00e9 st\u00e1tnosti", + "date": "2024-09-28" + }, + { + "name": "Den vzniku samostatn\u00e9ho \u010deskoslovensk\u00e9ho st\u00e1tu", + "date": "2024-10-28" + }, + { + "name": "Den boje za svobodu a demokracii a Mezin\u00e1rodn\u00ed den studentstva", + "date": "2024-11-17" + }, + { + "name": "\u0160t\u011bdr\u00fd den", + "date": "2024-12-24" + }, + { + "name": "1. sv\u00e1tek v\u00e1no\u010dn\u00ed", + "date": "2024-12-25" + }, + { + "name": "2. sv\u00e1tek v\u00e1no\u010dn\u00ed", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/CzechiaTest.php b/tests/Countries/CzechiaTest.php new file mode 100644 index 00000000..a23bac97 --- /dev/null +++ b/tests/Countries/CzechiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); \ No newline at end of file From df95e9911a80e3b3a6d02ea903f88a9ebfba8a24 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 12:23:46 +0000 Subject: [PATCH 57/95] Fix styling --- tests/Countries/CzechiaTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Countries/CzechiaTest.php b/tests/Countries/CzechiaTest.php index a23bac97..0a7ece2f 100644 --- a/tests/Countries/CzechiaTest.php +++ b/tests/Countries/CzechiaTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); \ No newline at end of file +}); From 20aa6126af10d3b7acc1e893e31edb4c1d87e6c9 Mon Sep 17 00:00:00 2001 From: Julio Fagundes Date: Thu, 18 Jan 2024 16:41:23 -0300 Subject: [PATCH 58/95] Update Brazil.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added "Dia Nacional de Zumbi e da Consciência Negra" --- src/Countries/Brazil.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index 19b9af7a..a05dbbf4 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -23,6 +23,7 @@ protected function allHolidays(int $year): array 'Nossa Senhora Aparecida' => '10-12', 'Finados' => '11-02', 'Proclamação da República' => '11-15', + 'Dia Nacional de Zumbi e da Consciência Negra' => '11-20', 'Natal' => '12-25', ], $this->variableHolidays($year)); } From dde45578d5aa13d36b84f558a2a13e67386cc01b Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 13:53:38 +0100 Subject: [PATCH 59/95] activate brazil --- src/Countries/Brazil.php | 2 -- tests/Countries/BrazilTest.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index a05dbbf4..e861e887 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -13,8 +13,6 @@ public function countryCode(): string protected function allHolidays(int $year): array { - throw new \Exception('Not implemented yet.'); - return array_merge([ 'Dia de Ano Novo' => '01-01', 'Dia de Tiradentes' => '04-21', diff --git a/tests/Countries/BrazilTest.php b/tests/Countries/BrazilTest.php index a91509ff..91be74d4 100644 --- a/tests/Countries/BrazilTest.php +++ b/tests/Countries/BrazilTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -})->skip('Still an issue'); +}); From 8cec2855faea2d75ae863b2abb722aea68a2b85b Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:18:39 +0100 Subject: [PATCH 60/95] calculate correct easter date --- src/Countries/Andorra.php | 3 +-- src/Countries/Austria.php | 3 +-- src/Countries/Belgium.php | 3 +-- src/Countries/Brazil.php | 2 +- src/Countries/Country.php | 7 +++++++ src/Countries/Czechia.php | 3 +-- src/Countries/Denmark.php | 3 +-- src/Countries/France.php | 3 +-- src/Countries/Hungary.php | 3 +-- src/Countries/Italy.php | 3 +-- src/Countries/Netherlands.php | 3 +-- src/Countries/Portugal.php | 3 +-- src/Countries/Zambia.php | 3 +-- .../BrazilTest/it_can_calculate_brazil_holidays.snap | 4 ++++ 14 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Countries/Andorra.php b/src/Countries/Andorra.php index 51615e69..89ce91c8 100644 --- a/src/Countries/Andorra.php +++ b/src/Countries/Andorra.php @@ -30,8 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + $easter = $this->easter($year); return [ 'Divendres Sant' => $easter->subDays(2), diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index 73fb6128..5041c401 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -34,8 +34,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Vienna'); + $easter = $this->easter($year); return [ 'Ostermontag' => $easter->addDay(), diff --git a/src/Countries/Belgium.php b/src/Countries/Belgium.php index af52b681..8710daf7 100644 --- a/src/Countries/Belgium.php +++ b/src/Countries/Belgium.php @@ -27,8 +27,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + $easter = $this->easter($year); return [ 'Paasmaandag' => $easter->addDay(), diff --git a/src/Countries/Brazil.php b/src/Countries/Brazil.php index e861e887..d2be75a2 100644 --- a/src/Countries/Brazil.php +++ b/src/Countries/Brazil.php @@ -29,7 +29,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('America/Sao_Paulo'); + $easter = $this->easter($year); return [ 'Carnaval' => $easter->subDays(47), diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 8b75b8df..2c554702 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -40,6 +40,13 @@ public static function make(): static return new static(...func_get_args()); } + protected function easter(string $year): CarbonImmutable + { + $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21"); + + return $easter->addDays(easter_days($year)); + } + public static function find(string $countryCode): ?Country { $countryCode = strtolower($countryCode); diff --git a/src/Countries/Czechia.php b/src/Countries/Czechia.php index f0cce6f0..c4aff420 100644 --- a/src/Countries/Czechia.php +++ b/src/Countries/Czechia.php @@ -31,8 +31,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Prague'); + $easter = $this->easter($year); return [ 'Velikonoční pondělí' => $easter->addDay(), diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index 66d2113a..ee68d1d7 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -24,8 +24,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Copenhagen'); + $easter = $this->easter($year); $holidays = [ 'Påskedag' => $easter->addDay(), diff --git a/src/Countries/France.php b/src/Countries/France.php index c948556f..c0272aab 100644 --- a/src/Countries/France.php +++ b/src/Countries/France.php @@ -35,8 +35,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Paris'); + $easter = $this->easter($year); $holidays = [ 'Lundi de Pâques' => $easter->addDay(), diff --git a/src/Countries/Hungary.php b/src/Countries/Hungary.php index 15a46e99..9658c380 100644 --- a/src/Countries/Hungary.php +++ b/src/Countries/Hungary.php @@ -28,8 +28,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Brussels'); + $easter = $this->easter($year); return [ 'Nagypéntek' => $easter->subDays(2), diff --git a/src/Countries/Italy.php b/src/Countries/Italy.php index 169533ae..e4f53b09 100644 --- a/src/Countries/Italy.php +++ b/src/Countries/Italy.php @@ -30,8 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Rome'); + $easter = $this->easter($year); return [ 'Lunedì di Pasqua' => $easter->addDay(), diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index b694c25c..91abc9bd 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -30,8 +30,7 @@ protected function variableHolidays(int $year): array $koningsDag = $koningsDag->subDay(); } - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Amsterdam'); + $easter = $this->easter($year); return [ 'Koningsdag' => $koningsDag, diff --git a/src/Countries/Portugal.php b/src/Countries/Portugal.php index 4525591d..98c09b0a 100644 --- a/src/Countries/Portugal.php +++ b/src/Countries/Portugal.php @@ -30,8 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Lisbon'); + $easter = $this->easter($year); return [ 'Páscoa' => $easter, diff --git a/src/Countries/Zambia.php b/src/Countries/Zambia.php index 14112e6e..c8802a90 100644 --- a/src/Countries/Zambia.php +++ b/src/Countries/Zambia.php @@ -33,8 +33,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Africa/Lusaka'); + $easter = $this->easter($year); return [ 'Good Friday' => $easter->subDays(2), diff --git a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap index 5be3e640..eeaf05a7 100644 --- a/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap +++ b/tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap @@ -39,6 +39,10 @@ "name": "Proclama\u00e7\u00e3o da Rep\u00fablica", "date": "2024-11-15" }, + { + "name": "Dia Nacional de Zumbi e da Consci\u00eancia Negra", + "date": "2024-11-20" + }, { "name": "Natal", "date": "2024-12-25" From 615486161d9d48828242889755d1991eadf9907f Mon Sep 17 00:00:00 2001 From: Joel Crawford Date: Fri, 19 Jan 2024 13:49:45 +0300 Subject: [PATCH 61/95] Added Uganda holidays and Tests --- src/Countries/Uganda.php | 56 +++++++++++++++++++ .../it_can_calculate_ugandan_holidays.snap | 50 +++++++++++++++++ tests/Countries/UgandaTest.php | 18 ++++++ 3 files changed, 124 insertions(+) create mode 100644 src/Countries/Uganda.php create mode 100644 tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap create mode 100644 tests/Countries/UgandaTest.php diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php new file mode 100644 index 00000000..023d20b7 --- /dev/null +++ b/src/Countries/Uganda.php @@ -0,0 +1,56 @@ + Github: LinkedIn: + */ + +namespace Spatie\Holidays\Countries; + +use Carbon\CarbonImmutable; + +class Uganda extends Country +{ + + public function countryCode(): string + { + return 'ug'; + } + + /** + * @inheritDoc + */ + protected function allHolidays(int $year): array + { + + /** + * 'New Year' => '01-01', Format:: Month-Date + */ + return array_merge([ + 'New Year' => '01-01', + 'NRM Liberation Day' => '01-26', + 'Archbishop Janani Luwum Day' => '02-16', + 'International Womens Day' => '03-08', + 'Labour Day' => '05-01', + 'Martyrs Day' => '06-03', + 'National Hereos Day' => '06-09', + 'Independence Day' => '10-09', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + /** + * @param int $year + * + * @return array + */ + private function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + return [ + "Good Friday" => $easter->subDays(2), + "Easter Monday" => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap new file mode 100644 index 00000000..35276c50 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "New Year", + "date": "2024-01-01" + }, + { + "name": "NRM Liberation Day", + "date": "2024-01-26" + }, + { + "name": "Archbishop Janani Luwum Day", + "date": "2024-02-16" + }, + { + "name": "International Womens Day", + "date": "2024-03-08" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Martyrs Day", + "date": "2024-06-03" + }, + { + "name": "National Hereos Day", + "date": "2024-06-09" + }, + { + "name": "Independence Day", + "date": "2024-10-09" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/UgandaTest.php b/tests/Countries/UgandaTest.php new file mode 100644 index 00000000..82ab1f7f --- /dev/null +++ b/tests/Countries/UgandaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 67db06b6a8a0ffe3a2d5e7b889dd67b1bc01b759 Mon Sep 17 00:00:00 2001 From: Joel Crawford Date: Fri, 19 Jan 2024 15:55:55 +0300 Subject: [PATCH 62/95] Fixed::Name having ' on it --- src/Countries/Uganda.php | 20 +++++++++---------- .../it_can_calculate_ugandan_holidays.snap | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 023d20b7..635b1b29 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -27,16 +27,16 @@ protected function allHolidays(int $year): array * 'New Year' => '01-01', Format:: Month-Date */ return array_merge([ - 'New Year' => '01-01', - 'NRM Liberation Day' => '01-26', - 'Archbishop Janani Luwum Day' => '02-16', - 'International Womens Day' => '03-08', - 'Labour Day' => '05-01', - 'Martyrs Day' => '06-03', - 'National Hereos Day' => '06-09', - 'Independence Day' => '10-09', - 'Christmas Day' => '12-25', - 'Boxing Day' => '12-26', + "New Year's Day" => "01-01", + "NRM Liberation Day" => "01-26", + "Archbishop Janani Luwum Day" => "02-16", + "International Women's Day" => "03-08", + "Labour Day" => "05-01", + "Martyrs' Day" => "06-03", + "National Hereos Day" => "06-09", + "Independence Day" => "10-09", + "Christmas Day" => "12-25", + "Boxing Day" => "12-26", ], $this->variableHolidays($year)); } diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap index 35276c50..ff373318 100644 --- a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_ugandan_holidays.snap @@ -1,6 +1,6 @@ [ { - "name": "New Year", + "name": "New Year's Day", "date": "2024-01-01" }, { @@ -12,7 +12,7 @@ "date": "2024-02-16" }, { - "name": "International Womens Day", + "name": "International Women's Day", "date": "2024-03-08" }, { @@ -28,7 +28,7 @@ "date": "2024-05-01" }, { - "name": "Martyrs Day", + "name": "Martyrs' Day", "date": "2024-06-03" }, { From a094266657d915ad94677f33c2d243d9b774d526 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:21:46 +0000 Subject: [PATCH 63/95] Fix styling --- src/Countries/Uganda.php | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 635b1b29..8673698d 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -11,46 +11,44 @@ class Uganda extends Country { - public function countryCode(): string { return 'ug'; } /** - * @inheritDoc + * {@inheritDoc} */ protected function allHolidays(int $year): array { - /** - * 'New Year' => '01-01', Format:: Month-Date - */ + /** + * 'New Year' => '01-01', Format:: Month-Date + */ return array_merge([ - "New Year's Day" => "01-01", - "NRM Liberation Day" => "01-26", - "Archbishop Janani Luwum Day" => "02-16", - "International Women's Day" => "03-08", - "Labour Day" => "05-01", - "Martyrs' Day" => "06-03", - "National Hereos Day" => "06-09", - "Independence Day" => "10-09", - "Christmas Day" => "12-25", - "Boxing Day" => "12-26", + "New Year's Day" => '01-01', + 'NRM Liberation Day' => '01-26', + 'Archbishop Janani Luwum Day' => '02-16', + "International Women's Day" => '03-08', + 'Labour Day' => '05-01', + "Martyrs' Day" => '06-03', + 'National Hereos Day' => '06-09', + 'Independence Day' => '10-09', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', ], $this->variableHolidays($year)); } /** - * @param int $year - * * @return array */ private function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + return [ - "Good Friday" => $easter->subDays(2), - "Easter Monday" => $easter->addDay(), + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), ]; } } From 307b304faed2276930afdfe0a56dfd35f9431910 Mon Sep 17 00:00:00 2001 From: Ricardo Martos Date: Fri, 19 Jan 2024 11:49:25 +0100 Subject: [PATCH 64/95] Add Venezuela country class and test This commit adds the `Venezuela` class to handle holidays in Venezuela. The class includes a method to calculate all fixed holidays and another method to calculate variable holidays based on Easter. Additionally, a test is added to ensure that the calculation of Venezuelan holidays is correct. --- src/Countries/Venezuela.php | 43 ++++++++++++++ .../it_can_calculate_venezuelan_holidays.snap | 58 +++++++++++++++++++ tests/Countries/VenezuelaTest.php | 18 ++++++ 3 files changed, 119 insertions(+) create mode 100644 src/Countries/Venezuela.php create mode 100644 tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap create mode 100644 tests/Countries/VenezuelaTest.php diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php new file mode 100644 index 00000000..80441506 --- /dev/null +++ b/src/Countries/Venezuela.php @@ -0,0 +1,43 @@ + '01-01', + 'Declaración de la Independencia' => '04-19', + 'Día del Trabajador' => '05-01', + 'Aniversario de la Batalla de Carabobo' => '06-24', + 'Día de la Independencia' => '07-05', + 'Natalicio de Simón Bolívar' => '07-24', + 'Día de la Resistencia Indígena' => '10-12', + 'Víspera de Navidad' => '12-24', + 'Navidad' => '12-25', + 'Día de Fin de Año' => '12-31', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)); + + return [ + 'Lunes de Carnaval' => $easter->subDays(47), + 'Martes de Carnaval' => $easter->subDays(46), + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap new file mode 100644 index 00000000..1c867bd6 --- /dev/null +++ b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "A\u00f1o nuevo", + "date": "2024-01-01" + }, + { + "name": "Lunes de Carnaval", + "date": "2024-02-12" + }, + { + "name": "Martes de Carnaval", + "date": "2024-02-13" + }, + { + "name": "Jueves Santo", + "date": "2024-03-27" + }, + { + "name": "Viernes Santo", + "date": "2024-03-28" + }, + { + "name": "Declaraci\u00f3n de la Independencia", + "date": "2024-04-19" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Aniversario de la Batalla de Carabobo", + "date": "2024-06-24" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-07-05" + }, + { + "name": "Natalicio de Sim\u00f3n Bol\u00edvar", + "date": "2024-07-24" + }, + { + "name": "D\u00eda de la Resistencia Ind\u00edgena", + "date": "2024-10-12" + }, + { + "name": "V\u00edspera de Navidad", + "date": "2024-12-24" + }, + { + "name": "Navidad", + "date": "2024-12-25" + }, + { + "name": "D\u00eda de Fin de A\u00f1o", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/Countries/VenezuelaTest.php b/tests/Countries/VenezuelaTest.php new file mode 100644 index 00000000..5b2cf5ea --- /dev/null +++ b/tests/Countries/VenezuelaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From cf98cd700e47910eb6199d17809baaf68e8aa778 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:22:22 +0000 Subject: [PATCH 65/95] Fix styling --- src/Countries/Venezuela.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php index 80441506..bda60ac9 100644 --- a/src/Countries/Venezuela.php +++ b/src/Countries/Venezuela.php @@ -2,7 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\Carbon; use Carbon\CarbonImmutable; class Venezuela extends Country From 9f6347dbad3bdae5d33513e2e5fc34371386ae23 Mon Sep 17 00:00:00 2001 From: object505 Date: Fri, 19 Jan 2024 07:02:20 +0100 Subject: [PATCH 66/95] Add Macedonian holidays --- src/Countries/NorthMacedonia.php | 48 +++++++++++++++++++ .../it_can_calculate_macedonian_holidays.snap | 42 ++++++++++++++++ tests/Countries/NorthMacedoniaTest.php | 18 +++++++ 3 files changed, 108 insertions(+) create mode 100644 src/Countries/NorthMacedonia.php create mode 100644 tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap create mode 100644 tests/Countries/NorthMacedoniaTest.php diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php new file mode 100644 index 00000000..0ab6f07a --- /dev/null +++ b/src/Countries/NorthMacedonia.php @@ -0,0 +1,48 @@ + '01-01', + 'Божик, првиот ден на Божик според православниот календар' => '01-07', + 'Ден на трудот' => '05-01', + 'Св. Кирил и Методиј - Ден на сесловенските просветители' => '05-24', + 'Ден на Републиката' => '08-02', + 'Ден на независноста' => '09-08', + 'Ден на народното востание' => '10-11', + 'Ден на македонската револуционерна борба' => '10-23', + 'Св. Климент Охридски' => '12-08', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp($this->ortodoxEaster($year)) + ->setTimezone('Europe/Skopje'); + + return [ + 'Велигден, вториот ден на Велигден според православниот календар' => $easter->addDay(), + ]; + } + + protected function ortodoxEaster(int $year) + { + $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); + $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; + + return strtotime("+$daysDifference days", $timestamp); + } +} diff --git a/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap b/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap new file mode 100644 index 00000000..dfc69419 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "\u041d\u043e\u0432\u0430 \u0433\u043e\u0434\u0438\u043d\u0430", + "date": "2024-01-01" + }, + { + "name": "\u0411\u043e\u0436\u0438\u043a, \u043f\u0440\u0432\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0411\u043e\u0436\u0438\u043a \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440", + "date": "2024-01-07" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u0442\u0440\u0443\u0434\u043e\u0442", + "date": "2024-05-01" + }, + { + "name": "\u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d, \u0432\u0442\u043e\u0440\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440", + "date": "2024-05-06" + }, + { + "name": "\u0421\u0432. \u041a\u0438\u0440\u0438\u043b \u0438 \u041c\u0435\u0442\u043e\u0434\u0438\u0458 - \u0414\u0435\u043d \u043d\u0430 \u0441\u0435\u0441\u043b\u043e\u0432\u0435\u043d\u0441\u043a\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u0432\u0435\u0442\u0438\u0442\u0435\u043b\u0438", + "date": "2024-05-24" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u0420\u0435\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430", + "date": "2024-08-02" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u043d\u043e\u0441\u0442\u0430", + "date": "2024-09-08" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0430\u0440\u043e\u0434\u043d\u043e\u0442\u043e \u0432\u043e\u0441\u0442\u0430\u043d\u0438\u0435", + "date": "2024-10-11" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0430\u0442\u0430 \u0440\u0435\u0432\u043e\u043b\u0443\u0446\u0438\u043e\u043d\u0435\u0440\u043d\u0430 \u0431\u043e\u0440\u0431\u0430", + "date": "2024-10-23" + }, + { + "name": "\u0421\u0432. \u041a\u043b\u0438\u043c\u0435\u043d\u0442 \u041e\u0445\u0440\u0438\u0434\u0441\u043a\u0438", + "date": "2024-12-08" + } +] \ No newline at end of file diff --git a/tests/Countries/NorthMacedoniaTest.php b/tests/Countries/NorthMacedoniaTest.php new file mode 100644 index 00000000..b68507ff --- /dev/null +++ b/tests/Countries/NorthMacedoniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 7da301a0546abf307f3272e09ee892a1bf647b46 Mon Sep 17 00:00:00 2001 From: object505 Date: Fri, 19 Jan 2024 13:43:10 +0100 Subject: [PATCH 67/95] Added return type --- src/Countries/NorthMacedonia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 0ab6f07a..81da2e27 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -38,7 +38,7 @@ protected function variableHolidays(int $year): array ]; } - protected function ortodoxEaster(int $year) + protected function ortodoxEaster(int $year): bool|int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; From 27ab746e9df285ce88d0fa7f969ce1b367fd8f66 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:22:47 +0000 Subject: [PATCH 68/95] Fix styling --- src/Countries/NorthMacedonia.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 81da2e27..0d4a447f 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -6,7 +6,6 @@ class NorthMacedonia extends Country { - public function countryCode(): string { return 'mk'; @@ -41,7 +40,7 @@ protected function variableHolidays(int $year): array protected function ortodoxEaster(int $year): bool|int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); - $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; + $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; return strtotime("+$daysDifference days", $timestamp); } From 139c956ba95e286db34615b356eb3d7610cd6bfe Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 11:28:56 -0600 Subject: [PATCH 69/95] Adding Nicaragua Holidays Avoid PHPStorm insert final newline into snap, failing the test match string. --- .editorconfig | 3 ++ src/Countries/Nicaragua.php | 40 ++++++++++++++++++ .../it_can_calculate_nicaragua_holidays.snap | 42 +++++++++++++++++++ tests/Countries/NicaraguaTest.php | 18 ++++++++ 4 files changed, 103 insertions(+) create mode 100644 src/Countries/Nicaragua.php create mode 100644 tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap create mode 100644 tests/Countries/NicaraguaTest.php diff --git a/.editorconfig b/.editorconfig index a7c44ddb..6f7c0773 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,6 @@ trim_trailing_whitespace = false [*.{yml,yaml}] indent_size = 2 + +[*.snap] +insert_final_newline = false \ No newline at end of file diff --git a/src/Countries/Nicaragua.php b/src/Countries/Nicaragua.php new file mode 100644 index 00000000..d185b59b --- /dev/null +++ b/src/Countries/Nicaragua.php @@ -0,0 +1,40 @@ + '01-01', + 'Día internacional de los trabajadores' => '05-01', + 'Día de las madres' => '05-30', + 'Aniversario de la revolución' => '07-19', + 'Aniversario de la batalla de san jacinto' => '09-14', + 'Aniversario de la independencia' => '09-15', + 'Día de la inmaculada concepción' => '12-08', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Managua'); + + + return [ + 'Jueves santo' => $easter->subDays(3)->format('m-d'), + 'Viernes santo' => $easter->subDays(2)->format('m-d'), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap new file mode 100644 index 00000000..b92235be --- /dev/null +++ b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "A\u00f1o nuevo", + "date": "2024-01-01" + }, + { + "name": "Jueves santo", + "date": "2024-03-28" + }, + { + "name": "Viernes santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda internacional de los trabajadores", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de las madres", + "date": "2024-05-30" + }, + { + "name": "Aniversario de la revoluci\u00f3n", + "date": "2024-07-19" + }, + { + "name": "Aniversario de la batalla de san jacinto", + "date": "2024-09-14" + }, + { + "name": "Aniversario de la independencia", + "date": "2024-09-15" + }, + { + "name": "D\u00eda de la inmaculada concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/NicaraguaTest.php b/tests/Countries/NicaraguaTest.php new file mode 100644 index 00000000..840a0609 --- /dev/null +++ b/tests/Countries/NicaraguaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From d4be094aa6f427d79ae9a8ff08f3cce7dc2aa5fa Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 11:59:30 -0600 Subject: [PATCH 70/95] fixing return for phpstan --- src/Countries/Nicaragua.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Countries/Nicaragua.php b/src/Countries/Nicaragua.php index d185b59b..8614270b 100644 --- a/src/Countries/Nicaragua.php +++ b/src/Countries/Nicaragua.php @@ -31,10 +31,9 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('America/Managua'); - return [ - 'Jueves santo' => $easter->subDays(3)->format('m-d'), - 'Viernes santo' => $easter->subDays(2)->format('m-d'), + 'Jueves santo' => $easter->subDays(3), + 'Viernes santo' => $easter->subDays(2), ]; } } From 1167645b8dddfda299fe09cf268b7c6d84667c8e Mon Sep 17 00:00:00 2001 From: calonzolg Date: Thu, 18 Jan 2024 13:35:35 -0600 Subject: [PATCH 71/95] match utc time --- .../NicaraguaTest/it_can_calculate_nicaragua_holidays.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap index b92235be..572176fc 100644 --- a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap +++ b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap @@ -5,11 +5,11 @@ }, { "name": "Jueves santo", - "date": "2024-03-28" + "date": "2024-03-27" }, { "name": "Viernes santo", - "date": "2024-03-29" + "date": "2024-03-28" }, { "name": "D\u00eda internacional de los trabajadores", From fe983b03074c8b13361e061b578602e521e800b8 Mon Sep 17 00:00:00 2001 From: kndrckjvr Date: Thu, 18 Jan 2024 01:01:00 +0800 Subject: [PATCH 72/95] add philippine's regular holidays * removed comments --- src/Countries/Philippines.php | 41 ++++++++++++++++++ .../it_can_calculate_philippine_holidays.snap | 42 +++++++++++++++++++ tests/Countries/PhilippinesTest.php | 19 +++++++++ 3 files changed, 102 insertions(+) create mode 100644 src/Countries/Philippines.php create mode 100644 tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap create mode 100644 tests/Countries/PhilippinesTest.php diff --git a/src/Countries/Philippines.php b/src/Countries/Philippines.php new file mode 100644 index 00000000..dd4cf848 --- /dev/null +++ b/src/Countries/Philippines.php @@ -0,0 +1,41 @@ + '01-01', + 'Araw ng Kagitingan' => '04-09', + 'Labor Day' => '05-01', + 'Independence Day' => '06-12', + 'Bonifacio Day' => '11-27', + 'Christmas Day' => '12-25', + 'Rizal Day' => '12-30', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $nationalHeroes = new CarbonImmutable("last monday of august {$year}"); + + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Asia/Manila'); + + return [ + 'Maundy Thursday' => $easter->subDays(3), + 'Good Friday' => $easter->subDays(2), + 'National Heroes Day' => $nationalHeroes, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap b/tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap new file mode 100644 index 00000000..0859fcf5 --- /dev/null +++ b/tests/.pest/snapshots/Countries/PhilippinesTest/it_can_calculate_philippine_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Maundy Thursday", + "date": "2024-03-28" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Araw ng Kagitingan", + "date": "2024-04-09" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Independence Day", + "date": "2024-06-12" + }, + { + "name": "National Heroes Day", + "date": "2024-08-26" + }, + { + "name": "Bonifacio Day", + "date": "2024-11-27" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Rizal Day", + "date": "2024-12-30" + } +] \ No newline at end of file diff --git a/tests/Countries/PhilippinesTest.php b/tests/Countries/PhilippinesTest.php new file mode 100644 index 00000000..4fd99717 --- /dev/null +++ b/tests/Countries/PhilippinesTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 13f093958458d7b455f6b0f218b81a9f50d7f521 Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:01:19 +0000 Subject: [PATCH 73/95] Adding Full Mexican Holidays --- src/Countries/Mexico.php | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/Countries/Mexico.php diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php new file mode 100644 index 00000000..c2339775 --- /dev/null +++ b/src/Countries/Mexico.php @@ -0,0 +1,87 @@ + */ + protected function allHolidays(int $year): array + { + + $natalicioBenitoJuarez = new CarbonImmutable(sprintf("third monday of march %s", $year)); + $promulgacionConstitucion = new CarbonImmutable(sprintf("first monday of february %s", $year)); + $revolucionMexicana = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-11-20")->setTimezone('America/Mexico_City'); + + if ($revolucionMexicana->isSunday()) { + $revolucionMexicana = $revolucionMexicana->next('monday'); + } + + $mandatory = [ + 'Año nuevo' => '01-01', + 'Aniversario de la promulgación de la Constitución de 1917' => $promulgacionConstitucion->format('m-d'), + 'Natalicio de Benito Juárez' => $natalicioBenitoJuarez->format('m-d'), + 'Día del Trabajo' => '05-01', + 'Día de la Independencia' => '09-15', + 'Revolución Mexicana' => $revolucionMexicana->format('m-d'), + 'Navidad' => '12-25', + ]; + + if ($this->transmisionPoderEjecutivoFederal($year)) { + $mandatory[ + "Transmisión del Poder Ejecutivo Federal" + ] = $this->transmisionPoderEjecutivoFederal($year); + } + + return array_merge($mandatory, $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + + $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); + + return [ + + 'Día de la Candelaria' => '02-02', + 'Día de la Bandera' => '02-24', + 'Día del Niño' => '04-30', + 'Día de la Madre' => '04-30', + 'Día del Padre' => $fathersDay, + 'Día de la Raza' => '10-12', + 'Día de Muertos' => '11-02', + 'Virgen de Guadalupe' => '12-12', + ]; + } + + + protected function transmisionPoderEjecutivoFederal($year) + { + $period = new CarbonPeriod(); + $period->setDateClass(CarbonImmutable::class); + $period + ->every("6 years") + ->since(sprintf("%s-10-01", 2024)) + ->until(sprintf("%s-10-01 00:00:00", Carbon::now()->addYears(6)->year)); + + $period->addFilter(function ($date) use ($year) { + return $date->year === $year; + }); + + $availableDates = $period->toArray(); + + if (count($availableDates)) { + return $availableDates[0]->format("m-d"); + } + return false; + } +} From 7528c00ef7475dfa8fe0fad8ba9ae34622a4fcff Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:06:15 +0000 Subject: [PATCH 74/95] Add Test --- tests/Countries/MexicoTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/Countries/MexicoTest.php diff --git a/tests/Countries/MexicoTest.php b/tests/Countries/MexicoTest.php new file mode 100644 index 00000000..ac89542a --- /dev/null +++ b/tests/Countries/MexicoTest.php @@ -0,0 +1,19 @@ +Meget(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 00bcc613b0b8fde18527f58701a4aca320c2014f Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:10:30 +0000 Subject: [PATCH 75/95] update test description and remove typo, --- .vscode/settings.json | 5 ++++ src/Countries/Mexico.php | 54 +++++++++++++++++----------------- tests/Countries/MexicoTest.php | 4 +-- 3 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b242572e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] +} \ No newline at end of file diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index c2339775..9c85f523 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -15,6 +15,24 @@ public function countryCode(): string /** @return array */ protected function allHolidays(int $year): array + { + return array_merge([ + 'Año nuevo' => '01-01', + 'Día de la Candelaria' => '02-02', + 'Día de la Bandera' => '02-24', + 'Día del Niño' => '04-30', + 'Día de la Madre' => '04-30', + 'Día del Trabajo' => '05-01', + 'Día de la Independencia' => '09-15', + 'Día de la Raza' => '10-12', + 'Día de Muertos' => '11-02', + 'Virgen de Guadalupe' => '12-12', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array { $natalicioBenitoJuarez = new CarbonImmutable(sprintf("third monday of march %s", $year)); @@ -25,46 +43,28 @@ protected function allHolidays(int $year): array $revolucionMexicana = $revolucionMexicana->next('monday'); } - $mandatory = [ - 'Año nuevo' => '01-01', + $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); + + + $days = [ 'Aniversario de la promulgación de la Constitución de 1917' => $promulgacionConstitucion->format('m-d'), 'Natalicio de Benito Juárez' => $natalicioBenitoJuarez->format('m-d'), - 'Día del Trabajo' => '05-01', - 'Día de la Independencia' => '09-15', 'Revolución Mexicana' => $revolucionMexicana->format('m-d'), - 'Navidad' => '12-25', + 'Día del Padre' => $fathersDay->format('m-d'), + ]; if ($this->transmisionPoderEjecutivoFederal($year)) { - $mandatory[ + $days[ "Transmisión del Poder Ejecutivo Federal" ] = $this->transmisionPoderEjecutivoFederal($year); } - return array_merge($mandatory, $this->variableHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - - $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); - - return [ - - 'Día de la Candelaria' => '02-02', - 'Día de la Bandera' => '02-24', - 'Día del Niño' => '04-30', - 'Día de la Madre' => '04-30', - 'Día del Padre' => $fathersDay, - 'Día de la Raza' => '10-12', - 'Día de Muertos' => '11-02', - 'Virgen de Guadalupe' => '12-12', - ]; + return $days; } - protected function transmisionPoderEjecutivoFederal($year) + protected function transmisionPoderEjecutivoFederal($year): bool|string { $period = new CarbonPeriod(); $period->setDateClass(CarbonImmutable::class); diff --git a/tests/Countries/MexicoTest.php b/tests/Countries/MexicoTest.php index ac89542a..cb2876ae 100644 --- a/tests/Countries/MexicoTest.php +++ b/tests/Countries/MexicoTest.php @@ -1,11 +1,11 @@ -Meget(); From e696676584bbb9a37515573446068e32e64ae0fa Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:12:54 +0000 Subject: [PATCH 76/95] remove vscode folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ff8bfd7e..96b3d690 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .php_cs .php_cs.cache .phpunit.cache +.vscode build composer.lock coverage From 149d3368168a5271da60ded29599a474987c30bf Mon Sep 17 00:00:00 2001 From: davsaniuv <58817543+davsaniuv@users.noreply.github.com> Date: Wed, 17 Jan 2024 11:13:31 -0600 Subject: [PATCH 77/95] Delete .vscode directory --- .vscode/settings.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b242572e..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "githubPullRequests.ignoredPullRequestBranches": [ - "main" - ] -} \ No newline at end of file From 89cdd36317731e4aaa8decb8e42a437e1b41cfbb Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:27:08 +0000 Subject: [PATCH 78/95] Fix styling --- src/Countries/Mexico.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 9c85f523..db745960 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -35,16 +35,15 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { - $natalicioBenitoJuarez = new CarbonImmutable(sprintf("third monday of march %s", $year)); - $promulgacionConstitucion = new CarbonImmutable(sprintf("first monday of february %s", $year)); + $natalicioBenitoJuarez = new CarbonImmutable(sprintf('third monday of march %s', $year)); + $promulgacionConstitucion = new CarbonImmutable(sprintf('first monday of february %s', $year)); $revolucionMexicana = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-11-20")->setTimezone('America/Mexico_City'); if ($revolucionMexicana->isSunday()) { $revolucionMexicana = $revolucionMexicana->next('monday'); } - $fathersDay = new CarbonImmutable(sprintf("third sunday of june %s", $year)); - + $fathersDay = new CarbonImmutable(sprintf('third sunday of june %s', $year)); $days = [ 'Aniversario de la promulgación de la Constitución de 1917' => $promulgacionConstitucion->format('m-d'), @@ -56,22 +55,21 @@ protected function variableHolidays(int $year): array if ($this->transmisionPoderEjecutivoFederal($year)) { $days[ - "Transmisión del Poder Ejecutivo Federal" + 'Transmisión del Poder Ejecutivo Federal' ] = $this->transmisionPoderEjecutivoFederal($year); } return $days; } - protected function transmisionPoderEjecutivoFederal($year): bool|string { $period = new CarbonPeriod(); $period->setDateClass(CarbonImmutable::class); $period - ->every("6 years") - ->since(sprintf("%s-10-01", 2024)) - ->until(sprintf("%s-10-01 00:00:00", Carbon::now()->addYears(6)->year)); + ->every('6 years') + ->since(sprintf('%s-10-01', 2024)) + ->until(sprintf('%s-10-01 00:00:00', Carbon::now()->addYears(6)->year)); $period->addFilter(function ($date) use ($year) { return $date->year === $year; @@ -80,8 +78,9 @@ protected function transmisionPoderEjecutivoFederal($year): bool|string $availableDates = $period->toArray(); if (count($availableDates)) { - return $availableDates[0]->format("m-d"); + return $availableDates[0]->format('m-d'); } + return false; } } From bb3f072a99d24c1c26910578c29479cf4ff06a69 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:31:46 +0100 Subject: [PATCH 79/95] wip --- src/Countries/Nicaragua.php | 3 +-- src/Countries/NorthMacedonia.php | 4 ++-- src/Countries/Philippines.php | 3 +-- src/Countries/Uganda.php | 12 ------------ src/Countries/Venezuela.php | 2 +- 5 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/Countries/Nicaragua.php b/src/Countries/Nicaragua.php index 8614270b..32837f3c 100644 --- a/src/Countries/Nicaragua.php +++ b/src/Countries/Nicaragua.php @@ -28,8 +28,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('America/Managua'); + $easter = $this->easter($year); return [ 'Jueves santo' => $easter->subDays(3), diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 0d4a447f..4ae2e25b 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -29,7 +29,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp($this->ortodoxEaster($year)) + $easter = CarbonImmutable::createFromTimestamp($this->orthodoxEaster($year)) ->setTimezone('Europe/Skopje'); return [ @@ -37,7 +37,7 @@ protected function variableHolidays(int $year): array ]; } - protected function ortodoxEaster(int $year): bool|int + protected function orthodoxEaster(int $year): bool|int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; diff --git a/src/Countries/Philippines.php b/src/Countries/Philippines.php index dd4cf848..c4d193e8 100644 --- a/src/Countries/Philippines.php +++ b/src/Countries/Philippines.php @@ -29,8 +29,7 @@ protected function variableHolidays(int $year): array { $nationalHeroes = new CarbonImmutable("last monday of august {$year}"); - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Asia/Manila'); + $easter = $this->easter($year); return [ 'Maundy Thursday' => $easter->subDays(3), diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 8673698d..90a0af5b 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -1,9 +1,4 @@ Github: LinkedIn: - */ namespace Spatie\Holidays\Countries; @@ -16,15 +11,8 @@ public function countryCode(): string return 'ug'; } - /** - * {@inheritDoc} - */ protected function allHolidays(int $year): array { - - /** - * 'New Year' => '01-01', Format:: Month-Date - */ return array_merge([ "New Year's Day" => '01-01', 'NRM Liberation Day' => '01-26', diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php index bda60ac9..01edb601 100644 --- a/src/Countries/Venezuela.php +++ b/src/Countries/Venezuela.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)); + $easter = $this->easter($year); return [ 'Lunes de Carnaval' => $easter->subDays(47), From fedc663787a7e72d5edd71264664a8f70dec8618 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:39:13 +0100 Subject: [PATCH 80/95] fix test --- src/Countries/Mexico.php | 2 +- .../it_can_calculate_mexico_holidays.snap | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index db745960..78effd74 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -6,7 +6,7 @@ use Carbon\CarbonImmutable; use Carbon\CarbonPeriod; -class Netherlands extends Country +class Mexico extends Country { public function countryCode(): string { diff --git a/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap b/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap new file mode 100644 index 00000000..ecafb2e0 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MexicoTest/it_can_calculate_mexico_holidays.snap @@ -0,0 +1,66 @@ +[ + { + "name": "A\u00f1o nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda de la Candelaria", + "date": "2024-02-02" + }, + { + "name": "Aniversario de la promulgaci\u00f3n de la Constituci\u00f3n de 1917", + "date": "2024-02-05" + }, + { + "name": "D\u00eda de la Bandera", + "date": "2024-02-24" + }, + { + "name": "Natalicio de Benito Ju\u00e1rez", + "date": "2024-03-18" + }, + { + "name": "D\u00eda del Ni\u00f1o", + "date": "2024-04-30" + }, + { + "name": "D\u00eda de la Madre", + "date": "2024-04-30" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "D\u00eda del Padre", + "date": "2024-06-16" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-09-15" + }, + { + "name": "Transmisi\u00f3n del Poder Ejecutivo Federal", + "date": "2024-10-01" + }, + { + "name": "D\u00eda de la Raza", + "date": "2024-10-12" + }, + { + "name": "D\u00eda de Muertos", + "date": "2024-11-02" + }, + { + "name": "Revoluci\u00f3n Mexicana", + "date": "2024-11-19" + }, + { + "name": "Virgen de Guadalupe", + "date": "2024-12-12" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file From cd8854dc11d89837c4fd3a6e5f2dd797a7df0213 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 19 Jan 2024 14:45:44 +0100 Subject: [PATCH 81/95] wip --- src/Countries/Country.php | 3 ++- src/Countries/Venezuela.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 2c554702..9416ca65 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -42,7 +42,8 @@ public static function make(): static protected function easter(string $year): CarbonImmutable { - $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21"); + $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21") + ->startOfDay(); return $easter->addDays(easter_days($year)); } diff --git a/src/Countries/Venezuela.php b/src/Countries/Venezuela.php index 01edb601..10082f44 100644 --- a/src/Countries/Venezuela.php +++ b/src/Countries/Venezuela.php @@ -33,8 +33,8 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); return [ - 'Lunes de Carnaval' => $easter->subDays(47), - 'Martes de Carnaval' => $easter->subDays(46), + 'Lunes de Carnaval' => $easter->subDays(48), + 'Martes de Carnaval' => $easter->subDays(42), 'Jueves Santo' => $easter->subDays(3), 'Viernes Santo' => $easter->subDays(2), ]; From 82ad417266cce414e8e2bc9ab2aa112797622e47 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Fri, 19 Jan 2024 13:46:12 +0000 Subject: [PATCH 82/95] Fix styling --- src/Countries/Country.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 9416ca65..82d5d882 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -43,7 +43,7 @@ public static function make(): static protected function easter(string $year): CarbonImmutable { $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21") - ->startOfDay(); + ->startOfDay(); return $easter->addDays(easter_days($year)); } From daf469cd8aaaf72d1d7d6f838d3925c69950f33a Mon Sep 17 00:00:00 2001 From: Marc Hanlon Date: Fri, 19 Jan 2024 14:27:22 +0000 Subject: [PATCH 83/95] Add support for Irish public holidays (#44) * Add support for Irish public holidays * Add logic that St Brigid's only started from 2023 * Add tests for St Brigid's Day St Brigids Day is a new holiday in 2023 and it is variable so adding tests around the logic * Apply PSR12 formatting --- src/Countries/Ireland.php | 54 +++++++++++++++++++ .../it_can_calculate_irish_holidays.snap | 42 +++++++++++++++ tests/Countries/IrelandTest.php | 29 ++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/Countries/Ireland.php create mode 100644 tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap create mode 100644 tests/Countries/IrelandTest.php diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php new file mode 100644 index 00000000..a75428ce --- /dev/null +++ b/src/Countries/Ireland.php @@ -0,0 +1,54 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'New Year\'s Day' => '01-01', + 'Saint Patrick\'s Day' => '03-17', + 'Christmas Day' => '12-25', + 'Saint Stephen\'s Day' => '12-26' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Europe/Dublin'); + $mayHoliday = new CarbonImmutable("first monday of May $year", 'Europe/Dublin'); + $juneHoliday = new CarbonImmutable("first monday of June $year", 'Europe/Dublin'); + $augHoliday = new CarbonImmutable("first monday of August $year", 'Europe/Dublin'); + $octHoliday = new CarbonImmutable("last monday of October $year", 'Europe/Dublin'); + + $variableHolidays = [ + 'Easter Monday' => $easter->addDays(1), + 'May Public Holiday' => $mayHoliday, + 'June Public Holiday' => $juneHoliday, + 'August Public Holiday' => $augHoliday, + 'October Public Holiday' => $octHoliday + ]; + + // In 2023, Ireland added a new public holiday for St Brigid's day. + // It is the First Monday in February, or 1 February if the date falls on a Friday + if ($year >= 2023) { + $stBrigidsDay = new CarbonImmutable("$year-02-01", 'Europe/Dublin'); + if (!$stBrigidsDay->isFriday()) { + $stBrigidsDay = new CarbonImmutable("first monday of February $year", 'Europe/Dublin'); + } + $variableHolidays['St Brigid\'s Day'] = $stBrigidsDay; + } + + return $variableHolidays; + } +} diff --git a/tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap b/tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap new file mode 100644 index 00000000..5d241806 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IrelandTest/it_can_calculate_irish_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "St Brigid's Day", + "date": "2024-02-05" + }, + { + "name": "Saint Patrick's Day", + "date": "2024-03-17" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Public Holiday", + "date": "2024-05-06" + }, + { + "name": "June Public Holiday", + "date": "2024-06-03" + }, + { + "name": "August Public Holiday", + "date": "2024-08-05" + }, + { + "name": "October Public Holiday", + "date": "2024-10-28" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Saint Stephen's Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/IrelandTest.php b/tests/Countries/IrelandTest.php new file mode 100644 index 00000000..6ed63548 --- /dev/null +++ b/tests/Countries/IrelandTest.php @@ -0,0 +1,29 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate St Bridid\'s day in Ireland', function () { + // In 2022, there was no St Brigid's Day + expect(Holidays::for(country: 'ie')->isHoliday('2022-02-07'))->toBe(false); + + // In 2023, it was on Monday 6th Feb + expect(Holidays::for(country: 'ie')->isHoliday('2023-02-06'))->toBe(true); + + // In 2030, it will fall on Friday 1st Feb + expect(Holidays::for(country: 'ie')->isHoliday('2030-02-01'))->toBe(true); +}); From d59c1d53ef0623add4902fca732bda3eb79d9ffd Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 14:27:41 +0000 Subject: [PATCH 84/95] Fix styling --- src/Countries/Ireland.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index a75428ce..6d3c53b1 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -18,7 +18,7 @@ protected function allHolidays(int $year): array 'New Year\'s Day' => '01-01', 'Saint Patrick\'s Day' => '03-17', 'Christmas Day' => '12-25', - 'Saint Stephen\'s Day' => '12-26' + 'Saint Stephen\'s Day' => '12-26', ], $this->variableHolidays($year)); } @@ -36,14 +36,14 @@ protected function variableHolidays(int $year): array 'May Public Holiday' => $mayHoliday, 'June Public Holiday' => $juneHoliday, 'August Public Holiday' => $augHoliday, - 'October Public Holiday' => $octHoliday + 'October Public Holiday' => $octHoliday, ]; // In 2023, Ireland added a new public holiday for St Brigid's day. // It is the First Monday in February, or 1 February if the date falls on a Friday if ($year >= 2023) { $stBrigidsDay = new CarbonImmutable("$year-02-01", 'Europe/Dublin'); - if (!$stBrigidsDay->isFriday()) { + if (! $stBrigidsDay->isFriday()) { $stBrigidsDay = new CarbonImmutable("first monday of February $year", 'Europe/Dublin'); } $variableHolidays['St Brigid\'s Day'] = $stBrigidsDay; From 5f4e4bb3b777dd7b5abc6075a748104c1c8f9ea9 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:53:46 +0100 Subject: [PATCH 85/95] use better easter calculation for Ireland --- src/Countries/Ireland.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 6d3c53b1..527cd487 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'ie'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -25,7 +24,8 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Europe/Dublin'); + $easter = $this->easter($year); + $mayHoliday = new CarbonImmutable("first monday of May $year", 'Europe/Dublin'); $juneHoliday = new CarbonImmutable("first monday of June $year", 'Europe/Dublin'); $augHoliday = new CarbonImmutable("first monday of August $year", 'Europe/Dublin'); From e427e24e5f1a617f0e5f13a49e613e2c1cbf0cdf Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:56:50 +0100 Subject: [PATCH 86/95] use correct dates for nicaragua and venezuela --- .../NicaraguaTest/it_can_calculate_nicaragua_holidays.snap | 4 ++-- .../VenezuelaTest/it_can_calculate_venezuelan_holidays.snap | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap index 572176fc..b92235be 100644 --- a/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap +++ b/tests/.pest/snapshots/Countries/NicaraguaTest/it_can_calculate_nicaragua_holidays.snap @@ -5,11 +5,11 @@ }, { "name": "Jueves santo", - "date": "2024-03-27" + "date": "2024-03-28" }, { "name": "Viernes santo", - "date": "2024-03-28" + "date": "2024-03-29" }, { "name": "D\u00eda internacional de los trabajadores", diff --git a/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap index 1c867bd6..dd3850a4 100644 --- a/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap +++ b/tests/.pest/snapshots/Countries/VenezuelaTest/it_can_calculate_venezuelan_holidays.snap @@ -9,15 +9,15 @@ }, { "name": "Martes de Carnaval", - "date": "2024-02-13" + "date": "2024-02-18" }, { "name": "Jueves Santo", - "date": "2024-03-27" + "date": "2024-03-28" }, { "name": "Viernes Santo", - "date": "2024-03-28" + "date": "2024-03-29" }, { "name": "Declaraci\u00f3n de la Independencia", From 098556f6200fdfdc1432006bafb26a900ec7fca6 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:13:19 +0100 Subject: [PATCH 87/95] cleanup --- src/Countries/Austria.php | 5 ----- src/Countries/Country.php | 2 +- src/Countries/Mexico.php | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Countries/Austria.php b/src/Countries/Austria.php index 5041c401..36ddb41b 100644 --- a/src/Countries/Austria.php +++ b/src/Countries/Austria.php @@ -6,11 +6,6 @@ class Austria extends Country { - protected function __construct( - public ?string $region = null - ) { - } - public function countryCode(): string { return 'at'; diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 82d5d882..1c74eb6e 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -40,7 +40,7 @@ public static function make(): static return new static(...func_get_args()); } - protected function easter(string $year): CarbonImmutable + protected function easter(int $year): CarbonImmutable { $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21") ->startOfDay(); diff --git a/src/Countries/Mexico.php b/src/Countries/Mexico.php index 78effd74..21b25f10 100644 --- a/src/Countries/Mexico.php +++ b/src/Countries/Mexico.php @@ -13,7 +13,6 @@ public function countryCode(): string return 'mx'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ From b65633bf5adf4001528ceae56e01c7e92a498e06 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:15:06 +0100 Subject: [PATCH 88/95] move to baseline --- phpstan-baseline.neon | 21 ++++++++++++++++++--- src/Countries/NorthMacedonia.php | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 51b9330f..7de51241 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,12 +1,12 @@ parameters: ignoreErrors: - - message: "#^Unreachable statement \\- code above always terminates\\.$#" + message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 - path: src/Countries/Brazil.php + path: src/Countries/Country.php - - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" + message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 path: src/Countries/Country.php @@ -20,6 +20,21 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Cannot call method setTimezone\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 1 + path: src/Countries/Mexico.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:transmisionPoderEjecutivoFederal\\(\\) has parameter \\$year with no type specified\\.$#" + count: 1 + path: src/Countries/Mexico.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" + count: 1 + path: src/Countries/Mexico.php + - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 4ae2e25b..9865e3c3 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -37,11 +37,11 @@ protected function variableHolidays(int $year): array ]; } - protected function orthodoxEaster(int $year): bool|int + protected function orthodoxEaster(int $year): int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - return strtotime("+$daysDifference days", $timestamp); + return (int) strtotime("+$daysDifference days", $timestamp); } } From dd21d895da02d1a255b27a2312f5e1a376a3d256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frano=20Bara=C4=87?= Date: Fri, 19 Jan 2024 16:19:42 +0100 Subject: [PATCH 89/95] Add support for Croatian public holidays (#45) * adds croatian holidays * stan fixes * fixed allHolidays return type --- src/Countries/Croatia.php | 43 +++++++++++++++ .../it_can_calculate_croatian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/CroatiaTest.php | 18 +++++++ 3 files changed, 115 insertions(+) create mode 100644 src/Countries/Croatia.php create mode 100644 tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap create mode 100644 tests/Countries/CroatiaTest.php diff --git a/src/Countries/Croatia.php b/src/Countries/Croatia.php new file mode 100644 index 00000000..d95906f7 --- /dev/null +++ b/src/Countries/Croatia.php @@ -0,0 +1,43 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Nova godina' => '01-01', + 'Bogojavljenje' => '01-06', + 'Praznik rada' => '05-01', + 'Dan državnosti' => '05-30', + 'Dan antifašističke borbe' => '06-22', + 'Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja' => '08-05', + 'Velika Gospa' => '08-15', + 'Svi sveti' => '11-01', + 'Dan sjećanja na žrtve Domovinskog rata i Dan sjećanja na žrtvu Vukovara i Škabrnje' => '11-18', + 'Božić' => '12-25', + 'Sveti Stjepan' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Zagreb'); + + return [ + 'Uskrsni ponedjeljak' => $easter->addDay(), + 'Tijelovo' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap new file mode 100644 index 00000000..821ad707 --- /dev/null +++ b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Nova godina", + "date": "2024-01-01" + }, + { + "name": "Bogojavljenje", + "date": "2024-01-06" + }, + { + "name": "Uskrsni ponedjeljak", + "date": "2024-04-01" + }, + { + "name": "Praznik rada", + "date": "2024-05-01" + }, + { + "name": "Tijelovo", + "date": "2024-05-30" + }, + { + "name": "Dan dr\u017eavnosti", + "date": "2024-05-30" + }, + { + "name": "Dan antifa\u0161isti\u010dke borbe", + "date": "2024-06-22" + }, + { + "name": "Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja", + "date": "2024-08-05" + }, + { + "name": "Velika Gospa", + "date": "2024-08-15" + }, + { + "name": "Svi sveti", + "date": "2024-11-01" + }, + { + "name": "Dan sje\u0107anja na \u017ertve Domovinskog rata i Dan sje\u0107anja na \u017ertvu Vukovara i \u0160kabrnje", + "date": "2024-11-18" + }, + { + "name": "Bo\u017ei\u0107", + "date": "2024-12-25" + }, + { + "name": "Sveti Stjepan", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/CroatiaTest.php b/tests/Countries/CroatiaTest.php new file mode 100644 index 00000000..a78f5258 --- /dev/null +++ b/tests/Countries/CroatiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 774279de09296c73ae398d074c9f2da5f0f1e325 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:23:47 +0100 Subject: [PATCH 90/95] use easter() instead --- src/Countries/Croatia.php | 4 +--- .../it_can_calculate_croatian_holidays.snap | 4 ++-- tests/Countries/AustriaTest.php | 12 ------------ 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Countries/Croatia.php b/src/Countries/Croatia.php index d95906f7..f5d7b7c8 100644 --- a/src/Countries/Croatia.php +++ b/src/Countries/Croatia.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'hr'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -32,8 +31,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Zagreb'); + $easter = $this->easter($year); return [ 'Uskrsni ponedjeljak' => $easter->addDay(), diff --git a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap index 821ad707..206f0784 100644 --- a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap +++ b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap @@ -16,11 +16,11 @@ "date": "2024-05-01" }, { - "name": "Tijelovo", + "name": "Dan dr\u017eavnosti", "date": "2024-05-30" }, { - "name": "Dan dr\u017eavnosti", + "name": "Tijelovo", "date": "2024-05-30" }, { diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 3473abef..74794306 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -17,15 +17,3 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - -it('can calculate austrian holidays with region holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); - - $holidays = Holidays::for(Austria::make('bg'))->get(); - - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); - - expect(formatDates($holidays))->toMatchSnapshot(); -})->skip('Austria class has to be extended with regions first.'); From d6dee65a25b4cd36647b91c690edbeedb873b7fa Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 15:24:06 +0000 Subject: [PATCH 91/95] Fix styling --- tests/Countries/AustriaTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 74794306..9018307f 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Countries\Austria; use Spatie\Holidays\Holidays; it('can calculate austrian holidays', function () { From 2cf012981aad2af963e0f4d4f423267f6d05cdda Mon Sep 17 00:00:00 2001 From: rats4final <80012704+rats4final@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:26:58 -0400 Subject: [PATCH 92/95] Bolivian holidays (#40) * feature: add bolivian holidays * test: add bolivia test * test snap * fixed typo and phpstan * calculate correct easter date * Fix styling --------- Co-authored-by: rats4final Co-authored-by: rats4final --- src/Countries/Bolivia.php | 39 ++++++++++++++++ .../it_can_calculate_bolivian_holidays.snap | 46 +++++++++++++++++++ tests/Countries/BoliviaTest.php | 18 ++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/Countries/Bolivia.php create mode 100644 tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap create mode 100644 tests/Countries/BoliviaTest.php diff --git a/src/Countries/Bolivia.php b/src/Countries/Bolivia.php new file mode 100644 index 00000000..977d9bfa --- /dev/null +++ b/src/Countries/Bolivia.php @@ -0,0 +1,39 @@ + '01-01', + 'Día del Estado Plurinacional' => '01-22', + 'Día del Trabajador' => '05-01', + 'Año Nuevo Aymara' => '06-21', + 'Día de la Independencia' => '08-06', + 'Día de Todos los Santos' => '11-02', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter((string) $year); + + return [ + 'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6), + 'Martes de Carnaval' => $easter->subWeeks(6)->subDays(5), + 'Viernes Santo' => $easter->subDays(2), + 'Corpus Christi' => $easter->addWeeks(8)->addDays(4), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap b/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap new file mode 100644 index 00000000..c169618c --- /dev/null +++ b/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "D\u00eda de A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda del Estado Plurinacional", + "date": "2024-01-22" + }, + { + "name": "Lunes de Carnaval", + "date": "2024-02-12" + }, + { + "name": "Martes de Carnaval", + "date": "2024-02-13" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Corpus Christi", + "date": "2024-05-30" + }, + { + "name": "A\u00f1o Nuevo Aymara", + "date": "2024-06-21" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-08-06" + }, + { + "name": "D\u00eda de Todos los Santos", + "date": "2024-11-02" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BoliviaTest.php b/tests/Countries/BoliviaTest.php new file mode 100644 index 00000000..e1305657 --- /dev/null +++ b/tests/Countries/BoliviaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); + +}); From 083026e7a9bf3320c8aee40a0fef6f82e983f49f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:27:30 +0100 Subject: [PATCH 93/95] remove unneeded conversion --- src/Countries/Bolivia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Bolivia.php b/src/Countries/Bolivia.php index 977d9bfa..94072ed0 100644 --- a/src/Countries/Bolivia.php +++ b/src/Countries/Bolivia.php @@ -27,7 +27,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter((string) $year); + $easter = $this->easter($year); return [ 'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6), From a6f754b98d92f926a26346f7f3db4f6710df086a Mon Sep 17 00:00:00 2001 From: Jaanus Vapper Date: Fri, 19 Jan 2024 17:46:23 +0200 Subject: [PATCH 94/95] Add Estonian holidays (#47) * Add Estonian holidays * Use easter() method for easter date --- src/Countries/Estonia.php | 40 +++++++++++++++ .../it_can_calculate_estonian_holidays.snap | 50 +++++++++++++++++++ tests/Countries/EstoniaTest.php | 18 +++++++ 3 files changed, 108 insertions(+) create mode 100644 src/Countries/Estonia.php create mode 100644 tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap create mode 100644 tests/Countries/EstoniaTest.php diff --git a/src/Countries/Estonia.php b/src/Countries/Estonia.php new file mode 100644 index 00000000..4ba7efcd --- /dev/null +++ b/src/Countries/Estonia.php @@ -0,0 +1,40 @@ + '01-01', + 'Iseseisvuspäev' => '02-24', + 'Kevadpüha' => '05-01', + 'Võidupüha' => '06-23', + 'Jaanipäev' => '06-24', + 'Taasiseseisvumispäev' => '08-20', + 'Jõululaupäev' => '12-24', + 'Esimene jõulupüha' => '12-25', + 'Teine jõulupüha' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Suur reede' => $easter->subDays(2), + 'Ülestõusmispühade 1. püha' => $easter, + 'Nelipühade 1. püha' => $easter->addDays(49), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap b/tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap new file mode 100644 index 00000000..bbd7f3c1 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EstoniaTest/it_can_calculate_estonian_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Uusaasta", + "date": "2024-01-01" + }, + { + "name": "Iseseisvusp\u00e4ev", + "date": "2024-02-24" + }, + { + "name": "Suur reede", + "date": "2024-03-29" + }, + { + "name": "\u00dclest\u00f5usmisp\u00fchade 1. p\u00fcha", + "date": "2024-03-31" + }, + { + "name": "Kevadp\u00fcha", + "date": "2024-05-01" + }, + { + "name": "Nelip\u00fchade 1. p\u00fcha", + "date": "2024-05-19" + }, + { + "name": "V\u00f5idup\u00fcha", + "date": "2024-06-23" + }, + { + "name": "Jaanip\u00e4ev", + "date": "2024-06-24" + }, + { + "name": "Taasiseseisvumisp\u00e4ev", + "date": "2024-08-20" + }, + { + "name": "J\u00f5ululaup\u00e4ev", + "date": "2024-12-24" + }, + { + "name": "Esimene j\u00f5ulup\u00fcha", + "date": "2024-12-25" + }, + { + "name": "Teine j\u00f5ulup\u00fcha", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/EstoniaTest.php b/tests/Countries/EstoniaTest.php new file mode 100644 index 00000000..c7ee1aa0 --- /dev/null +++ b/tests/Countries/EstoniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 1c519e1f58bf35ce5af4058837bb5fd9b4a6326b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20Filipic=CC=8C?= Date: Fri, 19 Jan 2024 17:45:30 +0100 Subject: [PATCH 95/95] Easter method corrected after rebase --- src/Countries/Slovenia.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php index d84fff3d..1ed8f5c7 100644 --- a/src/Countries/Slovenia.php +++ b/src/Countries/Slovenia.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'si'; } - /** @return array */ protected function allHolidays(int $year): array { @@ -34,8 +33,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Ljubljana'); + $easter = $this->easter($year); return [ 'Velikonočni ponedeljek' => $easter->addDay(), // Easter Monday