From 7d54b6a661dda4dea1916608f2fed2394365abf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Conny=20Sj=C3=B6blom?= Date: Thu, 18 Jan 2024 11:55:09 +0200 Subject: [PATCH 01/25] Add holidays for Finland --- src/Countries/Finland.php | 54 +++++++++++++++++++ .../it_can_calculate_finnish_holidays.snap | 54 +++++++++++++++++++ tests/Countries/FinlandTest.php | 19 +++++++ 3 files changed, 127 insertions(+) create mode 100644 src/Countries/Finland.php create mode 100644 tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap create mode 100644 tests/Countries/FinlandTest.php diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php new file mode 100644 index 000000000..94c8b9713 --- /dev/null +++ b/src/Countries/Finland.php @@ -0,0 +1,54 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge($this->fixedHolidays($year), $this->variableHolidays($year)); + } + + /** @return array */ + protected function fixedHolidays(int $year): array + { + return [ + 'Uudenvuodenpäivä' => CarbonImmutable::create($year, 1, 1), + 'Loppiainen' => CarbonImmutable::create($year, 1, 6), + 'Vappu' => CarbonImmutable::create($year, 5, 1), + 'Itsenäisyyspäivä' => CarbonImmutable::create($year, 12, 6), + 'Joulupäivä' => CarbonImmutable::create($year, 12, 25), + 'Tapaninpäivä' => CarbonImmutable::create($year, 12, 26), + ]; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Stockholm'); + + $midsummerDay = CarbonImmutable::create($year, 6, 20)->next(CarbonImmutable::SATURDAY); + + return [ + 'Pitkäperjantai' => $easter->subDays(2), + 'Pääsiäispäivä' => $easter, + 'Toinen pääsiäispäivä' => $easter->addDay(), + 'Helatorstai' => $easter->addDays(39), + 'Helluntaipäivä' => $easter->addDays(49), + 'Juhannuspäivä' => $midsummerDay->day > 26 + ? $midsummerDay->subWeek() + : $midsummerDay, + 'Pyhäinpäivä' => CarbonImmutable::create($year, 10, 31) + ->next(CarbonImmutable::SATURDAY), + ]; + } +} \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap b/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap new file mode 100644 index 000000000..7613e9bc3 --- /dev/null +++ b/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Uudenvuodenp\u00e4iv\u00e4", + "date": "2024-01-01" + }, + { + "name": "Loppiainen", + "date": "2024-01-06" + }, + { + "name": "Pitk\u00e4perjantai", + "date": "2024-03-28" + }, + { + "name": "P\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", + "date": "2024-03-30" + }, + { + "name": "Toinen p\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", + "date": "2024-03-31" + }, + { + "name": "Vappu", + "date": "2024-05-01" + }, + { + "name": "Helatorstai", + "date": "2024-05-08" + }, + { + "name": "Helluntaip\u00e4iv\u00e4", + "date": "2024-05-18" + }, + { + "name": "Juhannusp\u00e4iv\u00e4", + "date": "2024-06-22" + }, + { + "name": "Pyh\u00e4inp\u00e4iv\u00e4", + "date": "2024-11-02" + }, + { + "name": "Itsen\u00e4isyysp\u00e4iv\u00e4", + "date": "2024-12-06" + }, + { + "name": "Joulup\u00e4iv\u00e4", + "date": "2024-12-25" + }, + { + "name": "Tapaninp\u00e4iv\u00e4", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/FinlandTest.php b/tests/Countries/FinlandTest.php new file mode 100644 index 000000000..4cfd6c474 --- /dev/null +++ b/tests/Countries/FinlandTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); \ No newline at end of file From 000e248f26317c04557ef7806bfcba65ceaf08c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Conny=20Sj=C3=B6blom?= Date: Thu, 18 Jan 2024 12:05:12 +0200 Subject: [PATCH 02/25] Set timezone in test correctly --- src/Countries/Finland.php | 4 ++-- .../FinlandTest/it_can_calculate_finnish_holidays.snap | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 94c8b9713..a25f98f7e 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -34,7 +34,7 @@ protected function fixedHolidays(int $year): array protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Stockholm'); + ->setTimezone('Europe/Helsinki'); $midsummerDay = CarbonImmutable::create($year, 6, 20)->next(CarbonImmutable::SATURDAY); @@ -51,4 +51,4 @@ protected function variableHolidays(int $year): array ->next(CarbonImmutable::SATURDAY), ]; } -} \ No newline at end of file +} diff --git a/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap b/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap index 7613e9bc3..8a4f7a954 100644 --- a/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap +++ b/tests/.pest/snapshots/Countries/FinlandTest/it_can_calculate_finnish_holidays.snap @@ -9,15 +9,15 @@ }, { "name": "Pitk\u00e4perjantai", - "date": "2024-03-28" + "date": "2024-03-29" }, { "name": "P\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", - "date": "2024-03-30" + "date": "2024-03-31" }, { "name": "Toinen p\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", - "date": "2024-03-31" + "date": "2024-04-01" }, { "name": "Vappu", @@ -25,11 +25,11 @@ }, { "name": "Helatorstai", - "date": "2024-05-08" + "date": "2024-05-09" }, { "name": "Helluntaip\u00e4iv\u00e4", - "date": "2024-05-18" + "date": "2024-05-19" }, { "name": "Juhannusp\u00e4iv\u00e4", From 7f24feceb5e35bf2c77279f8e570a70f391636de 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 03/25] 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 12f5b0ff3..e41ea2ffd 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 c8eea5d62..b03a22e52 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 b99262a5c..2c875aa7f 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 000000000..67cda42e4 --- /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 9018307f2..3473abef1 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 b36e00a5cf5bb81e495755253c2ea4d759db4843 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 04/25] 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 67cda42e4..000000000 --- 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 ff686719c9ccad9f8f8d51ddb20f81197f58d808 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 05/25] edit readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e41ea2ffd..09dec13f8 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 ee64dc54f2ce8eb5763e57ba73e6704b14980548 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Thu, 18 Jan 2024 11:00:05 +0100 Subject: [PATCH 06/25] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 09dec13f8..479ae5497 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 60684bb262058f832777764156f884706c4663ff 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 07/25] 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 40f94f7ef..1d1a8ab5d 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 19e342ca5..51615e690 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 b03a22e52..73fb61285 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 f5d268db5..af52b6810 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 4c93f100b..479d78360 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 2c875aa7f..8b75b8dfd 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 8a6467455..15a46e997 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 c79223dd0..427c670d9 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 1c443ee69ebb60da825f1faea59937d10f94f4e9 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 08/25] 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 60ce66b64..e171b0463 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 14315473c..c15c8423e 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 3a1b3ffe3956e996bbf136e86658da4beaccffe0 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 09/25] 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 cd4239c24..30e62c774 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 c15c8423e..77a34a44d 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 0fc1413e1b3b1be2ba25abc03b8ee1f59a750faa 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 10/25] 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 479d78360..19b9af7a0 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 91be74d40..a91509ffb 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 fa7996fcc022b7f18177c2cf19b7f48f5d5eb26c 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 11/25] ignore issue --- phpstan-baseline.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1d1a8ab5d..51b9330fc 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 4c114a87ce8223663de2772ba6947e2614036a00 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 12/25] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 479ae5497..44af97b77 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 2c71a2cca2c608c87f56b5d0a85cdbf130d3505f Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:42:45 +0100 Subject: [PATCH 13/25] 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 000000000..e1d625105 --- /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 000000000..dc01757ce --- /dev/null +++ b/tests/DenmarkTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 859f0585ed9257d21fba221427b154af6c5d5672 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:49:40 +0100 Subject: [PATCH 14/25] 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 e1d625105..152bf2290 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 8e684740b2cd1c5779695842b1ddcefee343d9c9 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 14:58:16 +0100 Subject: [PATCH 15/25] 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 152bf2290..0852bfebc 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 dbe37bd2afc43a7934d8139ca053ade03dc5a79f Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 17 Jan 2024 15:02:15 +0100 Subject: [PATCH 16/25] 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 000000000..7fa897a91 --- /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 1328b81c0d973388b4627df9fff36160860abea2 Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 18 Jan 2024 09:15:59 +0100 Subject: [PATCH 17/25] 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 0852bfebc..3c8a6976e 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 7fa897a91..b19f23c2d 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 4336cdd7004138b1cbf2a4c097623132714fcfac Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 18 Jan 2024 09:24:01 +0100 Subject: [PATCH 18/25] 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 a4377ce4bbd35d13048c078a5fec3f90b2760f26 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 18 Jan 2024 11:15:02 +0000 Subject: [PATCH 19/25] 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 3c8a6976e..4e7ef6f74 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 cee5b4895e6f623ba49bc64bbfd4673fac9a2e3f 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 20/25] 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 4e7ef6f74..66d2113a6 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 9e2c1d83c493f45b47d264dc299843cd7530991a 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 21/25] 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 aa1da0465..91002ed8c 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 000000000..16d5e4724 --- /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 8158609a1bac3af5a79fc3a021e705460a0cc95e Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 18 Jan 2024 12:49:50 +0000 Subject: [PATCH 22/25] Fix styling --- playground.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/playground.php b/playground.php index 16d5e4724..c53856a26 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 5cc61d118740ffdc2624a893959e19667ca66511 Mon Sep 17 00:00:00 2001 From: Rick de Boer Date: Thu, 18 Jan 2024 08:51:32 +0100 Subject: [PATCH 23/25] 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 427c670d9..b694c25cc 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 4e1b1615a4c96e1812c4828b00f8e670f7d666db 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 24/25] 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 3257dd423..7ba840be8 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 bafc6291170484863f6d6423a4a9095c4bca9fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Conny=20Sj=C3=B6blom?= Date: Thu, 18 Jan 2024 17:49:17 +0200 Subject: [PATCH 25/25] Remove PHPDoc --- src/Countries/Finland.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index a25f98f7e..00b810fe8 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'fi'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge($this->fixedHolidays($year), $this->variableHolidays($year));