From eb53eab8b5cbfd0dc9f51cc6754bc2cf4d0e8aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Thu, 18 Jan 2024 21:19:42 +0100 Subject: [PATCH 01/99] Add Slovakia holidays --- src/Countries/Slovakia.php | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Countries/Slovakia.php diff --git a/src/Countries/Slovakia.php b/src/Countries/Slovakia.php new file mode 100644 index 000000000..f400d349b --- /dev/null +++ b/src/Countries/Slovakia.php @@ -0,0 +1,44 @@ + '01-01', + 'Zjavenie Pána (Traja králi)' => '01-06', + 'Sviatok práce' => '05-01', + 'Deň víťazstva nad fašizmom' => '05-08', + 'Sviatok svätého Cyrila a Metoda' => '07-05', + 'Výročie Výročie Slovenského národného povstania' => '08-29', + 'Deň Ústavy Slovenskej republiky' => '09-01', + 'Sedembolestná Panna Mária' => '09-15', + 'Deň vzniku samostatného česko-slovenského štátu' => '10-28', + 'Sviatok všetkých svätých' => '11-01', + 'Deň boja za slobodu a demokraciu' => '11-17', + 'Štedrý deň' => '12-24', + 'Prvý sviatok vianočný' => '12-25', + 'Druhý sviatok vianočný' => '12-26', + ], $this->variableHolidays($year)); + } + + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Bratislava'); + + return [ + 'Veľkonočný pondelok' => $easter->addDay(), + 'Veľký piatok' => $easter->subDays(2), + ]; + } +} From bff08d203d1393100aa6ea236599c21868d2cbe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Thu, 18 Jan 2024 21:20:05 +0100 Subject: [PATCH 02/99] Add Slovakia test --- .../it_can_calculate_slovak_holidays.snap | 66 +++++++++++++++++++ tests/Countries/SlovakiaTest.php | 18 +++++ 2 files changed, 84 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap create mode 100644 tests/Countries/SlovakiaTest.php diff --git a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap new file mode 100644 index 000000000..2aa7ea1fd --- /dev/null +++ b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap @@ -0,0 +1,66 @@ +[ + { + "name": "De\u0148 vzniku Slovenskej republiky", + "date": "2024-01-01" + }, + { + "name": "Zjavenie P\u00e1na (Traja kr\u00e1li)", + "date": "2024-01-06" + }, + { + "name": "Ve\u013ek\u00fd piatok", + "date": "2024-03-29" + }, + { + "name": "Ve\u013ekono\u010dn\u00fd pondelok", + "date": "2024-04-01" + }, + { + "name": "Sviatok pr\u00e1ce", + "date": "2024-05-01" + }, + { + "name": "De\u0148 v\u00ed\u0165azstva nad fa\u0161izmom", + "date": "2024-05-08" + }, + { + "name": "Sviatok sv\u00e4t\u00e9ho Cyrila a Metoda", + "date": "2024-07-05" + }, + { + "name": "V\u00fdro\u010die V\u00fdro\u010die Slovensk\u00e9ho n\u00e1rodn\u00e9ho povstania", + "date": "2024-08-29" + }, + { + "name": "De\u0148 \u00dastavy Slovenskej republiky", + "date": "2024-09-01" + }, + { + "name": "Sedembolestn\u00e1 Panna M\u00e1ria", + "date": "2024-09-15" + }, + { + "name": "De\u0148 vzniku samostatn\u00e9ho \u010desko-slovensk\u00e9ho \u0161t\u00e1tu", + "date": "2024-10-28" + }, + { + "name": "Sviatok v\u0161etk\u00fdch sv\u00e4t\u00fdch", + "date": "2024-11-01" + }, + { + "name": "De\u0148 boja za slobodu a demokraciu", + "date": "2024-11-17" + }, + { + "name": "\u0160tedr\u00fd de\u0148", + "date": "2024-12-24" + }, + { + "name": "Prv\u00fd sviatok viano\u010dn\u00fd", + "date": "2024-12-25" + }, + { + "name": "Druh\u00fd sviatok viano\u010dn\u00fd", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/SlovakiaTest.php b/tests/Countries/SlovakiaTest.php new file mode 100644 index 000000000..cb08ebd5a --- /dev/null +++ b/tests/Countries/SlovakiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 8ec69653cf5ef6f7405c55e27e244eaa4e1aece2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Fri, 19 Jan 2024 18:37:16 +0100 Subject: [PATCH 03/99] Fix typo Co-authored-by: matusk --- src/Countries/Slovakia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Slovakia.php b/src/Countries/Slovakia.php index f400d349b..589f0989a 100644 --- a/src/Countries/Slovakia.php +++ b/src/Countries/Slovakia.php @@ -19,7 +19,7 @@ protected function allHolidays(int $year): array 'Sviatok práce' => '05-01', 'Deň víťazstva nad fašizmom' => '05-08', 'Sviatok svätého Cyrila a Metoda' => '07-05', - 'Výročie Výročie Slovenského národného povstania' => '08-29', + 'Výročie Slovenského národného povstania' => '08-29', 'Deň Ústavy Slovenskej republiky' => '09-01', 'Sedembolestná Panna Mária' => '09-15', 'Deň vzniku samostatného česko-slovenského štátu' => '10-28', From ee8e9e1bf2812afc1c1f38c1bd6e586d344aa28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Fri, 19 Jan 2024 18:37:32 +0100 Subject: [PATCH 04/99] Fix typo Co-authored-by: matusk --- .../SlovakiaTest/it_can_calculate_slovak_holidays.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap index 2aa7ea1fd..a802e2e06 100644 --- a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap +++ b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap @@ -28,7 +28,7 @@ "date": "2024-07-05" }, { - "name": "V\u00fdro\u010die V\u00fdro\u010die Slovensk\u00e9ho n\u00e1rodn\u00e9ho povstania", + "name": "V\u00fdro\u010die Slovensk\u00e9ho n\u00e1rodn\u00e9ho povstania", "date": "2024-08-29" }, { From 56cac551bf3ec4189609faa3572995a517d54d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Fri, 19 Jan 2024 18:45:39 +0100 Subject: [PATCH 05/99] Update Slovakia.php Co-authored-by: matusk --- src/Countries/Slovakia.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Slovakia.php b/src/Countries/Slovakia.php index 589f0989a..0d5774f04 100644 --- a/src/Countries/Slovakia.php +++ b/src/Countries/Slovakia.php @@ -22,7 +22,6 @@ protected function allHolidays(int $year): array 'Výročie Slovenského národného povstania' => '08-29', 'Deň Ústavy Slovenskej republiky' => '09-01', 'Sedembolestná Panna Mária' => '09-15', - 'Deň vzniku samostatného česko-slovenského štátu' => '10-28', 'Sviatok všetkých svätých' => '11-01', 'Deň boja za slobodu a demokraciu' => '11-17', 'Štedrý deň' => '12-24', From 9e229556b60a1f24caca39bfab0bfa0b36ac4a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Fri, 19 Jan 2024 18:45:45 +0100 Subject: [PATCH 06/99] Update it_can_calculate_slovak_holidays.snap Co-authored-by: matusk --- .../SlovakiaTest/it_can_calculate_slovak_holidays.snap | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap index a802e2e06..ac07602fd 100644 --- a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap +++ b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap @@ -39,10 +39,6 @@ "name": "Sedembolestn\u00e1 Panna M\u00e1ria", "date": "2024-09-15" }, - { - "name": "De\u0148 vzniku samostatn\u00e9ho \u010desko-slovensk\u00e9ho \u0161t\u00e1tu", - "date": "2024-10-28" - }, { "name": "Sviatok v\u0161etk\u00fdch sv\u00e4t\u00fdch", "date": "2024-11-01" From 751da09dd5df9b2113fbe6328cc85e433473ba0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Fri, 19 Jan 2024 22:26:50 +0100 Subject: [PATCH 07/99] Add return type docblock --- src/Countries/Slovakia.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Countries/Slovakia.php b/src/Countries/Slovakia.php index f400d349b..199aea437 100644 --- a/src/Countries/Slovakia.php +++ b/src/Countries/Slovakia.php @@ -31,6 +31,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } + /** @return array */ protected function variableHolidays(int $year): array { $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) From 09360740bb253239f5a8dd4135117cecae7bfb17 Mon Sep 17 00:00:00 2001 From: Ivars Date: Tue, 23 Jan 2024 17:57:06 +0200 Subject: [PATCH 08/99] Add latvian holidays --- src/Countries/Latvia.php | 63 +++++++++++++++++++ .../it_can_calculate_latvian_holidays.snap | 58 +++++++++++++++++ tests/Countries/LatviaTest.php | 18 ++++++ 3 files changed, 139 insertions(+) create mode 100644 src/Countries/Latvia.php create mode 100644 tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_holidays.snap create mode 100644 tests/Countries/LatviaTest.php diff --git a/src/Countries/Latvia.php b/src/Countries/Latvia.php new file mode 100644 index 000000000..b9a29ad3e --- /dev/null +++ b/src/Countries/Latvia.php @@ -0,0 +1,63 @@ + '01-01', + 'Darba svētki' => '05-01', + 'Latvijas Republikas Neatkarības deklarācijas pasludināšanas diena' => '05-04', + 'Līgo diena' => '06-23', + 'Jāņu diena' => '06-24', + 'Latvijas Republikas proklamēšanas diena' => '11-18', + 'Ziemassvētku vakars' => '12-24', + 'Pirmie Ziemassvētki' => '12-25', + 'Otrie Ziemassvētki' => '12-26', + 'Vecgada vakars' => '12-31', + ], $this->variableHolidays($year), $this->postponedHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Lielā Piektdiena' => $easter->subDays(2), + 'Pirmās Lieldienas' => $easter, + 'Otrās Lieldienas' => $easter->addDay(), + ]; + } + + /** @return array */ + protected function postponedHolidays(int $year): array + { + // If the holidays - May 4 and November 18 - fall on a Saturday or Sunday, + // the next working day is designated as a holiday. + $holidays = []; + + $date = new CarbonImmutable(); + + $date = $date->setDate($year, 5, 4); + if($date->isWeekend()) { + $holidays['Pārceltā 4. maija brīvdiena'] = $date->nextWeekday()->format('m-d'); + } + + $date = $date->setDate($year, 11, 18); + if($date->isWeekend()) { + $holidays['Pārceltā 18. novembra brīvdiena'] = $date->nextWeekday()->format('m-d'); + } + + return $holidays; + } +} diff --git a/tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_holidays.snap b/tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_holidays.snap new file mode 100644 index 000000000..efe1c19fc --- /dev/null +++ b/tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "Jaunais gads", + "date": "2024-01-01" + }, + { + "name": "Liel\u0101 Piektdiena", + "date": "2024-03-29" + }, + { + "name": "Pirm\u0101s Lieldienas", + "date": "2024-03-31" + }, + { + "name": "Otr\u0101s Lieldienas", + "date": "2024-04-01" + }, + { + "name": "Darba sv\u0113tki", + "date": "2024-05-01" + }, + { + "name": "Latvijas Republikas Neatkar\u012bbas deklar\u0101cijas pasludin\u0101\u0161anas diena", + "date": "2024-05-04" + }, + { + "name": "P\u0101rcelt\u0101 4. maija br\u012bvdiena", + "date": "2024-05-06" + }, + { + "name": "L\u012bgo diena", + "date": "2024-06-23" + }, + { + "name": "J\u0101\u0146u diena", + "date": "2024-06-24" + }, + { + "name": "Latvijas Republikas proklam\u0113\u0161anas diena", + "date": "2024-11-18" + }, + { + "name": "Ziemassv\u0113tku vakars", + "date": "2024-12-24" + }, + { + "name": "Pirmie Ziemassv\u0113tki", + "date": "2024-12-25" + }, + { + "name": "Otrie Ziemassv\u0113tki", + "date": "2024-12-26" + }, + { + "name": "Vecgada vakars", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/Countries/LatviaTest.php b/tests/Countries/LatviaTest.php new file mode 100644 index 000000000..bce7acb68 --- /dev/null +++ b/tests/Countries/LatviaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 9aa2b302b5243363e52618897432f1120650702e Mon Sep 17 00:00:00 2001 From: thecaliskan Date: Tue, 23 Jan 2024 19:04:14 +0300 Subject: [PATCH 09/99] Added has helper --- README.md | 11 +++++++++++ src/Holidays.php | 5 +++++ tests/HolidaysTest.php | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 8bc3564e3..714dbff0c 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,17 @@ use Spatie\Holidays\Holidays; Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar ``` +### Determining whether a country is supported + +If you need to check a country supported, you can use the `has` method. + +```php +use Spatie\Holidays\Holidays; + +Holidays::has('be'); // true +Holidays::has('unknown'); // false +``` + ### Package limitations 1. Islamic holidays are not supported (yet) diff --git a/src/Holidays.php b/src/Holidays.php index 775592df5..8b530b0b2 100755 --- a/src/Holidays.php +++ b/src/Holidays.php @@ -28,6 +28,11 @@ public static function for(Country|string $country, ?int $year = null): static return new static($country, $year); } + public static function has(string $country): bool + { + return Country::find($country) instanceof Country; + } + /** @return array */ public function get(Country|string|null $country = null, ?int $year = null): array { diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index 2477e6053..aa242162b 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -83,3 +83,11 @@ $result = Holidays::for('be')->getName(CarbonImmutable::parse('2024-01-02')); expect($result)->toBeNull(); }); + +it('can get the country is supported', function () { + $result = Holidays::has(country: 'be'); + expect($result)->toBeTrue(); + + $result = Holidays::has(country: 'unknown'); + expect($result)->toBeFalse(); +}); From e932a2d5ac9c4ccdf2ccfff6fec07cde88965bc9 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:28:16 +0100 Subject: [PATCH 10/99] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 714dbff0c..92128ddeb 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar ### Determining whether a country is supported -If you need to check a country supported, you can use the `has` method. +To verify whether a country is supported, you can use the `has` method. ```php use Spatie\Holidays\Holidays; From d66e37598278a3b846c6e5f4e2b7b8194e593bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Tue, 23 Jan 2024 21:16:37 +0100 Subject: [PATCH 11/99] Use `easter()` method to calculate easter date from parent class --- src/Countries/Slovakia.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/Slovakia.php b/src/Countries/Slovakia.php index c57ace0ae..32d21dccb 100644 --- a/src/Countries/Slovakia.php +++ b/src/Countries/Slovakia.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('Europe/Bratislava'); + $easter = $this->easter($year); return [ 'Veľkonočný pondelok' => $easter->addDay(), From e96aab31994e6d1512a9977d465b11886e3c5add Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 09:47:07 +0100 Subject: [PATCH 12/99] check on null instead of object --- src/Holidays.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Holidays.php b/src/Holidays.php index 8b530b0b2..4cc9011a0 100755 --- a/src/Holidays.php +++ b/src/Holidays.php @@ -30,7 +30,7 @@ public static function for(Country|string $country, ?int $year = null): static public static function has(string $country): bool { - return Country::find($country) instanceof Country; + return Country::find($country) !== null; } /** @return array */ From b600a44ecf145885ce1ec9fd188bbb6c0b45bb0b Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 10:02:01 +0100 Subject: [PATCH 13/99] add locale to api --- src/Countries/Country.php | 7 ++++++- src/Holidays.php | 14 +++++++++++--- tests/HolidaysTest.php | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 3a09768db..78457455e 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -14,7 +14,7 @@ abstract public function countryCode(): string; abstract protected function allHolidays(int $year): array; /** @return array */ - public function get(int $year): array + public function get(int $year, ?string $locale = null): array { $this->ensureYearCanBeCalculated($year); @@ -90,6 +90,11 @@ public static function findOrFail(string $countryCode): Country return $country; } + protected function translate(string $name): string + { + return $name; + } + protected function ensureYearCanBeCalculated(int $year): void { /** diff --git a/src/Holidays.php b/src/Holidays.php index 4cc9011a0..76123011a 100755 --- a/src/Holidays.php +++ b/src/Holidays.php @@ -14,10 +14,11 @@ class Holidays protected function __construct( protected Country $country, protected int $year, + protected ?string $locale = null, ) { } - public static function for(Country|string $country, ?int $year = null): static + public static function for(Country|string $country, ?int $year = null, ?string $locale = null): static { $year ??= CarbonImmutable::now()->year; @@ -25,7 +26,7 @@ public static function for(Country|string $country, ?int $year = null): static $country = Country::findOrFail($country); } - return new static($country, $year); + return new static($country, $year, $locale); } public static function has(string $country): bool @@ -33,6 +34,13 @@ public static function has(string $country): bool return Country::find($country) !== null; } + public function locale(string $locale): static + { + $this->locale = $locale; + + return $this; + } + /** @return array */ public function get(Country|string|null $country = null, ?int $year = null): array { @@ -91,7 +99,7 @@ public function getName(CarbonInterface|string $date, Country|string|null $count protected function calculate(): self { - $this->holidays = $this->country->get($this->year); + $this->holidays = $this->country->get($this->year, $this->locale); return $this; } diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index aa242162b..8929ff433 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -91,3 +91,35 @@ $result = Holidays::has(country: 'unknown'); expect($result)->toBeFalse(); }); + +it('can get translated holiday names', function () { + $result = Holidays::for(country: 'be', year: 2020, locale: 'nl')->get(); + + expect($result) + ->toBeArray() + ->toContain('Nieuwjaar') + ->not()->toContain('jour de l\'An'); + + $result = Holidays::for(country: 'be', year: 2020, locale: 'fr')->get(); + + expect($result) + ->toBeArray() + ->toContain('jour de l\'An') + ->not()->toContain('Nieuwjaar'); +}); + +it('can get translated holiday names by calling the locale method', function () { + $result = Holidays::for('be')->locale('nl')->get(); + + expect($result) + ->toBeArray() + ->toContain('Nieuwjaar') + ->not()->toContain('jour de l\'An'); + + $result = Holidays::for('be')->locale('fr')->get(); + + expect($result) + ->toBeArray() + ->toContain('jour de l\'An') + ->not()->toContain('Nieuwjaar'); +}); From 1ec5d8d117f7b1292eccd41a2705dac5f1b0bf90 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 10:02:45 +0100 Subject: [PATCH 14/99] remove locale setter not using this for country and year either --- src/Holidays.php | 7 ------- tests/HolidaysTest.php | 16 ---------------- 2 files changed, 23 deletions(-) diff --git a/src/Holidays.php b/src/Holidays.php index 76123011a..ee2accb98 100755 --- a/src/Holidays.php +++ b/src/Holidays.php @@ -34,13 +34,6 @@ public static function has(string $country): bool return Country::find($country) !== null; } - public function locale(string $locale): static - { - $this->locale = $locale; - - return $this; - } - /** @return array */ public function get(Country|string|null $country = null, ?int $year = null): array { diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index 8929ff433..7367908b7 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -107,19 +107,3 @@ ->toContain('jour de l\'An') ->not()->toContain('Nieuwjaar'); }); - -it('can get translated holiday names by calling the locale method', function () { - $result = Holidays::for('be')->locale('nl')->get(); - - expect($result) - ->toBeArray() - ->toContain('Nieuwjaar') - ->not()->toContain('jour de l\'An'); - - $result = Holidays::for('be')->locale('fr')->get(); - - expect($result) - ->toBeArray() - ->toContain('jour de l\'An') - ->not()->toContain('Nieuwjaar'); -}); From 28ac2927d130a539c7caaf8844a8ec28c78a8a2c Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:55:44 +0100 Subject: [PATCH 15/99] add translations in french for Belgium --- lang/belgium/fr/holidays.json | 12 ++++++ src/Concerns/Translatable.php | 30 +++++++++++++ src/Countries/Country.php | 21 +++++----- src/Holidays.php | 3 +- .../it_can_get_translated_holiday_names.snap | 42 +++++++++++++++++++ tests/HolidaysTest.php | 12 +----- 6 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 lang/belgium/fr/holidays.json create mode 100644 src/Concerns/Translatable.php create mode 100644 tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap diff --git a/lang/belgium/fr/holidays.json b/lang/belgium/fr/holidays.json new file mode 100644 index 000000000..4232e2d7d --- /dev/null +++ b/lang/belgium/fr/holidays.json @@ -0,0 +1,12 @@ +{ + "Nieuwjaar": "Jour de l'An", + "Dag van de Arbeid": "Fête du Travail", + "Nationale Feestdag": "Fête nationale", + "OLV Hemelvaart": "Assomption", + "Allerheiligen": "Toussaint", + "Wapenstilstand": "Armistice", + "Kerstmis": "Noël", + "Paasmaandag": "Lundi de Pâques", + "OLH Hemelvaart": "Ascension", + "Pinkstermaandag": "Lundi de Pentecôte" +} diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php new file mode 100644 index 000000000..41df04cff --- /dev/null +++ b/src/Concerns/Translatable.php @@ -0,0 +1,30 @@ + */ @@ -20,19 +23,22 @@ public function get(int $year, ?string $locale = null): array $allHolidays = $this->allHolidays($year); - $allHolidays = array_map(function ($date) use ($year) { + $translatedHolidays = []; + foreach ($allHolidays as $name => $date) { if (is_string($date)) { $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); } - return $date; - }, $allHolidays); + $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); + + $translatedHolidays[$name] = $date; + } - uasort($allHolidays, + uasort($translatedHolidays, fn (CarbonImmutable $a, CarbonImmutable $b) => $a->timestamp <=> $b->timestamp ); - return $allHolidays; + return $translatedHolidays; } public static function make(): static @@ -90,11 +96,6 @@ public static function findOrFail(string $countryCode): Country return $country; } - protected function translate(string $name): string - { - return $name; - } - protected function ensureYearCanBeCalculated(int $year): void { /** diff --git a/src/Holidays.php b/src/Holidays.php index ee2accb98..b526308ac 100755 --- a/src/Holidays.php +++ b/src/Holidays.php @@ -39,8 +39,9 @@ public function get(Country|string|null $country = null, ?int $year = null): arr { $country ??= $this->country; $year ??= $this->year; + $locale ??= $this->locale; - return static::for($country, $year) + return static::for($country, $year, $locale) ->calculate() ->toArray(); } diff --git a/tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap b/tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap new file mode 100644 index 000000000..037a0d8f2 --- /dev/null +++ b/tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Jour de l'An", + "date": "2020-01-01" + }, + { + "name": "Lundi de P\u00e2ques", + "date": "2020-04-13" + }, + { + "name": "F\u00eate du Travail", + "date": "2020-05-01" + }, + { + "name": "Ascension", + "date": "2020-05-21" + }, + { + "name": "Lundi de Pentec\u00f4te", + "date": "2020-06-01" + }, + { + "name": "F\u00eate nationale", + "date": "2020-07-21" + }, + { + "name": "Assomption", + "date": "2020-08-15" + }, + { + "name": "Toussaint", + "date": "2020-11-01" + }, + { + "name": "Armistice", + "date": "2020-11-11" + }, + { + "name": "No\u00ebl", + "date": "2020-12-25" + } +] \ No newline at end of file diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index 7367908b7..a74c54016 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -93,17 +93,7 @@ }); it('can get translated holiday names', function () { - $result = Holidays::for(country: 'be', year: 2020, locale: 'nl')->get(); - - expect($result) - ->toBeArray() - ->toContain('Nieuwjaar') - ->not()->toContain('jour de l\'An'); - $result = Holidays::for(country: 'be', year: 2020, locale: 'fr')->get(); - expect($result) - ->toBeArray() - ->toContain('jour de l\'An') - ->not()->toContain('Nieuwjaar'); + expect(formatDates($result))->toMatchSnapshot(); }); From bf14f45cfc4a7a941826c72b3b214f76e4667890 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:58:08 +0100 Subject: [PATCH 16/99] cleanup --- src/Concerns/Translatable.php | 1 + src/Holidays.php | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 41df04cff..3da140448 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -19,6 +19,7 @@ protected function translate(string $country, string $name, ?string $locale = nu return $name; } + /** @var array $data */ $data = json_decode($content, true); if (! isset($data[$name])) { diff --git a/src/Holidays.php b/src/Holidays.php index b526308ac..4f27a579e 100755 --- a/src/Holidays.php +++ b/src/Holidays.php @@ -39,9 +39,8 @@ public function get(Country|string|null $country = null, ?int $year = null): arr { $country ??= $this->country; $year ??= $this->year; - $locale ??= $this->locale; - return static::for($country, $year, $locale) + return static::for($country, $year, $this->locale) ->calculate() ->toArray(); } From cb5cfec333cc73cbc31c977ef2b714d3a0978239 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 24 Jan 2024 10:58:33 +0000 Subject: [PATCH 17/99] Fix styling --- src/Concerns/Translatable.php | 2 +- tests/HolidaysTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 3da140448..68877cb3b 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -13,7 +13,7 @@ protected function translate(string $country, string $name, ?string $locale = nu $countryName = strtolower($country); - $content = file_get_contents(__DIR__ . "/../../lang/{$countryName}/{$locale}/holidays.json"); + $content = file_get_contents(__DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"); if ($content === false) { return $name; diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index a74c54016..f6487f5cf 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -92,7 +92,7 @@ expect($result)->toBeFalse(); }); -it('can get translated holiday names', function () { +it('can get translated holiday names', function () { $result = Holidays::for(country: 'be', year: 2020, locale: 'fr')->get(); expect(formatDates($result))->toMatchSnapshot(); From 1a3b1361afb072bf6c7ed2b912848f74b4624789 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:58:08 +0100 Subject: [PATCH 18/99] cleanup --- src/Concerns/Translatable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 68877cb3b..d8e7af489 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -2,7 +2,6 @@ namespace Spatie\Holidays\Concerns; -/** @ */ trait Translatable { protected function translate(string $country, string $name, ?string $locale = null): string From 59cca7b4ba7f861d1576fc3607212f377e86fd5e Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 12:36:57 +0100 Subject: [PATCH 19/99] update readme and throw exception when needed --- README.md | 11 +++++++++++ src/Concerns/Translatable.php | 4 +++- src/Exceptions/InvalidLocale.php | 13 +++++++++++++ tests/HolidaysTest.php | 5 +++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Exceptions/InvalidLocale.php diff --git a/README.md b/README.md index 92128ddeb..508e61d5b 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,16 @@ use Spatie\Holidays\Holidays; $holidays = Holidays::for(country: 'be', year: 2024))->get(); ``` +### Getting holidays in a specific language + +```php +use Spatie\Holidays\Holidays; + +$holidays = Holidays::for(country: 'be', locale: 'fr'))->get(); +``` + +If the locale is not supported for a country, an exception will be thrown. + ### Determining if a date is a holiday If you need to see if a date is a holiday, you can use the `isHoliday` method. @@ -112,6 +122,7 @@ This is a community driven package. If you find any errors, please create an iss 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. +5. If the country has multiple languages, add a file in the `lang/` 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. diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index d8e7af489..0c65b5f7a 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -2,6 +2,8 @@ namespace Spatie\Holidays\Concerns; +use Spatie\Holidays\Exceptions\InvalidLocale; + trait Translatable { protected function translate(string $country, string $name, ?string $locale = null): string @@ -15,7 +17,7 @@ protected function translate(string $country, string $name, ?string $locale = nu $content = file_get_contents(__DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"); if ($content === false) { - return $name; + throw InvalidLocale::notFound($country, $locale); } /** @var array $data */ diff --git a/src/Exceptions/InvalidLocale.php b/src/Exceptions/InvalidLocale.php new file mode 100644 index 000000000..1d34fc8d3 --- /dev/null +++ b/src/Exceptions/InvalidLocale.php @@ -0,0 +1,13 @@ +toMatchSnapshot(); }); + +it('cannot get translated holiday names for unsupported locales', function () { + Holidays::for(country: 'be', year: 2020, locale: 'en')->get(); +})->throws(InvalidLocale::class, 'Locale `en` is not supported for country `Belgium`.'); From 52aef70b7dc47e23fb0c9821be66f6d2858c4919 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 24 Jan 2024 11:37:35 +0000 Subject: [PATCH 20/99] Fix styling --- tests/HolidaysTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index bec1aeab3..6d0b2b317 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -99,6 +99,6 @@ expect(formatDates($result))->toMatchSnapshot(); }); -it('cannot get translated holiday names for unsupported locales', function () { +it('cannot get translated holiday names for unsupported locales', function () { Holidays::for(country: 'be', year: 2020, locale: 'en')->get(); })->throws(InvalidLocale::class, 'Locale `en` is not supported for country `Belgium`.'); From faf22be7976c1f56505ba4aa69447db81c212db9 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 12:39:52 +0100 Subject: [PATCH 21/99] remove snapshot --- .../it_can_get_translated_holiday_names.snap | 42 ------------------- tests/HolidaysTest.php | 3 +- 2 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap diff --git a/tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap b/tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap deleted file mode 100644 index 037a0d8f2..000000000 --- a/tests/.pest/snapshots/HolidaysTest/it_can_get_translated_holiday_names.snap +++ /dev/null @@ -1,42 +0,0 @@ -[ - { - "name": "Jour de l'An", - "date": "2020-01-01" - }, - { - "name": "Lundi de P\u00e2ques", - "date": "2020-04-13" - }, - { - "name": "F\u00eate du Travail", - "date": "2020-05-01" - }, - { - "name": "Ascension", - "date": "2020-05-21" - }, - { - "name": "Lundi de Pentec\u00f4te", - "date": "2020-06-01" - }, - { - "name": "F\u00eate nationale", - "date": "2020-07-21" - }, - { - "name": "Assomption", - "date": "2020-08-15" - }, - { - "name": "Toussaint", - "date": "2020-11-01" - }, - { - "name": "Armistice", - "date": "2020-11-11" - }, - { - "name": "No\u00ebl", - "date": "2020-12-25" - } -] \ No newline at end of file diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index 6d0b2b317..c09d7db67 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -96,7 +96,8 @@ it('can get translated holiday names', function () { $result = Holidays::for(country: 'be', year: 2020, locale: 'fr')->get(); - expect(formatDates($result))->toMatchSnapshot(); + expect($result)->toBeArray(); + expect($result[0]['name'])->toBe('Jour de l\'An'); }); it('cannot get translated holiday names for unsupported locales', function () { From eb85b1f3e22fcd26f146a6fa5398209d085e1181 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 24 Jan 2024 12:22:52 +0000 Subject: [PATCH 22/99] Fix styling --- src/Countries/Latvia.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Latvia.php b/src/Countries/Latvia.php index b9a29ad3e..b5c088605 100644 --- a/src/Countries/Latvia.php +++ b/src/Countries/Latvia.php @@ -49,12 +49,12 @@ protected function postponedHolidays(int $year): array $date = new CarbonImmutable(); $date = $date->setDate($year, 5, 4); - if($date->isWeekend()) { + if ($date->isWeekend()) { $holidays['Pārceltā 4. maija brīvdiena'] = $date->nextWeekday()->format('m-d'); } $date = $date->setDate($year, 11, 18); - if($date->isWeekend()) { + if ($date->isWeekend()) { $holidays['Pārceltā 18. novembra brīvdiena'] = $date->nextWeekday()->format('m-d'); } From 82afddc1dbc1eca374427c77755bd37cd23580e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Le=C3=B3n=20Torres?= <47951932+alvleont@users.noreply.github.com> Date: Wed, 24 Jan 2024 07:43:50 -0500 Subject: [PATCH 23/99] Added Colombia Holidays (#55) * Adding Colombia Holidays Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday. * Adding Colombia Holidays Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday. * Update Colombia.php Deleted the line as suggested by @Nielsvanpach * Update Colombia.php * Added changes to Colombia.php and to the test file - Suggestions from @luisprmat were incorporated. - All the work of emiliani holiday generation was included into the emilianiHoliday method to achieve code readability - The order of the holidays was updated to ensure that the next emiliani holiday that appears can be included at the end of the list. - The test was updated because it's "colombian holidays" not "colombia holidays" --- src/Countries/Colombia.php | 58 +++++++++++++++ .../it_can_calculate_colombian_holidays.snap | 74 +++++++++++++++++++ tests/Countries/ColombiaTest.php | 18 +++++ 3 files changed, 150 insertions(+) create mode 100644 src/Countries/Colombia.php create mode 100644 tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap create mode 100644 tests/Countries/ColombiaTest.php diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php new file mode 100644 index 000000000..e2430f76a --- /dev/null +++ b/src/Countries/Colombia.php @@ -0,0 +1,58 @@ + '01-01', + 'Día del Trabajo' => '05-01', + 'Día de la independencia' => '07-20', + 'Batalla de Boyacá' => '08-07', + 'Inmaculada Concepción' => '12-08', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + 'Ascención de Jesús' => $easter->addDays(43), + 'Corpus Christi' => $easter->addDays(64), + 'Sagrado corazón de Jesús' => $easter->addDays(71), + 'Reyes Magos' => $this->emilianiHoliday($year, 1, 6), + 'Día de San José' => $this->emilianiHoliday($year, 3, 19), + 'San Pedro y San Pablo' => $this->emilianiHoliday($year, 6, 29), + 'Asunción de la Virgen' => $this->emilianiHoliday($year, 8, 15), + 'Día de la raza' => $this->emilianiHoliday($year, 10, 12), + 'Todos los santos' => $this->emilianiHoliday($year, 11, 1), + 'Independencia de Cartagena' => $this->emilianiHoliday($year, 11, 11), + + ]; + } + + /** @return CarbonImmutable */ + private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable + { + $dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); + if ($dateObj->is('Monday')) { + return $dateObj; + } else { + return $dateObj->next('Monday'); + } + } +} diff --git a/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap new file mode 100644 index 000000000..38e611c25 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_holidays.snap @@ -0,0 +1,74 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Reyes Magos", + "date": "2024-01-08" + }, + { + "name": "D\u00eda de San Jos\u00e9", + "date": "2024-03-25" + }, + { + "name": "Jueves Santo", + "date": "2024-03-28" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "Ascenci\u00f3n de Jes\u00fas", + "date": "2024-05-13" + }, + { + "name": "Corpus Christi", + "date": "2024-06-03" + }, + { + "name": "Sagrado coraz\u00f3n de Jes\u00fas", + "date": "2024-06-10" + }, + { + "name": "San Pedro y San Pablo", + "date": "2024-07-01" + }, + { + "name": "D\u00eda de la independencia", + "date": "2024-07-20" + }, + { + "name": "Batalla de Boyac\u00e1", + "date": "2024-08-07" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-19" + }, + { + "name": "D\u00eda de la raza", + "date": "2024-10-14" + }, + { + "name": "Todos los santos", + "date": "2024-11-04" + }, + { + "name": "Independencia de Cartagena", + "date": "2024-11-11" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ColombiaTest.php b/tests/Countries/ColombiaTest.php new file mode 100644 index 000000000..623ffd94b --- /dev/null +++ b/tests/Countries/ColombiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From cefdbaec0eb080cfd0cc2e2b94331291472cb860 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 24 Jan 2024 12:44:13 +0000 Subject: [PATCH 24/99] Fix styling --- src/Countries/Colombia.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php index e2430f76a..f3176f794 100644 --- a/src/Countries/Colombia.php +++ b/src/Countries/Colombia.php @@ -45,7 +45,6 @@ protected function variableHolidays(int $year): array ]; } - /** @return CarbonImmutable */ private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable { $dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); From 72c128082e1334414f416b2d969d8155d42bdbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Conny=20Sj=C3=B6blom?= <34518404+ConnySjoblom@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:15:30 +0200 Subject: [PATCH 25/99] Add Finnish Holidays (#85) * Add holidays for Finland * Use createFromDate instead of create * Add holidays for Finland in Swedish --- lang/finland/sv/holidays.json | 15 ++++++ src/Countries/Finland.php | 54 +++++++++++++++++++ .../it_can_calculate_finnish_holidays.snap | 54 +++++++++++++++++++ ...t_can_get_finnish_holidays_in_swedish.snap | 54 +++++++++++++++++++ tests/Countries/FinlandTest.php | 32 +++++++++++ 5 files changed, 209 insertions(+) create mode 100644 lang/finland/sv/holidays.json 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/.pest/snapshots/Countries/FinlandTest/it_can_get_finnish_holidays_in_swedish.snap create mode 100644 tests/Countries/FinlandTest.php diff --git a/lang/finland/sv/holidays.json b/lang/finland/sv/holidays.json new file mode 100644 index 000000000..0baa6a4c5 --- /dev/null +++ b/lang/finland/sv/holidays.json @@ -0,0 +1,15 @@ +{ + "Uudenvuodenpäivä": "Nyårsdagen", + "Loppiainen": "Trettondagen", + "Pitkäperjantai": "Långfredagen", + "Pääsiäispäivä": "Påskdagen", + "Toinen pääsiäispäivä": "Annandag påsk", + "Vappu": "Första maj", + "Helatorstai": "Kristi himmelsfärdsdag", + "Helluntaipäivä": "Pingst", + "Juhannuspäivä": "Midsommardagen", + "Pyhäinpäivä": "Alla helgons dag", + "Itsenäisyyspäivä": "Självständighetsdagen", + "Joulupäivä": "Juldagen", + "Tapaninpäivä": "Annandag jul" +} diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php new file mode 100644 index 000000000..103fda86f --- /dev/null +++ b/src/Countries/Finland.php @@ -0,0 +1,54 @@ +fixedHolidays($year), $this->variableHolidays($year)); + } + + /** @return array */ + protected function fixedHolidays(int $year): array + { + return [ + 'Uudenvuodenpäivä' => CarbonImmutable::createFromDate($year, 1, 1), + 'Loppiainen' => CarbonImmutable::createFromDate($year, 1, 6), + 'Vappu' => CarbonImmutable::createFromDate($year, 5, 1), + 'Itsenäisyyspäivä' => CarbonImmutable::createFromDate($year, 12, 6), + 'Joulupäivä' => CarbonImmutable::createFromDate($year, 12, 25), + 'Tapaninpäivä' => CarbonImmutable::createFromDate($year, 12, 26), + ]; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Helsinki'); + + $midsummerDay = CarbonImmutable::createFromDate($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::createFromDate($year, 10, 31) + ->next(CarbonImmutable::SATURDAY), + ]; + } +} 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..8a4f7a954 --- /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-29" + }, + { + "name": "P\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", + "date": "2024-03-31" + }, + { + "name": "Toinen p\u00e4\u00e4si\u00e4isp\u00e4iv\u00e4", + "date": "2024-04-01" + }, + { + "name": "Vappu", + "date": "2024-05-01" + }, + { + "name": "Helatorstai", + "date": "2024-05-09" + }, + { + "name": "Helluntaip\u00e4iv\u00e4", + "date": "2024-05-19" + }, + { + "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/.pest/snapshots/Countries/FinlandTest/it_can_get_finnish_holidays_in_swedish.snap b/tests/.pest/snapshots/Countries/FinlandTest/it_can_get_finnish_holidays_in_swedish.snap new file mode 100644 index 000000000..7f852ccd4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/FinlandTest/it_can_get_finnish_holidays_in_swedish.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Ny\u00e5rsdagen", + "date": "2024-01-01" + }, + { + "name": "Trettondagen", + "date": "2024-01-06" + }, + { + "name": "L\u00e5ngfredagen", + "date": "2024-03-29" + }, + { + "name": "P\u00e5skdagen", + "date": "2024-03-31" + }, + { + "name": "Annandag p\u00e5sk", + "date": "2024-04-01" + }, + { + "name": "F\u00f6rsta maj", + "date": "2024-05-01" + }, + { + "name": "Kristi himmelsf\u00e4rdsdag", + "date": "2024-05-09" + }, + { + "name": "Pingst", + "date": "2024-05-19" + }, + { + "name": "Midsommardagen", + "date": "2024-06-22" + }, + { + "name": "Alla helgons dag", + "date": "2024-11-02" + }, + { + "name": "Sj\u00e4lvst\u00e4ndighetsdagen", + "date": "2024-12-06" + }, + { + "name": "Juldagen", + "date": "2024-12-25" + }, + { + "name": "Annandag jul", + "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..565dc1623 --- /dev/null +++ b/tests/Countries/FinlandTest.php @@ -0,0 +1,32 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('can get finnish holidays in swedish', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'fi', locale: 'sv')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 915f16a83c3e857869610d94e513534df11108fd Mon Sep 17 00:00:00 2001 From: Marc <108322460+mkokio@users.noreply.github.com> Date: Thu, 25 Jan 2024 00:17:37 +0900 Subject: [PATCH 26/99] Add Japan support (#160) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Japan country support * Tested: it can calculate japanese holidays → Snapshot created --- src/Countries/Japan.php | 59 +++++++++++++++++ .../it_can_calculate_japanese_holidays.snap | 66 +++++++++++++++++++ tests/Countries/JapanTest.php | 18 +++++ 3 files changed, 143 insertions(+) create mode 100644 src/Countries/Japan.php create mode 100644 tests/.pest/snapshots/Countries/JapanTest/it_can_calculate_japanese_holidays.snap create mode 100644 tests/Countries/JapanTest.php diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php new file mode 100644 index 000000000..07acee028 --- /dev/null +++ b/src/Countries/Japan.php @@ -0,0 +1,59 @@ + '01-01', // New Year's Day + '建国記念の日' => '02-11', // Foundation Day + '天皇誕生日' => '02-23', // Emperor's Birthday + '春分の日' => '03-20', // Vernal Equinox Day *Decided each year; rarely on 03-21 + '昭和の日' => '04-29', // Showa Day + '憲法記念日' => '05-03', // Constitution Day + 'みどりの日' => '05-04', // Greenery Day + 'こどもの日' => '05-05', // Children's Day + '山の日' => '08-11', // Mountain Day + '秋分の日' => '09-23', // Autumnal Equinox Day *Decided each year; rarely on 09-22 + '文化の日' => '11-03', // Culture Day + '勤労感謝の日' => '11-23', // Labor Thanksgiving Day + + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $comingOfAgeDay = (new CarbonImmutable("second monday of january $year")) // Coming of Age Day + ->setTimezone('Asia/Tokyo'); + + $oceansDay = (new CarbonImmutable("third monday of july $year")) // Ocean's Day + ->setTimezone('Asia/Tokyo'); + + $respectForTheAgedDay = (new CarbonImmutable("third monday of september $year")) // Respect for the Aged Day + ->setTimezone('Asia/Tokyo'); + + $sportsDay = (new CarbonImmutable("second monday of october $year")) // Sports Day + ->setTimezone('Asia/Tokyo'); + + $holidays = [ + '成人の日' => $comingOfAgeDay, + '海の日' => $oceansDay, + '敬老の日' => $respectForTheAgedDay, + 'スポーツの日' => $sportsDay, + ]; + + return $holidays; + + } + +} \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/JapanTest/it_can_calculate_japanese_holidays.snap b/tests/.pest/snapshots/Countries/JapanTest/it_can_calculate_japanese_holidays.snap new file mode 100644 index 000000000..5d86d702a --- /dev/null +++ b/tests/.pest/snapshots/Countries/JapanTest/it_can_calculate_japanese_holidays.snap @@ -0,0 +1,66 @@ +[ + { + "name": "\u5143\u65e5", + "date": "2024-01-01" + }, + { + "name": "\u6210\u4eba\u306e\u65e5", + "date": "2024-01-08" + }, + { + "name": "\u5efa\u56fd\u8a18\u5ff5\u306e\u65e5", + "date": "2024-02-11" + }, + { + "name": "\u5929\u7687\u8a95\u751f\u65e5", + "date": "2024-02-23" + }, + { + "name": "\u6625\u5206\u306e\u65e5", + "date": "2024-03-20" + }, + { + "name": "\u662d\u548c\u306e\u65e5", + "date": "2024-04-29" + }, + { + "name": "\u61b2\u6cd5\u8a18\u5ff5\u65e5", + "date": "2024-05-03" + }, + { + "name": "\u307f\u3069\u308a\u306e\u65e5", + "date": "2024-05-04" + }, + { + "name": "\u3053\u3069\u3082\u306e\u65e5", + "date": "2024-05-05" + }, + { + "name": "\u6d77\u306e\u65e5", + "date": "2024-07-15" + }, + { + "name": "\u5c71\u306e\u65e5", + "date": "2024-08-11" + }, + { + "name": "\u656c\u8001\u306e\u65e5", + "date": "2024-09-16" + }, + { + "name": "\u79cb\u5206\u306e\u65e5", + "date": "2024-09-23" + }, + { + "name": "\u30b9\u30dd\u30fc\u30c4\u306e\u65e5", + "date": "2024-10-14" + }, + { + "name": "\u6587\u5316\u306e\u65e5", + "date": "2024-11-03" + }, + { + "name": "\u52e4\u52b4\u611f\u8b1d\u306e\u65e5", + "date": "2024-11-23" + } +] \ No newline at end of file diff --git a/tests/Countries/JapanTest.php b/tests/Countries/JapanTest.php new file mode 100644 index 000000000..252cd24dc --- /dev/null +++ b/tests/Countries/JapanTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); \ No newline at end of file From 964e741fe6cbfe2a65428fd33fe3aee39ba26ed6 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 24 Jan 2024 15:17:58 +0000 Subject: [PATCH 27/99] Fix styling --- src/Countries/Japan.php | 9 ++++----- tests/Countries/JapanTest.php | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index 07acee028..38b1bc7d5 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -26,7 +26,7 @@ protected function allHolidays(int $year): array '秋分の日' => '09-23', // Autumnal Equinox Day *Decided each year; rarely on 09-22 '文化の日' => '11-03', // Culture Day '勤労感謝の日' => '11-23', // Labor Thanksgiving Day - + ], $this->variableHolidays($year)); } @@ -41,9 +41,9 @@ protected function variableHolidays(int $year): array $respectForTheAgedDay = (new CarbonImmutable("third monday of september $year")) // Respect for the Aged Day ->setTimezone('Asia/Tokyo'); - + $sportsDay = (new CarbonImmutable("second monday of october $year")) // Sports Day - ->setTimezone('Asia/Tokyo'); + ->setTimezone('Asia/Tokyo'); $holidays = [ '成人の日' => $comingOfAgeDay, @@ -55,5 +55,4 @@ protected function variableHolidays(int $year): array return $holidays; } - -} \ No newline at end of file +} diff --git a/tests/Countries/JapanTest.php b/tests/Countries/JapanTest.php index 252cd24dc..3a948815e 100644 --- a/tests/Countries/JapanTest.php +++ b/tests/Countries/JapanTest.php @@ -15,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); \ No newline at end of file +}); From 95f9772ddb23dea99124815dc81b27628b5b72a4 Mon Sep 17 00:00:00 2001 From: Anand Capur <551002+arcdigital@users.noreply.github.com> Date: Wed, 24 Jan 2024 07:19:23 -0800 Subject: [PATCH 28/99] Add US Holidays (#26) --- src/Countries/UnitedStates.php | 49 +++++++++++++++++++ ...ate_united_states_holidays_after_2021.snap | 46 +++++++++++++++++ ...te_united_states_holidays_before_2021.snap | 42 ++++++++++++++++ tests/Countries/UnitedStatesTest.php | 32 ++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 src/Countries/UnitedStates.php create mode 100644 tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap create mode 100644 tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap create mode 100644 tests/Countries/UnitedStatesTest.php diff --git a/src/Countries/UnitedStates.php b/src/Countries/UnitedStates.php new file mode 100644 index 000000000..695103dca --- /dev/null +++ b/src/Countries/UnitedStates.php @@ -0,0 +1,49 @@ + '01-01', + 'Independence Day' => '07-04', + 'Veterans Day' => '11-11', + 'Christmas' => '12-25', + ], $this->variableHolidays($year)); + + if ($year >= 2021) { + $holidays['Juneteenth National Independence Day'] = '06-19'; + } + + return $holidays; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $martinLutherKingDay = new CarbonImmutable("third monday of January $year", 'America/Los_Angeles'); + $presidentsDay = new CarbonImmutable("third monday of February $year", 'America/Los_Angeles'); + $memorialDay = new CarbonImmutable("last monday of May $year", 'America/Los_Angeles'); + $laborDay = new CarbonImmutable("first monday of September $year", 'America/Los_Angeles'); + $columbusDay = new CarbonImmutable("second monday of October $year", 'America/Los_Angeles'); + $thanksgiving = new CarbonImmutable("fourth thursday of November $year", 'America/Los_Angeles'); + + return [ + 'Martin Luther King Day' => $martinLutherKingDay, + 'Presidents\' Day' => $presidentsDay, + 'Memorial Day' => $memorialDay, + 'Labor Day' => $laborDay, + 'Columbus Day' => $columbusDay, + 'Thanksgiving' => $thanksgiving, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap new file mode 100644 index 000000000..41227b5c4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_after_2021.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Martin Luther King Day", + "date": "2024-01-15" + }, + { + "name": "Presidents' Day", + "date": "2024-02-19" + }, + { + "name": "Memorial Day", + "date": "2024-05-27" + }, + { + "name": "Juneteenth National Independence Day", + "date": "2024-06-19" + }, + { + "name": "Independence Day", + "date": "2024-07-04" + }, + { + "name": "Labor Day", + "date": "2024-09-02" + }, + { + "name": "Columbus Day", + "date": "2024-10-14" + }, + { + "name": "Veterans Day", + "date": "2024-11-11" + }, + { + "name": "Thanksgiving", + "date": "2024-11-28" + }, + { + "name": "Christmas", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap new file mode 100644 index 000000000..5d92494f7 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UnitedStatesTest/it_can_calculate_united_states_holidays_before_2021.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Martin Luther King Day", + "date": "2020-01-20" + }, + { + "name": "Presidents' Day", + "date": "2020-02-17" + }, + { + "name": "Memorial Day", + "date": "2020-05-25" + }, + { + "name": "Independence Day", + "date": "2020-07-04" + }, + { + "name": "Labor Day", + "date": "2020-09-07" + }, + { + "name": "Columbus Day", + "date": "2020-10-12" + }, + { + "name": "Veterans Day", + "date": "2020-11-11" + }, + { + "name": "Thanksgiving", + "date": "2020-11-26" + }, + { + "name": "Christmas", + "date": "2020-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/UnitedStatesTest.php b/tests/Countries/UnitedStatesTest.php new file mode 100644 index 000000000..bdf277d2f --- /dev/null +++ b/tests/Countries/UnitedStatesTest.php @@ -0,0 +1,32 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('can calculate united states holidays before 2021', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'us')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From e82a37e1456166ec4a4b34024b7d9f2bc670b611 Mon Sep 17 00:00:00 2001 From: Nikola Zivkovic Date: Wed, 24 Jan 2024 16:29:44 +0100 Subject: [PATCH 29/99] Add Serbian holidays (#107) * Add Serbian holidays * Calculate orthodox easter * Improve phpstan * Fix test * Expand list with Christmas and Easter --- src/Countries/Serbia.php | 54 +++++++++++++++++++ .../it_can_calculate_serbian_holidays.snap | 46 ++++++++++++++++ tests/Countries/SerbiaTest.php | 18 +++++++ 3 files changed, 118 insertions(+) create mode 100644 src/Countries/Serbia.php create mode 100644 tests/.pest/snapshots/Countries/SerbiaTest/it_can_calculate_serbian_holidays.snap create mode 100644 tests/Countries/SerbiaTest.php diff --git a/src/Countries/Serbia.php b/src/Countries/Serbia.php new file mode 100644 index 000000000..adbea34ce --- /dev/null +++ b/src/Countries/Serbia.php @@ -0,0 +1,54 @@ + '01-01', + 'Nova godina - drugi dan' => '01-02', + 'Božić' => '01-07', + 'Dan državnosti - prvi dan' => '02-15', + 'Dan državnosti - drugi dan' => '02-16', + 'Praznik rada - prvi dan' => '05-01', + 'Praznik rada - drugi dan' => '05-02', + 'Dan primirja u Prvom svetskom ratu' => '11-11', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp( + $this->orthodoxEaster($year) + )->setTimezone('Europe/Belgrade'); + + return [ + 'Veliki petak' => $easter->subDays(2), + 'Vaskrs' => $easter, + 'Vaskršnji ponedeljak' => $easter->addDay(), + ]; + } + + protected function orthodoxEaster(int $year): int + { + $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); + $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; + + return (int) strtotime("+$daysDifference days", $timestamp); + } +} diff --git a/tests/.pest/snapshots/Countries/SerbiaTest/it_can_calculate_serbian_holidays.snap b/tests/.pest/snapshots/Countries/SerbiaTest/it_can_calculate_serbian_holidays.snap new file mode 100644 index 000000000..09b207302 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SerbiaTest/it_can_calculate_serbian_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Nova godina - prvi dan", + "date": "2024-01-01" + }, + { + "name": "Nova godina - drugi dan", + "date": "2024-01-02" + }, + { + "name": "Bo\u017ei\u0107", + "date": "2024-01-07" + }, + { + "name": "Dan dr\u017eavnosti - prvi dan", + "date": "2024-02-15" + }, + { + "name": "Dan dr\u017eavnosti - drugi dan", + "date": "2024-02-16" + }, + { + "name": "Praznik rada - prvi dan", + "date": "2024-05-01" + }, + { + "name": "Praznik rada - drugi dan", + "date": "2024-05-02" + }, + { + "name": "Veliki petak", + "date": "2024-05-03" + }, + { + "name": "Vaskrs", + "date": "2024-05-05" + }, + { + "name": "Vaskr\u0161nji ponedeljak", + "date": "2024-05-06" + }, + { + "name": "Dan primirja u Prvom svetskom ratu", + "date": "2024-11-11" + } +] \ No newline at end of file diff --git a/tests/Countries/SerbiaTest.php b/tests/Countries/SerbiaTest.php new file mode 100644 index 000000000..1a44fbb44 --- /dev/null +++ b/tests/Countries/SerbiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 3fe183595a79db02b8da0c7e219267928f801147 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 24 Jan 2024 15:30:04 +0000 Subject: [PATCH 30/99] Fix styling --- src/Countries/Serbia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Serbia.php b/src/Countries/Serbia.php index adbea34ce..13dc3ad8f 100644 --- a/src/Countries/Serbia.php +++ b/src/Countries/Serbia.php @@ -47,7 +47,7 @@ protected function variableHolidays(int $year): array protected function orthodoxEaster(int $year): 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 (int) strtotime("+$daysDifference days", $timestamp); } From 86483371c45dc1a253fd4dd603e7172158b241fa Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:33:55 +0100 Subject: [PATCH 31/99] fix Serbia --- src/Countries/Serbia.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Countries/Serbia.php b/src/Countries/Serbia.php index 13dc3ad8f..117885062 100644 --- a/src/Countries/Serbia.php +++ b/src/Countries/Serbia.php @@ -6,11 +6,6 @@ class Serbia extends Country { - protected function __construct( - public ?string $region = null - ) { - } - public function countryCode(): string { return 'sr'; @@ -33,9 +28,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp( - $this->orthodoxEaster($year) - )->setTimezone('Europe/Belgrade'); + $easter = $this->orthodoxEaster($year); return [ 'Veliki petak' => $easter->subDays(2), @@ -43,12 +36,4 @@ protected function variableHolidays(int $year): array 'Vaskršnji ponedeljak' => $easter->addDay(), ]; } - - protected function orthodoxEaster(int $year): int - { - $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); - $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - - return (int) strtotime("+$daysDifference days", $timestamp); - } } From a47637ea1d3c96fb259f6e974a4d0e38e494c6e1 Mon Sep 17 00:00:00 2001 From: Mauricio Villatoro Date: Wed, 24 Jan 2024 09:41:49 -0600 Subject: [PATCH 32/99] Add El Salvador Holidays (#93) * add El Salvador holidays * fix styling --- src/Countries/ElSalvador.php | 41 +++++++++++++++++ ...it_can_calculate_el_salvador_holidays.snap | 46 +++++++++++++++++++ tests/Countries/ElSalvadorTest.php | 18 ++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/Countries/ElSalvador.php create mode 100644 tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap create mode 100644 tests/Countries/ElSalvadorTest.php diff --git a/src/Countries/ElSalvador.php b/src/Countries/ElSalvador.php new file mode 100644 index 000000000..7f6183b3b --- /dev/null +++ b/src/Countries/ElSalvador.php @@ -0,0 +1,41 @@ + '01-01', + 'Día del Trabajo' => '05-01', + 'Día de la Madre' => '05-10', + 'Día del Padre' => '06-17', + 'Fiesta Divino Salvador del Mundo' => '08-06', + 'Día de la Independencia' => '09-15', + 'Día de Los Difuntos' => '11-02', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/El_Salvador'); + + return [ + 'Jueves Santo' => $easter->subDays(3), + 'Viernes Santo' => $easter->subDays(2), + 'Sábado de Gloria' => $easter->subDays(1), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap b/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap new file mode 100644 index 000000000..2586f7686 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Jueves Santo", + "date": "2024-03-27" + }, + { + "name": "Viernes Santo", + "date": "2024-03-28" + }, + { + "name": "S\u00e1bado de Gloria", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de la Madre", + "date": "2024-05-10" + }, + { + "name": "D\u00eda del Padre", + "date": "2024-06-17" + }, + { + "name": "Fiesta Divino Salvador del Mundo", + "date": "2024-08-06" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-09-15" + }, + { + "name": "D\u00eda de Los Difuntos", + "date": "2024-11-02" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ElSalvadorTest.php b/tests/Countries/ElSalvadorTest.php new file mode 100644 index 000000000..892a8f791 --- /dev/null +++ b/tests/Countries/ElSalvadorTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 076b619261a707cb50484a296c45f8a95fe5cc0c Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 24 Jan 2024 15:42:09 +0000 Subject: [PATCH 33/99] Fix styling --- src/Countries/ElSalvador.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/ElSalvador.php b/src/Countries/ElSalvador.php index 7f6183b3b..c3a84a224 100644 --- a/src/Countries/ElSalvador.php +++ b/src/Countries/ElSalvador.php @@ -6,7 +6,6 @@ class ElSalvador extends Country { - public function countryCode(): string { return 'sv'; From 0acd603c6f1534e87e088b6e53f26d3816930de7 Mon Sep 17 00:00:00 2001 From: Dzianis Kotau Date: Thu, 25 Jan 2024 12:15:39 +0400 Subject: [PATCH 34/99] Belarus Holidays (#156) --- lang/belarus/be-latn/holidays.json | 12 +++++ lang/belarus/en/holidays.json | 12 +++++ lang/belarus/ru/holidays.json | 12 +++++ src/Countries/Belarus.php | 38 +++++++++++++ .../it_can_calculate_belarus_holidays.snap | 42 +++++++++++++++ ...e_belarus_holidays_in_Belarus_Lacinka.snap | 42 +++++++++++++++ ...calculate_belarus_holidays_in_English.snap | 42 +++++++++++++++ ...calculate_belarus_holidays_in_Russian.snap | 42 +++++++++++++++ tests/Countries/BelarusTest.php | 54 +++++++++++++++++++ 9 files changed, 296 insertions(+) create mode 100644 lang/belarus/be-latn/holidays.json create mode 100644 lang/belarus/en/holidays.json create mode 100644 lang/belarus/ru/holidays.json create mode 100644 src/Countries/Belarus.php create mode 100644 tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Belarus_Lacinka.snap create mode 100644 tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_English.snap create mode 100644 tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Russian.snap create mode 100644 tests/Countries/BelarusTest.php diff --git a/lang/belarus/be-latn/holidays.json b/lang/belarus/be-latn/holidays.json new file mode 100644 index 000000000..fda504206 --- /dev/null +++ b/lang/belarus/be-latn/holidays.json @@ -0,0 +1,12 @@ +{ + "Новы год": "Novy hod", + "Новы год (другі дзень)": "Novy hod (druhi dzień)", + "Нараджэнне Хрыстова (праваслаўнае Раство)": "Naradžeńnie Chrystova (pravasłaŭnaje Rastvo)", + "Дзень жанчын": "Dzień žančyn", + "Свята працы": "Sviata pracy", + "Дзень Перамогі": "Dzień Pieramohi", + "Дзень Незалежнасці": "Dzień Niezaležnaści", + "Дзень Кастрычніцкай рэвалюцыі": "Dzień Kastryčnickaj revalucyi", + "Нараджэнне Хрыстова (каталіцкае Раство)": "Naradžeńnie Chrystova (katalickaje Rastvo)", + "Радаўніца": "Radaŭnica" +} diff --git a/lang/belarus/en/holidays.json b/lang/belarus/en/holidays.json new file mode 100644 index 000000000..89c241bcd --- /dev/null +++ b/lang/belarus/en/holidays.json @@ -0,0 +1,12 @@ +{ + "Новы год": "New Year's Day", + "Новы год (другі дзень)": "New Year's Day (second day)", + "Нараджэнне Хрыстова (праваслаўнае Раство)": "Orthodox Christmas", + "Дзень жанчын": "Women's Day", + "Свята працы": "Labor Day", + "Дзень Перамогі": "Victory Day", + "Дзень Незалежнасці": "Independence Day", + "Дзень Кастрычніцкай рэвалюцыі": "October Revolution Day", + "Нараджэнне Хрыстова (каталіцкае Раство)": "Catholic Christmas", + "Радаўніца": "Radaunitsa" +} diff --git a/lang/belarus/ru/holidays.json b/lang/belarus/ru/holidays.json new file mode 100644 index 000000000..266eb0cef --- /dev/null +++ b/lang/belarus/ru/holidays.json @@ -0,0 +1,12 @@ +{ + "Новы год": "Новый год", + "Новы год (другі дзень)": "Новый год (второй день)", + "Нараджэнне Хрыстова (праваслаўнае Раство)": "Православное Рождество", + "Дзень жанчын": "Международный женский день", + "Свята працы": "День труда", + "Дзень Перамогі": "День Победы", + "Дзень Незалежнасці": "День Независимости", + "Дзень Кастрычніцкай рэвалюцыі": "День Октябрьской революции", + "Нараджэнне Хрыстова (каталіцкае Раство)": "Католическое Рождество", + "Радаўніца": "Радуница" +} diff --git a/src/Countries/Belarus.php b/src/Countries/Belarus.php new file mode 100644 index 000000000..f065d714e --- /dev/null +++ b/src/Countries/Belarus.php @@ -0,0 +1,38 @@ + '01-01', + 'Новы год (другі дзень)' => '01-02', + 'Нараджэнне Хрыстова (праваслаўнае Раство)' => '01-07', + 'Дзень жанчын' => '03-08', + 'Свята працы' => '05-01', + 'Дзень Перамогі' => '05-09', + 'Дзень Незалежнасці' => '07-03', + 'Дзень Кастрычніцкай рэвалюцыі' => '11-07', + 'Нараджэнне Хрыстова (каталіцкае Раство)' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->orthodoxEaster($year); + + return [ + 'Радаўніца' => $easter->addDays(9), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays.snap b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays.snap new file mode 100644 index 000000000..7f456be80 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "\u041d\u043e\u0432\u044b \u0433\u043e\u0434", + "date": "2024-01-01" + }, + { + "name": "\u041d\u043e\u0432\u044b \u0433\u043e\u0434 (\u0434\u0440\u0443\u0433\u0456 \u0434\u0437\u0435\u043d\u044c)", + "date": "2024-01-02" + }, + { + "name": "\u041d\u0430\u0440\u0430\u0434\u0436\u044d\u043d\u043d\u0435 \u0425\u0440\u044b\u0441\u0442\u043e\u0432\u0430 (\u043f\u0440\u0430\u0432\u0430\u0441\u043b\u0430\u045e\u043d\u0430\u0435 \u0420\u0430\u0441\u0442\u0432\u043e)", + "date": "2024-01-07" + }, + { + "name": "\u0414\u0437\u0435\u043d\u044c \u0436\u0430\u043d\u0447\u044b\u043d", + "date": "2024-03-08" + }, + { + "name": "\u0421\u0432\u044f\u0442\u0430 \u043f\u0440\u0430\u0446\u044b", + "date": "2024-05-01" + }, + { + "name": "\u0414\u0437\u0435\u043d\u044c \u041f\u0435\u0440\u0430\u043c\u043e\u0433\u0456", + "date": "2024-05-09" + }, + { + "name": "\u0420\u0430\u0434\u0430\u045e\u043d\u0456\u0446\u0430", + "date": "2024-05-14" + }, + { + "name": "\u0414\u0437\u0435\u043d\u044c \u041d\u0435\u0437\u0430\u043b\u0435\u0436\u043d\u0430\u0441\u0446\u0456", + "date": "2024-07-03" + }, + { + "name": "\u0414\u0437\u0435\u043d\u044c \u041a\u0430\u0441\u0442\u0440\u044b\u0447\u043d\u0456\u0446\u043a\u0430\u0439 \u0440\u044d\u0432\u0430\u043b\u044e\u0446\u044b\u0456", + "date": "2024-11-07" + }, + { + "name": "\u041d\u0430\u0440\u0430\u0434\u0436\u044d\u043d\u043d\u0435 \u0425\u0440\u044b\u0441\u0442\u043e\u0432\u0430 (\u043a\u0430\u0442\u0430\u043b\u0456\u0446\u043a\u0430\u0435 \u0420\u0430\u0441\u0442\u0432\u043e)", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Belarus_Lacinka.snap b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Belarus_Lacinka.snap new file mode 100644 index 000000000..3ce0d9150 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Belarus_Lacinka.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Novy hod", + "date": "2024-01-01" + }, + { + "name": "Novy hod (druhi dzie\u0144)", + "date": "2024-01-02" + }, + { + "name": "Narad\u017ee\u0144nie Chrystova (pravas\u0142a\u016dnaje Rastvo)", + "date": "2024-01-07" + }, + { + "name": "Dzie\u0144 \u017ean\u010dyn", + "date": "2024-03-08" + }, + { + "name": "Sviata pracy", + "date": "2024-05-01" + }, + { + "name": "Dzie\u0144 Pieramohi", + "date": "2024-05-09" + }, + { + "name": "Rada\u016dnica", + "date": "2024-05-14" + }, + { + "name": "Dzie\u0144 Niezale\u017ena\u015bci", + "date": "2024-07-03" + }, + { + "name": "Dzie\u0144 Kastry\u010dnickaj revalucyi", + "date": "2024-11-07" + }, + { + "name": "Narad\u017ee\u0144nie Chrystova (katalickaje Rastvo)", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_English.snap b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_English.snap new file mode 100644 index 000000000..a57b40011 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_English.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "New Year's Day (second day)", + "date": "2024-01-02" + }, + { + "name": "Orthodox Christmas", + "date": "2024-01-07" + }, + { + "name": "Women's Day", + "date": "2024-03-08" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Victory Day", + "date": "2024-05-09" + }, + { + "name": "Radaunitsa", + "date": "2024-05-14" + }, + { + "name": "Independence Day", + "date": "2024-07-03" + }, + { + "name": "October Revolution Day", + "date": "2024-11-07" + }, + { + "name": "Catholic Christmas", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Russian.snap b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Russian.snap new file mode 100644 index 000000000..1c93d7360 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BelarusTest/it_can_calculate_belarus_holidays_in_Russian.snap @@ -0,0 +1,42 @@ +[ + { + "name": "\u041d\u043e\u0432\u044b\u0439 \u0433\u043e\u0434", + "date": "2024-01-01" + }, + { + "name": "\u041d\u043e\u0432\u044b\u0439 \u0433\u043e\u0434 (\u0432\u0442\u043e\u0440\u043e\u0439 \u0434\u0435\u043d\u044c)", + "date": "2024-01-02" + }, + { + "name": "\u041f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u043e\u0435 \u0420\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u043e", + "date": "2024-01-07" + }, + { + "name": "\u041c\u0435\u0436\u0434\u0443\u043d\u0430\u0440\u043e\u0434\u043d\u044b\u0439 \u0436\u0435\u043d\u0441\u043a\u0438\u0439 \u0434\u0435\u043d\u044c", + "date": "2024-03-08" + }, + { + "name": "\u0414\u0435\u043d\u044c \u0442\u0440\u0443\u0434\u0430", + "date": "2024-05-01" + }, + { + "name": "\u0414\u0435\u043d\u044c \u041f\u043e\u0431\u0435\u0434\u044b", + "date": "2024-05-09" + }, + { + "name": "\u0420\u0430\u0434\u0443\u043d\u0438\u0446\u0430", + "date": "2024-05-14" + }, + { + "name": "\u0414\u0435\u043d\u044c \u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438", + "date": "2024-07-03" + }, + { + "name": "\u0414\u0435\u043d\u044c \u041e\u043a\u0442\u044f\u0431\u0440\u044c\u0441\u043a\u043e\u0439 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u0438", + "date": "2024-11-07" + }, + { + "name": "\u041a\u0430\u0442\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0420\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u043e", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BelarusTest.php b/tests/Countries/BelarusTest.php new file mode 100644 index 000000000..5fc33f7e7 --- /dev/null +++ b/tests/Countries/BelarusTest.php @@ -0,0 +1,54 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate belarus holidays in English', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'by', locale: 'en')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate belarus holidays in Belarus Lacinka', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'by', locale: 'be-latn')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate belarus holidays in Russian', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'by', locale: 'ru')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From ab04ec4b4dad19258f2e9142a28fbfa96962b00e Mon Sep 17 00:00:00 2001 From: Arne Breitsprecher Date: Thu, 25 Jan 2024 09:21:27 +0100 Subject: [PATCH 35/99] Adding German holidays (#8) * Create Germany.php * Create GermanyTest.php * Test Snapshot * Change easter to class method * Adding regional state holidays * Adding state testing snapshots * Pint fixes * Moving failing test to fixed TestTime * phpstan fixing return * Test fix: Count regional holidays by numbers from wikipedia & Fixing Bug for regional SN,BB, HE --- src/Countries/Germany.php | 189 ++++++++++++++++++ .../it_can_calculate_german_holidays.snap | 38 ++++ ...with_data_set____BB___12_____BB___12_.snap | 50 +++++ ...with_data_set____BE___10_____BE___10_.snap | 42 ++++ ...with_data_set____BW___12_____BW___12_.snap | 50 +++++ ...with_data_set____BY___13_____BY___13_.snap | 54 +++++ ...with_data_set____HB___10_____HB___10_.snap | 42 ++++ ...with_data_set____HE___12_____HE___12_.snap | 50 +++++ ...with_data_set____HH___10_____HH___10_.snap | 42 ++++ ...with_data_set____MV___11_____MV___11_.snap | 46 +++++ ...with_data_set____NI___10_____NI___10_.snap | 42 ++++ ...with_data_set____NW___11_____NW___11_.snap | 46 +++++ ...with_data_set____RP___11_____RP___11_.snap | 46 +++++ ...with_data_set____SH___10_____SH___10_.snap | 42 ++++ ...with_data_set____SL___12_____SL___12_.snap | 50 +++++ ...with_data_set____SN___11_____SN___11_.snap | 46 +++++ ...with_data_set____ST___11_____ST___11_.snap | 46 +++++ ...with_data_set____TH___11_____TH___11_.snap | 46 +++++ tests/Countries/GermanyTest.php | 80 ++++++++ 19 files changed, 1047 insertions(+) create mode 100644 src/Countries/Germany.php create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_calculate_german_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BB___12_____BB___12_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BE___10_____BE___10_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BW___12_____BW___12_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BY___13_____BY___13_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HB___10_____HB___10_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HE___12_____HE___12_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HH___10_____HH___10_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____MV___11_____MV___11_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NI___10_____NI___10_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NW___11_____NW___11_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____RP___11_____RP___11_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SH___10_____SH___10_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SL___12_____SL___12_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SN___11_____SN___11_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____ST___11_____ST___11_.snap create mode 100644 tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____TH___11_____TH___11_.snap create mode 100644 tests/Countries/GermanyTest.php diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php new file mode 100644 index 000000000..6bdc0da33 --- /dev/null +++ b/src/Countries/Germany.php @@ -0,0 +1,189 @@ +format('m-d'); + } + + /** @return array */ + protected function historicalHolidays(int $year): array + { + $historicalHolidays = []; + if ($year >= 1990 && $year <= 1994) { + $historicalHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year); + } + if ($year === 2017) { + $historicalHolidays['Reformationstag'] = '10-31'; + } + + return $historicalHolidays; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + + return array_merge([ + 'Neujahr' => '01-01', + 'Tag der deutschen Einheit' => '10-03', + 'Tag der Arbeit' => '05-01', + '1. Weihnachtstag' => '12-25', + '2. Weihnachtstag' => '12-26', + ], $this->variableHolidays($year), $this->historicalHolidays($year), $this->regionHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + + $easter = $this->easter($year); + + return [ + 'Karfreitag' => $easter->subDays(2), + 'Ostermontag' => $easter->addDay(), + 'Himmelfahrt' => $easter->addDays(39), + 'Pfingstmontag' => $easter->addDays(50), + ]; + } + + /** @return array */ + protected function regionHolidays(int $year): array + { + $easter = $this->easter($year); + + switch ($this->region) { + case 'DE-BW': + return [ + 'Heilige Drei Könige' => '01-06', + 'Fronleichnam' => $easter->addDays(60), + 'Allerheiligen' => '11-01', + ]; + case 'DE-BY': + return [ + 'Heilige Drei Könige' => '01-06', + 'Fronleichnam' => $easter->addDays(60), + 'Allerheiligen' => '11-01', + 'Mariä Himmelfahrt' => '08-15', + ]; + + case 'DE-BE': + if ($year >= 2019) { + return [ + 'Internationaler Frauentag' => '03-08', + ]; + } else { + return [ + + ]; + } + case 'DE-BB': + if ($year >= 1991) { + return [ + 'Ostersonntag' => $easter, + 'Reformationstag' => '10-31', + 'Pfingstsonntag' => $easter->addDays(49), + ]; + } else { + return [ + 'Ostersonntag' => $easter, + 'Pfingstsonntag' => $easter->addDays(49), + ]; + } + case 'DE-HB': + case 'DE-HH': + case 'DE-NI': + case 'DE-SH': + if ($year >= 2017) { + return [ + 'Reformationstag' => '10-31', + ]; + } else { + return [ + + ]; + } + + case 'DE-HE': + return [ + 'Ostersonntag' => $easter, + 'Pfingstsonntag' => $easter->addDays(49), + 'Fronleichnam' => $easter->addDays(60), + ]; + case 'DE-MV': + $mvHolidays = []; + if ($year >= 1990) { + $mvHolidays['Reformationstag'] = '10-31'; + } + if ($year >= 2023) { + $mvHolidays['Internationaler Frauentag'] = '03-08'; + } + + return $mvHolidays; + case 'DE-NW': + case 'DE-RP': + + return [ + 'Fronleichnam' => $easter->addDays(60), + 'Allerheiligen' => '11-01', + ]; + case 'DE-SL': + return [ + 'Fronleichnam' => $easter->addDays(60), + 'Allerheiligen' => '11-01', + 'Mariä Himmelfahrt' => '08-15', + ]; + case 'DE-SN': + $snHolidays = []; + if ($year >= 1990) { + $snHolidays['Reformationstag'] = '10-31'; + + } + if ($year > 1994) { + $snHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year); + + } + + return $snHolidays; + case 'DE-ST': + $stHolidays = []; + if ($year >= 1990) { + $stHolidays['Reformationstag'] = '10-31'; + + } + if ($year >= 1991) { + $stHolidays['Heilige Drei Könige'] = '01-06'; + } + case 'DE-TH': + $thHolidays = []; + if ($year >= 1990) { + $thHolidays['Reformationstag'] = '10-31'; + } + if ($year >= 2019) { + $thHolidays['Weltkindertag'] = '09-20'; + } + + return $thHolidays; + + } + + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_calculate_german_holidays.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_calculate_german_holidays.snap new file mode 100644 index 000000000..74db923c9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_calculate_german_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BB___12_____BB___12_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BB___12_____BB___12_.snap new file mode 100644 index 000000000..03823bf9f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BB___12_____BB___12_.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostersonntag", + "date": "2024-03-31" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstsonntag", + "date": "2024-05-19" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BE___10_____BE___10_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BE___10_____BE___10_.snap new file mode 100644 index 000000000..bcaf49aa5 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BE___10_____BE___10_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Internationaler Frauentag", + "date": "2024-03-08" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BW___12_____BW___12_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BW___12_____BW___12_.snap new file mode 100644 index 000000000..0c50fb2cc --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BW___12_____BW___12_.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Heilige Drei K\u00f6nige", + "date": "2024-01-06" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Fronleichnam", + "date": "2024-05-30" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BY___13_____BY___13_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BY___13_____BY___13_.snap new file mode 100644 index 000000000..dcd248232 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____BY___13_____BY___13_.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Heilige Drei K\u00f6nige", + "date": "2024-01-06" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "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": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HB___10_____HB___10_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HB___10_____HB___10_.snap new file mode 100644 index 000000000..bb14985fc --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HB___10_____HB___10_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HE___12_____HE___12_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HE___12_____HE___12_.snap new file mode 100644 index 000000000..3f4e98c2b --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HE___12_____HE___12_.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostersonntag", + "date": "2024-03-31" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstsonntag", + "date": "2024-05-19" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Fronleichnam", + "date": "2024-05-30" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HH___10_____HH___10_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HH___10_____HH___10_.snap new file mode 100644 index 000000000..bb14985fc --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____HH___10_____HH___10_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____MV___11_____MV___11_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____MV___11_____MV___11_.snap new file mode 100644 index 000000000..e672cac96 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____MV___11_____MV___11_.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Internationaler Frauentag", + "date": "2024-03-08" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NI___10_____NI___10_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NI___10_____NI___10_.snap new file mode 100644 index 000000000..bb14985fc --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NI___10_____NI___10_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NW___11_____NW___11_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NW___11_____NW___11_.snap new file mode 100644 index 000000000..8ead1399c --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____NW___11_____NW___11_.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Fronleichnam", + "date": "2024-05-30" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____RP___11_____RP___11_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____RP___11_____RP___11_.snap new file mode 100644 index 000000000..8ead1399c --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____RP___11_____RP___11_.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Fronleichnam", + "date": "2024-05-30" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SH___10_____SH___10_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SH___10_____SH___10_.snap new file mode 100644 index 000000000..bb14985fc --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SH___10_____SH___10_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SL___12_____SL___12_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SL___12_____SL___12_.snap new file mode 100644 index 000000000..41c9b5a7c --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SL___12_____SL___12_.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "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": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Allerheiligen", + "date": "2024-11-01" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SN___11_____SN___11_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SN___11_____SN___11_.snap new file mode 100644 index 000000000..814d58188 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____SN___11_____SN___11_.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "Bu\u00df- und Bettag", + "date": "2024-11-20" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____ST___11_____ST___11_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____ST___11_____ST___11_.snap new file mode 100644 index 000000000..cc02b4ad8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____ST___11_____ST___11_.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Weltkindertag", + "date": "2024-09-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____TH___11_____TH___11_.snap b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____TH___11_____TH___11_.snap new file mode 100644 index 000000000..cc02b4ad8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GermanyTest/it_can_get_german_holidays_for_other_regions_with_data_set____TH___11_____TH___11_.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Neujahr", + "date": "2024-01-01" + }, + { + "name": "Karfreitag", + "date": "2024-03-29" + }, + { + "name": "Ostermontag", + "date": "2024-04-01" + }, + { + "name": "Tag der Arbeit", + "date": "2024-05-01" + }, + { + "name": "Himmelfahrt", + "date": "2024-05-09" + }, + { + "name": "Pfingstmontag", + "date": "2024-05-20" + }, + { + "name": "Weltkindertag", + "date": "2024-09-20" + }, + { + "name": "Tag der deutschen Einheit", + "date": "2024-10-03" + }, + { + "name": "Reformationstag", + "date": "2024-10-31" + }, + { + "name": "1. Weihnachtstag", + "date": "2024-12-25" + }, + { + "name": "2. Weihnachtstag", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php new file mode 100644 index 000000000..d1a6cba79 --- /dev/null +++ b/tests/Countries/GermanyTest.php @@ -0,0 +1,80 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('can calculate german historical reformationstag in year 2017', function () { + CarbonImmutable::setTestNowAndTimezone('2017-01-01'); + + $holiday = Holidays::for('de')->isHoliday('2017-10-31'); + + expect($holiday)->toBeTrue(); + +}); +it('can calculate german historical reformationstag in year 2018 is not a holiday', function () { + CarbonImmutable::setTestNowAndTimezone('2018-01-01'); + + $holiday = Holidays::for('de')->isHoliday('2018-10-31'); + + expect($holiday)->toBeFalse(); + +}); + +it('can calculate german buß- und bettag in year 1990', function () { + CarbonImmutable::setTestNowAndTimezone('1990-01-01'); + + $holiday = Holidays::for('de')->isHoliday('1990-10-03'); + + expect($holiday)->toBeTrue(); + +}); +/* + This test will check for all regional holidays in Germany. Source: https://en.wikipedia.org/wiki/Public_holidays_in_Germany + The total numbers are referenced in the wikipedia article. +*/ +it('can get german holidays for other regions', function (string $region, int $totalHolidays) { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + $holidays = Holidays::for(Germany::make('DE-'.$region))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(count($holidays))->toBe($totalHolidays); + + expect(formatDates($holidays))->toMatchSnapshot(); +})->with( + [ + ['BW',12], + ['BY',13], + ['BE',10], + ['BB',12], + ['HB',10], + ['HH',10], + ['HE',12], + ['MV',11], + ['NI',10], + ['NW',11], + ['RP',11], + ['SL',12], + ['SN',11], + ['ST',11], + ['SH',10], + ['TH',11] ] +); From eebcfd2a7f787d5378253dd729f179bab09b11f5 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 08:21:46 +0000 Subject: [PATCH 36/99] Fix styling --- tests/Countries/GermanyTest.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index d1a6cba79..3cb388e5b 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -61,20 +61,20 @@ expect(formatDates($holidays))->toMatchSnapshot(); })->with( [ - ['BW',12], - ['BY',13], - ['BE',10], - ['BB',12], - ['HB',10], - ['HH',10], - ['HE',12], - ['MV',11], - ['NI',10], - ['NW',11], - ['RP',11], - ['SL',12], - ['SN',11], - ['ST',11], - ['SH',10], - ['TH',11] ] + ['BW', 12], + ['BY', 13], + ['BE', 10], + ['BB', 12], + ['HB', 10], + ['HH', 10], + ['HE', 12], + ['MV', 11], + ['NI', 10], + ['NW', 11], + ['RP', 11], + ['SL', 12], + ['SN', 11], + ['ST', 11], + ['SH', 10], + ['TH', 11]] ); From 7f169c09f46c3dc8edc90c8063001d9428eb2f2b Mon Sep 17 00:00:00 2001 From: Patrick O'Meara Date: Thu, 25 Jan 2024 19:34:56 +1100 Subject: [PATCH 37/99] Add Australian Holidays (#43) * Add Australian Holidays These are the national holidays, that all states observe. * Use the easter method * Add state regional holidays * Clean up the name of whoever's birthday it is. * Added modify call on CarbonImmutable to PHPStan baseline --- phpstan-baseline.neon | 5 + src/Countries/Australia.php | 119 ++++++++++++++++ .../it_can_calculate_australian_holidays.snap | 30 ++++ ...stralian_holidays_for_a_specific_year.snap | 30 ++++ ...alculate_regional_australian_holidays.snap | 54 ++++++++ tests/Countries/AustraliaTest.php | 130 ++++++++++++++++++ tests/Pest.php | 11 ++ 7 files changed, 379 insertions(+) create mode 100644 src/Countries/Australia.php create mode 100644 tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays_for_a_specific_year.snap create mode 100644 tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_regional_australian_holidays.snap create mode 100644 tests/Countries/AustraliaTest.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d237ce635..31f8d0e58 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Cannot call method modify\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 1 + path: src/Countries/Australia.php + - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php new file mode 100644 index 000000000..87dcb6a6f --- /dev/null +++ b/src/Countries/Australia.php @@ -0,0 +1,119 @@ + '01-01', + 'Australia Day' => '01-26', + 'Anzac Day' => '04-25', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year)->setTimezone('Australia/Sydney'); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + // https://en.wikipedia.org/wiki/Public_holidays_in_Australia + ...array_filter(match($this->region) { + 'act' => [ + 'Canberra Day' => CarbonImmutable::parse("second monday of march {$year}"), + 'Easter Saturday' => $easter->subDay(), + 'Easter Sunday' => $easter, + 'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)->modify('monday'), + $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), + 'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"), + ], + 'nsw' => [ + 'Easter Saturday' => $easter->subDay(), + 'Easter Sunday' => $easter, + $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), + 'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"), + ], + 'nt' => [ + 'Easter Saturday' => $easter->subDay(), + 'May Day' => CarbonImmutable::parse("first monday of may {$year}"), + 'Picnic Day' => CarbonImmutable::parse("first monday of august {$year}"), + ], + 'qld' => [ + 'The day after Good Friday' => $easter->subDay(), + 'Easter Sunday' => $easter, + 'Labour Day' => CarbonImmutable::parse("first monday of may {$year}"), + $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("first monday of october {$year}"), + ], + 'sa' => [ + 'Adelaide Cup Day' => $year < 2006 + ? CarbonImmutable::parse("third monday of may {$year}") + : CarbonImmutable::parse("second monday of march {$year}"), + 'The day after Good Friday' => $easter->subDay(), + $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), + 'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"), + ], + 'tas' => [ + 'Eight Hours Day' => CarbonImmutable::parse("second monday of march {$year}"), + $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), + ], + 'vic' => [ + 'Labour Day' => CarbonImmutable::parse("second monday of march {$year}"), + 'Saturday before Easter Sunday' => $easter->subDay(), + 'Easter Sunday' => $easter, + $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), + 'Friday before AFL Grand Final' => $this->fridayBeforeAflGrandFinal($year), + 'Melbourne Cup' => CarbonImmutable::parse("first tuesday of november {$year}"), + ], + 'wa' => [ + 'Labour Day' => CarbonImmutable::parse("first monday of march {$year}"), + 'Easter Sunday' => $easter, + 'Western Australia Day' => CarbonImmutable::parse("first monday of june {$year}"), + $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("last monday of september {$year}"), + ], + default => [], + }), + ]; + } + + // https://business.vic.gov.au/business-information/public-holidays/victorian-public-holidays-2025 + // https://en.wikipedia.org/wiki/List_of_VFL/AFL_premiers#VFL/AFL_premierships + protected function fridayBeforeAflGrandFinal(int $year): ?CarbonImmutable + { + if ($year < 2015) { + return null; + } + + return match ($year) { + 2015 => CarbonImmutable::parse('2015-10-02'), + 2020 => CarbonImmutable::parse('2020-10-23'), + 2022 => CarbonImmutable::parse('2022-09-23'), + default => CarbonImmutable::parse("last friday of september {$year}"), + }; + } + + protected function sovereignBirthdayKey(int $year): string + { + // https://www.abc.net.au/news/2022-09-22/queens-birthday-public-holiday-becomes-kings-birthday/101453408 + $changeYear = $this->region === 'wa' ? 2022 : 2023; + + return $year >= $changeYear ? "King's Birthday" : "Queen's Birthday"; + } +} diff --git a/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays.snap b/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays.snap new file mode 100644 index 000000000..ebc8a6046 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays.snap @@ -0,0 +1,30 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Australia Day", + "date": "2024-01-26" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Anzac Day", + "date": "2024-04-25" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays_for_a_specific_year.snap b/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays_for_a_specific_year.snap new file mode 100644 index 000000000..340c74d77 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_australian_holidays_for_a_specific_year.snap @@ -0,0 +1,30 @@ +[ + { + "name": "New Year's Day", + "date": "2025-01-01" + }, + { + "name": "Australia Day", + "date": "2025-01-26" + }, + { + "name": "Good Friday", + "date": "2025-04-18" + }, + { + "name": "Easter Monday", + "date": "2025-04-21" + }, + { + "name": "Anzac Day", + "date": "2025-04-25" + }, + { + "name": "Christmas Day", + "date": "2025-12-25" + }, + { + "name": "Boxing Day", + "date": "2025-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_regional_australian_holidays.snap b/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_regional_australian_holidays.snap new file mode 100644 index 000000000..6ccbd6ab5 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AustraliaTest/it_can_calculate_regional_australian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Australia Day", + "date": "2024-01-26" + }, + { + "name": "Labour Day", + "date": "2024-03-11" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Saturday before Easter Sunday", + "date": "2024-03-30" + }, + { + "name": "Easter Sunday", + "date": "2024-03-31" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Anzac Day", + "date": "2024-04-25" + }, + { + "name": "King's Birthday", + "date": "2024-06-10" + }, + { + "name": "Friday before AFL Grand Final", + "date": "2024-09-27" + }, + { + "name": "Melbourne Cup", + "date": "2024-11-05" + }, + { + "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/AustraliaTest.php b/tests/Countries/AustraliaTest.php new file mode 100644 index 000000000..e274579df --- /dev/null +++ b/tests/Countries/AustraliaTest.php @@ -0,0 +1,130 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate australian holidays for a specific year', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne'); + + $holidays = Holidays::for(country: 'au', year: 2025)->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate regional australian holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne'); + + $holidays = Holidays::for(Australia::make('vic'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate the day before afl grand final', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-22', 'Australia/Melbourne'); + + $holidays = Holidays::for(Australia::make('vic'))->get(); + + expect(findDate($holidays, 'Friday before AFL Grand Final')) + ->toEqual(CarbonImmutable::create(2021, 9, 24)); +}); + +it('can calculate the day before afl grand final during lockdown', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-22', 'Australia/Melbourne'); + + $holidays = Holidays::for(Australia::make('vic'))->get(); + + expect(findDate($holidays, 'Friday before AFL Grand Final')) + ->toEqual(CarbonImmutable::create(2020, 10, 23)); +}); + +it('does not return the day before afl grand final before 2015', function () { + CarbonImmutable::setTestNowAndTimezone('2014-01-22', 'Australia/Melbourne'); + + $holidays = Holidays::for(Australia::make('vic'))->get(); + + expect(findDate($holidays, 'Friday before AFL Grand Final')) + ->toBeNull(); +}); + +it("returns queen's birthday before her death", function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-22', 'Australia/Perth'); + + $holidays = Holidays::for(Australia::make('wa'))->get(); + + expect(findDate($holidays, "Queen's Birthday")) + ->toEqual(CarbonImmutable::create(2021, 9, 27)); + + expect(findDate($holidays, "King's Birthday")) + ->toBeNull(); +}); + +it("returns king's birthday after her death", function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-22', 'Australia/Perth'); + + $holidays = Holidays::for(Australia::make('wa'))->get(); + + expect(findDate($holidays, "Queen's Birthday")) + ->toBeNull(); + + expect(findDate($holidays, "King's Birthday")) + ->toEqual(CarbonImmutable::create(2022, 9, 26)); +}); + +it('can calculate Adelaide Cup Day before 2006', function () { + CarbonImmutable::setTestNowAndTimezone('2005-01-22', 'Australia/Adelaide'); + + $holidays = Holidays::for(Australia::make('sa'))->get(); + + expect(findDate($holidays, 'Adelaide Cup Day')) + ->toEqual(CarbonImmutable::create(2005, 5, 16)); +}); + +it('can calculate Adelaide Cup Day after 2006', function () { + CarbonImmutable::setTestNowAndTimezone('2007-01-22', 'Australia/Adelaide'); + + $holidays = Holidays::for(Australia::make('sa'))->get(); + + expect(findDate($holidays, 'Adelaide Cup Day')) + ->toEqual(CarbonImmutable::create(2007, 3, 12)); +}); + +it('can calculate Reconciliation Day on 27 May', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Canberra'); + + $holidays = Holidays::for(Australia::make('act'))->get(); + + expect(findDate($holidays, 'Reconciliation Day')) + ->toEqual(CarbonImmutable::create(2024, 5, 27)); +}); + +it('can calculate Reconciliation Day after 27 May', function () { + CarbonImmutable::setTestNowAndTimezone('2025-01-22', 'Australia/Canberra'); + + $holidays = Holidays::for(Australia::make('act'))->get(); + + expect(findDate($holidays, 'Reconciliation Day')) + ->toEqual(CarbonImmutable::create(2025, 6, 2)); +}); diff --git a/tests/Pest.php b/tests/Pest.php index 310516cb7..b17024094 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -20,3 +20,14 @@ function formatDates(array $holidays): array return $holidays; } + +function findDate(array $holidays, string $name): ?Carbon\CarbonImmutable +{ + foreach ($holidays as $holiday) { + if ($holiday['name'] === $name) { + return $holiday['date']; + } + } + + return null; +} From ed1f589369ef9e2bddd0b6f18f6fa2cabdd0723c Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 08:35:24 +0000 Subject: [PATCH 38/99] Fix styling --- src/Countries/Australia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 87dcb6a6f..0b43bae4e 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -36,7 +36,7 @@ protected function variableHolidays(int $year): array 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), // https://en.wikipedia.org/wiki/Public_holidays_in_Australia - ...array_filter(match($this->region) { + ...array_filter(match ($this->region) { 'act' => [ 'Canberra Day' => CarbonImmutable::parse("second monday of march {$year}"), 'Easter Saturday' => $easter->subDay(), From 4de040f75e624397e5a3f6aa4caddaa15545bccc Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:54:30 +0100 Subject: [PATCH 39/99] remove all timezones from tests country holidays should be properly calculated in every timezone --- tests/Countries/AndorraTest.php | 2 +- tests/Countries/AustraliaTest.php | 24 +++++++++++------------ tests/Countries/AustriaTest.php | 2 +- tests/Countries/BangladeshTest.php | 2 +- tests/Countries/BelarusTest.php | 8 ++++---- tests/Countries/BelgiumTest.php | 2 +- tests/Countries/BoliviaTest.php | 2 +- tests/Countries/BrazilTest.php | 2 +- tests/Countries/CanadaTest.php | 2 +- tests/Countries/ColombiaTest.php | 2 +- tests/Countries/CroatiaTest.php | 2 +- tests/Countries/CzechiaTest.php | 2 +- tests/Countries/DenmarkTest.php | 2 +- tests/Countries/DominicanRepublicTest.php | 2 +- tests/Countries/ElSalvadorTest.php | 2 +- tests/Countries/EstoniaTest.php | 2 +- tests/Countries/FinlandTest.php | 4 ++-- tests/Countries/FranceTest.php | 6 +++--- tests/Countries/GermanyTest.php | 10 +++++----- tests/Countries/GreeceTest.php | 2 +- tests/Countries/GuatemalaTest.php | 2 +- tests/Countries/HaitiTest.php | 2 +- tests/Countries/HungaryTest.php | 2 +- tests/Countries/IrelandTest.php | 2 +- tests/Countries/ItalyTest.php | 2 +- tests/Countries/JapanTest.php | 2 +- tests/Countries/KosovoTest.php | 2 +- tests/Countries/LatviaTest.php | 2 +- tests/Countries/LiechtensteinTest.php | 2 +- tests/Countries/LithuaniaTest.php | 2 +- tests/Countries/LuxembourgTest.php | 2 +- tests/Countries/MalawiTest.php | 2 +- tests/Countries/MexicoTest.php | 2 +- tests/Countries/NetherlandsTest.php | 2 +- tests/Countries/NicaraguaTest.php | 2 +- tests/Countries/NorthMacedoniaTest.php | 2 +- tests/Countries/NorwayTest.php | 2 +- tests/Countries/PanamaTest.php | 2 +- tests/Countries/PeruTest.php | 2 +- tests/Countries/PhilippinesTest.php | 2 +- tests/Countries/PolandTest.php | 2 +- tests/Countries/PortugalTest.php | 2 +- tests/Countries/RomaniaTest.php | 2 +- tests/Countries/SerbiaTest.php | 2 +- tests/Countries/SlovakiaTest.php | 2 +- tests/Countries/SouthAfricaTest.php | 2 +- tests/Countries/TurkeyTest.php | 2 +- tests/Countries/TurkmenistanTest.php | 2 +- tests/Countries/UgandaTest.php | 2 +- tests/Countries/UkraineTest.php | 2 +- tests/Countries/UnitedStatesTest.php | 4 ++-- tests/Countries/VenezuelaTest.php | 2 +- tests/Countries/ZambiaTest.php | 2 +- 53 files changed, 75 insertions(+), 75 deletions(-) diff --git a/tests/Countries/AndorraTest.php b/tests/Countries/AndorraTest.php index 43f1c49cc..184dad385 100644 --- a/tests/Countries/AndorraTest.php +++ b/tests/Countries/AndorraTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate andorra holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ad')->get(); diff --git a/tests/Countries/AustraliaTest.php b/tests/Countries/AustraliaTest.php index e274579df..be239874d 100644 --- a/tests/Countries/AustraliaTest.php +++ b/tests/Countries/AustraliaTest.php @@ -7,7 +7,7 @@ use Spatie\Holidays\Holidays; it('can calculate australian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne'); + CarbonImmutable::setTestNow('2024-01-22'); $holidays = Holidays::for(country: 'au')->get(); @@ -19,7 +19,7 @@ }); it('can calculate australian holidays for a specific year', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne'); + CarbonImmutable::setTestNow('2024-01-22'); $holidays = Holidays::for(country: 'au', year: 2025)->get(); @@ -31,7 +31,7 @@ }); it('can calculate regional australian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne'); + CarbonImmutable::setTestNow('2024-01-22'); $holidays = Holidays::for(Australia::make('vic'))->get(); @@ -43,7 +43,7 @@ }); it('can calculate the day before afl grand final', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-22', 'Australia/Melbourne'); + CarbonImmutable::setTestNow('2021-01-22'); $holidays = Holidays::for(Australia::make('vic'))->get(); @@ -52,7 +52,7 @@ }); it('can calculate the day before afl grand final during lockdown', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-22', 'Australia/Melbourne'); + CarbonImmutable::setTestNow('2020-01-22'); $holidays = Holidays::for(Australia::make('vic'))->get(); @@ -61,7 +61,7 @@ }); it('does not return the day before afl grand final before 2015', function () { - CarbonImmutable::setTestNowAndTimezone('2014-01-22', 'Australia/Melbourne'); + CarbonImmutable::setTestNow('2014-01-22'); $holidays = Holidays::for(Australia::make('vic'))->get(); @@ -70,7 +70,7 @@ }); it("returns queen's birthday before her death", function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-22', 'Australia/Perth'); + CarbonImmutable::setTestNow('2021-01-22', 'Australia/Perth'); $holidays = Holidays::for(Australia::make('wa'))->get(); @@ -82,7 +82,7 @@ }); it("returns king's birthday after her death", function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-22', 'Australia/Perth'); + CarbonImmutable::setTestNow('2022-01-22', 'Australia/Perth'); $holidays = Holidays::for(Australia::make('wa'))->get(); @@ -94,7 +94,7 @@ }); it('can calculate Adelaide Cup Day before 2006', function () { - CarbonImmutable::setTestNowAndTimezone('2005-01-22', 'Australia/Adelaide'); + CarbonImmutable::setTestNow('2005-01-22', 'Australia/Adelaide'); $holidays = Holidays::for(Australia::make('sa'))->get(); @@ -103,7 +103,7 @@ }); it('can calculate Adelaide Cup Day after 2006', function () { - CarbonImmutable::setTestNowAndTimezone('2007-01-22', 'Australia/Adelaide'); + CarbonImmutable::setTestNow('2007-01-22', 'Australia/Adelaide'); $holidays = Holidays::for(Australia::make('sa'))->get(); @@ -112,7 +112,7 @@ }); it('can calculate Reconciliation Day on 27 May', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Canberra'); + CarbonImmutable::setTestNow('2024-01-22', 'Australia/Canberra'); $holidays = Holidays::for(Australia::make('act'))->get(); @@ -121,7 +121,7 @@ }); it('can calculate Reconciliation Day after 27 May', function () { - CarbonImmutable::setTestNowAndTimezone('2025-01-22', 'Australia/Canberra'); + CarbonImmutable::setTestNow('2025-01-22', 'Australia/Canberra'); $holidays = Holidays::for(Australia::make('act'))->get(); diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 9018307f2..2e196c8ce 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate austrian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'at')->get(); diff --git a/tests/Countries/BangladeshTest.php b/tests/Countries/BangladeshTest.php index b5b0f0b59..d978a795d 100644 --- a/tests/Countries/BangladeshTest.php +++ b/tests/Countries/BangladeshTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate bangladesh holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'bd')->get(); diff --git a/tests/Countries/BelarusTest.php b/tests/Countries/BelarusTest.php index 5fc33f7e7..2f8d1be47 100644 --- a/tests/Countries/BelarusTest.php +++ b/tests/Countries/BelarusTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate belarus holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'by')->get(); @@ -18,7 +18,7 @@ }); it('can calculate belarus holidays in English', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'by', locale: 'en')->get(); @@ -30,7 +30,7 @@ }); it('can calculate belarus holidays in Belarus Lacinka', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'by', locale: 'be-latn')->get(); @@ -42,7 +42,7 @@ }); it('can calculate belarus holidays in Russian', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'by', locale: 'ru')->get(); diff --git a/tests/Countries/BelgiumTest.php b/tests/Countries/BelgiumTest.php index 822834377..173922950 100644 --- a/tests/Countries/BelgiumTest.php +++ b/tests/Countries/BelgiumTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate belgian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'be')->get(); diff --git a/tests/Countries/BoliviaTest.php b/tests/Countries/BoliviaTest.php index e1305657f..2c50b0130 100644 --- a/tests/Countries/BoliviaTest.php +++ b/tests/Countries/BoliviaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate bolivian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'bo')->get(); diff --git a/tests/Countries/BrazilTest.php b/tests/Countries/BrazilTest.php index 91be74d40..39668d09c 100644 --- a/tests/Countries/BrazilTest.php +++ b/tests/Countries/BrazilTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate brazil holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'br')->get(); diff --git a/tests/Countries/CanadaTest.php b/tests/Countries/CanadaTest.php index 0619c4ecc..8d4e8ca23 100644 --- a/tests/Countries/CanadaTest.php +++ b/tests/Countries/CanadaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate canadian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ca')->get(); diff --git a/tests/Countries/ColombiaTest.php b/tests/Countries/ColombiaTest.php index 623ffd94b..7a97c0542 100644 --- a/tests/Countries/ColombiaTest.php +++ b/tests/Countries/ColombiaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate colombian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'co')->get(); diff --git a/tests/Countries/CroatiaTest.php b/tests/Countries/CroatiaTest.php index a78f5258a..e394ccba5 100644 --- a/tests/Countries/CroatiaTest.php +++ b/tests/Countries/CroatiaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate croatian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'hr')->get(); diff --git a/tests/Countries/CzechiaTest.php b/tests/Countries/CzechiaTest.php index 5b9f09bb3..b6b027f04 100644 --- a/tests/Countries/CzechiaTest.php +++ b/tests/Countries/CzechiaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate czech holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'cz')->get(); diff --git a/tests/Countries/DenmarkTest.php b/tests/Countries/DenmarkTest.php index dc01757ce..64034ba09 100644 --- a/tests/Countries/DenmarkTest.php +++ b/tests/Countries/DenmarkTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate danish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'da')->get(); diff --git a/tests/Countries/DominicanRepublicTest.php b/tests/Countries/DominicanRepublicTest.php index 954e2a589..166348751 100644 --- a/tests/Countries/DominicanRepublicTest.php +++ b/tests/Countries/DominicanRepublicTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate dominican republic holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'do')->get(); diff --git a/tests/Countries/ElSalvadorTest.php b/tests/Countries/ElSalvadorTest.php index 892a8f791..d6260641c 100644 --- a/tests/Countries/ElSalvadorTest.php +++ b/tests/Countries/ElSalvadorTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate el salvador holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'sv')->get(); diff --git a/tests/Countries/EstoniaTest.php b/tests/Countries/EstoniaTest.php index c7ee1aa0b..5f1c0ee79 100644 --- a/tests/Countries/EstoniaTest.php +++ b/tests/Countries/EstoniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate estonian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Europe/Tallinn'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ee')->get(); diff --git a/tests/Countries/FinlandTest.php b/tests/Countries/FinlandTest.php index 565dc1623..ac347ba0e 100644 --- a/tests/Countries/FinlandTest.php +++ b/tests/Countries/FinlandTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate finnish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'fi')->get(); @@ -19,7 +19,7 @@ }); it('can get finnish holidays in swedish', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'fi', locale: 'sv')->get(); diff --git a/tests/Countries/FranceTest.php b/tests/Countries/FranceTest.php index 358f8b1c0..300881b1e 100644 --- a/tests/Countries/FranceTest.php +++ b/tests/Countries/FranceTest.php @@ -7,7 +7,7 @@ use Spatie\Holidays\Holidays; it('can calculate french holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'fr')->get(); @@ -19,7 +19,7 @@ }); it('can calculate french easter based region holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(France::make('FR-57'))->get(); @@ -31,7 +31,7 @@ }); it('can calculate french date based regional holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(France::make('FR-BL'))->get(); diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index 3cb388e5b..b6a4f710f 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -7,7 +7,7 @@ use Spatie\Holidays\Holidays; it('can calculate german holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'de')->get(); @@ -20,7 +20,7 @@ }); it('can calculate german historical reformationstag in year 2017', function () { - CarbonImmutable::setTestNowAndTimezone('2017-01-01'); + CarbonImmutable::setTestNow('2017-01-01'); $holiday = Holidays::for('de')->isHoliday('2017-10-31'); @@ -28,7 +28,7 @@ }); it('can calculate german historical reformationstag in year 2018 is not a holiday', function () { - CarbonImmutable::setTestNowAndTimezone('2018-01-01'); + CarbonImmutable::setTestNow('2018-01-01'); $holiday = Holidays::for('de')->isHoliday('2018-10-31'); @@ -37,7 +37,7 @@ }); it('can calculate german buß- und bettag in year 1990', function () { - CarbonImmutable::setTestNowAndTimezone('1990-01-01'); + CarbonImmutable::setTestNow('1990-01-01'); $holiday = Holidays::for('de')->isHoliday('1990-10-03'); @@ -49,7 +49,7 @@ The total numbers are referenced in the wikipedia article. */ it('can get german holidays for other regions', function (string $region, int $totalHolidays) { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(Germany::make('DE-'.$region))->get(); expect($holidays) diff --git a/tests/Countries/GreeceTest.php b/tests/Countries/GreeceTest.php index 26805abbe..924065235 100644 --- a/tests/Countries/GreeceTest.php +++ b/tests/Countries/GreeceTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate hellenic holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'el')->get(); diff --git a/tests/Countries/GuatemalaTest.php b/tests/Countries/GuatemalaTest.php index 106ce7d4d..572dfbced 100644 --- a/tests/Countries/GuatemalaTest.php +++ b/tests/Countries/GuatemalaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate guatemalan holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gt')->get(); diff --git a/tests/Countries/HaitiTest.php b/tests/Countries/HaitiTest.php index 9e5632765..8a31192ea 100644 --- a/tests/Countries/HaitiTest.php +++ b/tests/Countries/HaitiTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate haiti holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ht')->get(); diff --git a/tests/Countries/HungaryTest.php b/tests/Countries/HungaryTest.php index f1c20ab25..4df502bb0 100644 --- a/tests/Countries/HungaryTest.php +++ b/tests/Countries/HungaryTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate hungarian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'hu')->get(); diff --git a/tests/Countries/IrelandTest.php b/tests/Countries/IrelandTest.php index 6ed63548f..1b3ff2c31 100644 --- a/tests/Countries/IrelandTest.php +++ b/tests/Countries/IrelandTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate irish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ie')->get(); diff --git a/tests/Countries/ItalyTest.php b/tests/Countries/ItalyTest.php index bd42933b6..55af7f42d 100644 --- a/tests/Countries/ItalyTest.php +++ b/tests/Countries/ItalyTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate italian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'it')->get(); diff --git a/tests/Countries/JapanTest.php b/tests/Countries/JapanTest.php index 3a948815e..3404f3a87 100644 --- a/tests/Countries/JapanTest.php +++ b/tests/Countries/JapanTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate japanese holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'jp')->get(); diff --git a/tests/Countries/KosovoTest.php b/tests/Countries/KosovoTest.php index 2621722ff..313bd3c0e 100644 --- a/tests/Countries/KosovoTest.php +++ b/tests/Countries/KosovoTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate kosovo holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'xk')->get(); diff --git a/tests/Countries/LatviaTest.php b/tests/Countries/LatviaTest.php index bce7acb68..1995326af 100644 --- a/tests/Countries/LatviaTest.php +++ b/tests/Countries/LatviaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate latvian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Europe/Riga'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'lv')->get(); diff --git a/tests/Countries/LiechtensteinTest.php b/tests/Countries/LiechtensteinTest.php index 00b62a5c6..3d385c0c3 100644 --- a/tests/Countries/LiechtensteinTest.php +++ b/tests/Countries/LiechtensteinTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate liechtenstein holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'li')->get(); diff --git a/tests/Countries/LithuaniaTest.php b/tests/Countries/LithuaniaTest.php index 310f58f5b..91fbd0c1b 100644 --- a/tests/Countries/LithuaniaTest.php +++ b/tests/Countries/LithuaniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate lithuanian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Europe/Vilnius'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'lt')->get(); diff --git a/tests/Countries/LuxembourgTest.php b/tests/Countries/LuxembourgTest.php index 48c69782c..13b500dc0 100644 --- a/tests/Countries/LuxembourgTest.php +++ b/tests/Countries/LuxembourgTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate luxembourgish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'lu')->get(); diff --git a/tests/Countries/MalawiTest.php b/tests/Countries/MalawiTest.php index bc2710322..0d30d5ad8 100644 --- a/tests/Countries/MalawiTest.php +++ b/tests/Countries/MalawiTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate malawi holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'mw')->get(); diff --git a/tests/Countries/MexicoTest.php b/tests/Countries/MexicoTest.php index dfd62a71e..c6be2b64e 100644 --- a/tests/Countries/MexicoTest.php +++ b/tests/Countries/MexicoTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate mexican holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'mx')->get(); diff --git a/tests/Countries/NetherlandsTest.php b/tests/Countries/NetherlandsTest.php index 993201976..b743adae2 100644 --- a/tests/Countries/NetherlandsTest.php +++ b/tests/Countries/NetherlandsTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate dutch holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'nl')->get(); diff --git a/tests/Countries/NicaraguaTest.php b/tests/Countries/NicaraguaTest.php index 840a0609a..d079f1cfd 100644 --- a/tests/Countries/NicaraguaTest.php +++ b/tests/Countries/NicaraguaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate nicaragua holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ni')->get(); diff --git a/tests/Countries/NorthMacedoniaTest.php b/tests/Countries/NorthMacedoniaTest.php index b68507ff4..5021d229e 100644 --- a/tests/Countries/NorthMacedoniaTest.php +++ b/tests/Countries/NorthMacedoniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate macedonian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'mk')->get(); diff --git a/tests/Countries/NorwayTest.php b/tests/Countries/NorwayTest.php index b9a342763..aba873f40 100644 --- a/tests/Countries/NorwayTest.php +++ b/tests/Countries/NorwayTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate norwegian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'no')->get(); diff --git a/tests/Countries/PanamaTest.php b/tests/Countries/PanamaTest.php index f848a26f2..215cf15ff 100644 --- a/tests/Countries/PanamaTest.php +++ b/tests/Countries/PanamaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate panama holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'pa')->get(); diff --git a/tests/Countries/PeruTest.php b/tests/Countries/PeruTest.php index aff6670eb..127694482 100644 --- a/tests/Countries/PeruTest.php +++ b/tests/Countries/PeruTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate peru holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'pe')->get(); diff --git a/tests/Countries/PhilippinesTest.php b/tests/Countries/PhilippinesTest.php index 4fd997173..22526a812 100644 --- a/tests/Countries/PhilippinesTest.php +++ b/tests/Countries/PhilippinesTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate philippine holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ph')->get(); diff --git a/tests/Countries/PolandTest.php b/tests/Countries/PolandTest.php index 25a75ebc7..ed8e5a333 100644 --- a/tests/Countries/PolandTest.php +++ b/tests/Countries/PolandTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate polish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'pl')->get(); diff --git a/tests/Countries/PortugalTest.php b/tests/Countries/PortugalTest.php index 7c2ed381f..db49ca87b 100644 --- a/tests/Countries/PortugalTest.php +++ b/tests/Countries/PortugalTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate portuguese holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'pt')->get(); diff --git a/tests/Countries/RomaniaTest.php b/tests/Countries/RomaniaTest.php index 80c177a98..95584b37d 100644 --- a/tests/Countries/RomaniaTest.php +++ b/tests/Countries/RomaniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate romanian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ro')->get(); diff --git a/tests/Countries/SerbiaTest.php b/tests/Countries/SerbiaTest.php index 1a44fbb44..4f8f640ef 100644 --- a/tests/Countries/SerbiaTest.php +++ b/tests/Countries/SerbiaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate serbian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'sr')->get(); diff --git a/tests/Countries/SlovakiaTest.php b/tests/Countries/SlovakiaTest.php index cb08ebd5a..65ab74a03 100644 --- a/tests/Countries/SlovakiaTest.php +++ b/tests/Countries/SlovakiaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate slovak holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'sk')->get(); diff --git a/tests/Countries/SouthAfricaTest.php b/tests/Countries/SouthAfricaTest.php index fe98169c5..86454c506 100644 --- a/tests/Countries/SouthAfricaTest.php +++ b/tests/Countries/SouthAfricaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate south africa holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'za')->get(); diff --git a/tests/Countries/TurkeyTest.php b/tests/Countries/TurkeyTest.php index 4deb524c9..129d4c4b6 100644 --- a/tests/Countries/TurkeyTest.php +++ b/tests/Countries/TurkeyTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate turkey holidays', function ($year) { - CarbonImmutable::setTestNowAndTimezone($year.'-01-01'); + CarbonImmutable::setTestNow($year.'-01-01'); $holidays = Holidays::for(country: 'tr')->get(); diff --git a/tests/Countries/TurkmenistanTest.php b/tests/Countries/TurkmenistanTest.php index 7f29d6635..c551f5720 100644 --- a/tests/Countries/TurkmenistanTest.php +++ b/tests/Countries/TurkmenistanTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate turkmen holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'tm')->get(); diff --git a/tests/Countries/UgandaTest.php b/tests/Countries/UgandaTest.php index 82ab1f7f6..93dd2ddcf 100644 --- a/tests/Countries/UgandaTest.php +++ b/tests/Countries/UgandaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate ugandan holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ug')->get(); diff --git a/tests/Countries/UkraineTest.php b/tests/Countries/UkraineTest.php index 04e9b3115..cabb8dd1c 100644 --- a/tests/Countries/UkraineTest.php +++ b/tests/Countries/UkraineTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate ukrainian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ua')->get(); diff --git a/tests/Countries/UnitedStatesTest.php b/tests/Countries/UnitedStatesTest.php index bdf277d2f..32ebff2bf 100644 --- a/tests/Countries/UnitedStatesTest.php +++ b/tests/Countries/UnitedStatesTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate united states holidays after 2021', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'us')->get(); @@ -19,7 +19,7 @@ }); it('can calculate united states holidays before 2021', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'us')->get(); diff --git a/tests/Countries/VenezuelaTest.php b/tests/Countries/VenezuelaTest.php index 5b2cf5ea2..77c7682d1 100644 --- a/tests/Countries/VenezuelaTest.php +++ b/tests/Countries/VenezuelaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate venezuelan holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 've')->get(); diff --git a/tests/Countries/ZambiaTest.php b/tests/Countries/ZambiaTest.php index 83e732256..c67b3982d 100644 --- a/tests/Countries/ZambiaTest.php +++ b/tests/Countries/ZambiaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate zambian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'zm')->get(); From 06c5f38d480cd703e9567cbcb80a3833429526e4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:54:44 +0100 Subject: [PATCH 40/99] try a different orthodox easter calculation --- src/Countries/Country.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index b6cfab347..3294bc536 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -56,6 +56,19 @@ protected function easter(int $year): CarbonImmutable protected function orthodoxEaster(int $year): CarbonImmutable { + $a = $year % 4; + $b = $year % 7; + $c = $year % 19; + $d = (19 * $c + 15) % 30; + $e = (2 * $a + 4 * $b - $d + 34) % 7; + $month = floor(($d + $e + 114) / 31); + $day = (($d + $e + 114) % 31) + 1; + + $easterDate = mktime(0, 0, 0, $month, $day + 13, $year); + + return CarbonImmutable::create($year, $month, $day); + + $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; From 799196ff730b37f9b61ecc74f2ba4081df36fcfa Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:13:27 +0100 Subject: [PATCH 41/99] fix calculating orthodox easter --- src/Countries/Country.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 3294bc536..9e9a85533 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -56,23 +56,13 @@ protected function easter(int $year): CarbonImmutable protected function orthodoxEaster(int $year): CarbonImmutable { - $a = $year % 4; - $b = $year % 7; - $c = $year % 19; - $d = (19 * $c + 15) % 30; - $e = (2 * $a + 4 * $b - $d + 34) % 7; - $month = floor(($d + $e + 114) / 31); - $day = (($d + $e + 114) % 31) + 1; - - $easterDate = mktime(0, 0, 0, $month, $day + 13, $year); - - return CarbonImmutable::create($year, $month, $day); - - - $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); - $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; + // Paschal full moon date + // Not covered edge case: + // when the full moon is on a 3 April, Easter is the next Sunday + $easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-04-03") + ->startOfDay(); - return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); + return $easter->addDays(easter_days($year, CAL_EASTER_ALWAYS_JULIAN)); } public static function find(string $countryCode): ?Country From 9b0988e48754925c78597b5e03e76057b57f935c Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 10:13:54 +0000 Subject: [PATCH 42/99] Fix styling --- src/Countries/Australia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 87dcb6a6f..0b43bae4e 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -36,7 +36,7 @@ protected function variableHolidays(int $year): array 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), // https://en.wikipedia.org/wiki/Public_holidays_in_Australia - ...array_filter(match($this->region) { + ...array_filter(match ($this->region) { 'act' => [ 'Canberra Day' => CarbonImmutable::parse("second monday of march {$year}"), 'Easter Saturday' => $easter->subDay(), From eb9833e7f6faf9ca91eaed6a97371a87e282cfad Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:15:15 +0100 Subject: [PATCH 43/99] move to baseline --- phpstan-baseline.neon | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 31f8d0e58..ec51df55b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12,7 +12,7 @@ parameters: - message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 + count: 2 path: src/Countries/Country.php - @@ -20,11 +20,6 @@ parameters: count: 1 path: src/Countries/Country.php - - - message: "#^Parameter \\#1 \\$timestamp of static method Carbon\\\\CarbonImmutable\\:\\:createFromTimestamp\\(\\) expects float\\|int\\|string, int\\|false given\\.$#" - count: 1 - path: src/Countries/Country.php - - message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(bool\\|Carbon\\\\CarbonImmutable, bool\\|Carbon\\\\CarbonImmutable\\)\\: int, Closure\\(Carbon\\\\CarbonImmutable, Carbon\\\\CarbonImmutable\\)\\: int\\<\\-1, 1\\> given\\.$#" count: 1 From 03fe5c205528416b95b0e3b0a45a80d6b1090275 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:46:41 +0100 Subject: [PATCH 44/99] add a test case to make sure orthodox easter is calculated correctly --- tests/CountryTest.php | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/CountryTest.php diff --git a/tests/CountryTest.php b/tests/CountryTest.php new file mode 100644 index 000000000..598698254 --- /dev/null +++ b/tests/CountryTest.php @@ -0,0 +1,51 @@ +setAccessible(true); + + $easter = $reflectionMethod->invoke($country, $year); + + expect($easter->format('Y-m-d'))->toBe($date); +})->with([ + [1997, "1997-04-27"], + [1998, "1998-04-19"], + [1999, "1999-04-11"], + [2000, "2000-04-30"], + [2001, "2001-04-15"], + [2002, "2002-05-05"], + [2003, "2003-04-27"], + [2004, "2004-04-11"], + [2005, "2005-05-01"], + [2006, "2006-04-23"], + [2007, "2007-04-08"], + [2008, "2008-04-27"], + [2009, "2009-04-19"], + [2010, "2010-04-04"], + [2011, "2011-04-24"], + [2012, "2012-04-15"], + [2013, "2013-05-05"], + [2014, "2014-04-20"], + [2015, "2015-04-12"], + [2016, "2016-05-01"], + [2017, "2017-04-16"], + [2018, "2018-04-08"], + [2019, "2019-04-28"], + [2020, "2020-04-19"], + [2021, "2021-05-02"], + [2022, "2022-04-24"], + [2023, "2023-04-16"], + [2024, "2024-05-05"], + [2025, "2025-04-20"], + [2026, "2026-04-12"], + [2027, "2027-05-02"], + [2028, "2028-04-16"], + [2029, "2029-04-08"], +]); From 76a87d7b3459193e920e48102ef7de0d42f75a7c Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 10:47:02 +0000 Subject: [PATCH 45/99] Fix styling --- tests/CountryTest.php | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/CountryTest.php b/tests/CountryTest.php index 598698254..513b7c419 100644 --- a/tests/CountryTest.php +++ b/tests/CountryTest.php @@ -15,37 +15,37 @@ expect($easter->format('Y-m-d'))->toBe($date); })->with([ - [1997, "1997-04-27"], - [1998, "1998-04-19"], - [1999, "1999-04-11"], - [2000, "2000-04-30"], - [2001, "2001-04-15"], - [2002, "2002-05-05"], - [2003, "2003-04-27"], - [2004, "2004-04-11"], - [2005, "2005-05-01"], - [2006, "2006-04-23"], - [2007, "2007-04-08"], - [2008, "2008-04-27"], - [2009, "2009-04-19"], - [2010, "2010-04-04"], - [2011, "2011-04-24"], - [2012, "2012-04-15"], - [2013, "2013-05-05"], - [2014, "2014-04-20"], - [2015, "2015-04-12"], - [2016, "2016-05-01"], - [2017, "2017-04-16"], - [2018, "2018-04-08"], - [2019, "2019-04-28"], - [2020, "2020-04-19"], - [2021, "2021-05-02"], - [2022, "2022-04-24"], - [2023, "2023-04-16"], - [2024, "2024-05-05"], - [2025, "2025-04-20"], - [2026, "2026-04-12"], - [2027, "2027-05-02"], - [2028, "2028-04-16"], - [2029, "2029-04-08"], + [1997, '1997-04-27'], + [1998, '1998-04-19'], + [1999, '1999-04-11'], + [2000, '2000-04-30'], + [2001, '2001-04-15'], + [2002, '2002-05-05'], + [2003, '2003-04-27'], + [2004, '2004-04-11'], + [2005, '2005-05-01'], + [2006, '2006-04-23'], + [2007, '2007-04-08'], + [2008, '2008-04-27'], + [2009, '2009-04-19'], + [2010, '2010-04-04'], + [2011, '2011-04-24'], + [2012, '2012-04-15'], + [2013, '2013-05-05'], + [2014, '2014-04-20'], + [2015, '2015-04-12'], + [2016, '2016-05-01'], + [2017, '2017-04-16'], + [2018, '2018-04-08'], + [2019, '2019-04-28'], + [2020, '2020-04-19'], + [2021, '2021-05-02'], + [2022, '2022-04-24'], + [2023, '2023-04-16'], + [2024, '2024-05-05'], + [2025, '2025-04-20'], + [2026, '2026-04-12'], + [2027, '2027-05-02'], + [2028, '2028-04-16'], + [2029, '2029-04-08'], ]); From 1fa7a39e20b2938ddd46b70f07b9eaf123a24740 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:50:10 +0100 Subject: [PATCH 46/99] use our invade package instead of Reflection --- composer.json | 1 + tests/CountryTest.php | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 9f8a2f7fb..8e0f585dc 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "laravel/prompts": "^0.1.15", "pestphp/pest": "^2.31", "phpstan/phpstan": "^1.10.56", + "spatie/invade": "^2.0", "spatie/ray": "^1.40.1", "symfony/var-dumper": "^6.4" }, diff --git a/tests/CountryTest.php b/tests/CountryTest.php index 513b7c419..6699ab606 100644 --- a/tests/CountryTest.php +++ b/tests/CountryTest.php @@ -2,16 +2,12 @@ namespace Spatie\Holidays\Tests; -use ReflectionMethod; use Spatie\Holidays\Countries\Belgium; it('can calculate orthodox easter', function (int $year, string $date) { $country = Belgium::make(); - $reflectionMethod = new ReflectionMethod('Spatie\Holidays\Countries\Belgium', 'orthodoxEaster'); - $reflectionMethod->setAccessible(true); - - $easter = $reflectionMethod->invoke($country, $year); + $easter = invade($country)->orthodoxEaster($year); expect($easter->format('Y-m-d'))->toBe($date); })->with([ From 18cd8b263d179875853938342e9296708a27366e Mon Sep 17 00:00:00 2001 From: Onyile Bassey Felix Date: Thu, 25 Jan 2024 12:02:57 +0100 Subject: [PATCH 47/99] Update Australia.php (#178) --- src/Countries/Australia.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 0b43bae4e..82273158e 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -92,7 +92,6 @@ protected function variableHolidays(int $year): array }), ]; } - // https://business.vic.gov.au/business-information/public-holidays/victorian-public-holidays-2025 // https://en.wikipedia.org/wiki/List_of_VFL/AFL_premiers#VFL/AFL_premierships protected function fridayBeforeAflGrandFinal(int $year): ?CarbonImmutable @@ -108,7 +107,6 @@ protected function fridayBeforeAflGrandFinal(int $year): ?CarbonImmutable default => CarbonImmutable::parse("last friday of september {$year}"), }; } - protected function sovereignBirthdayKey(int $year): string { // https://www.abc.net.au/news/2022-09-22/queens-birthday-public-holiday-becomes-kings-birthday/101453408 From 37b07173ed8c1df13919048015dad9e62ba6ff00 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 11:03:24 +0000 Subject: [PATCH 48/99] Fix styling --- src/Countries/Australia.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 82273158e..0b43bae4e 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -92,6 +92,7 @@ protected function variableHolidays(int $year): array }), ]; } + // https://business.vic.gov.au/business-information/public-holidays/victorian-public-holidays-2025 // https://en.wikipedia.org/wiki/List_of_VFL/AFL_premiers#VFL/AFL_premierships protected function fridayBeforeAflGrandFinal(int $year): ?CarbonImmutable @@ -107,6 +108,7 @@ protected function fridayBeforeAflGrandFinal(int $year): ?CarbonImmutable default => CarbonImmutable::parse("last friday of september {$year}"), }; } + protected function sovereignBirthdayKey(int $year): string { // https://www.abc.net.au/news/2022-09-22/queens-birthday-public-holiday-becomes-kings-birthday/101453408 From 59e6ae1ce14691f8d03ec04154901244f4668d1f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:16:27 +0100 Subject: [PATCH 49/99] fix warning in case a file is not found --- src/Concerns/Translatable.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 0c65b5f7a..237c8905a 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -13,8 +13,13 @@ protected function translate(string $country, string $name, ?string $locale = nu } $countryName = strtolower($country); + $filePath = __DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"; - $content = file_get_contents(__DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"); + if (file_exists($filePath)) { + $content = file_get_contents($filePath); + } else { + throw InvalidLocale::notFound($country, $locale); + } if ($content === false) { throw InvalidLocale::notFound($country, $locale); From 0eb53b7b84c9a7a9c1538999529c23816733a881 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 11:17:39 +0000 Subject: [PATCH 50/99] Update CHANGELOG --- CHANGELOG.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14dc75264..326828cd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,46 @@ All notable changes to `holidays` will be documented in this file. +## 1.3.0 - 2024-01-25 + +### What's Changed + +* Add Ukrainian holidays by @kapi14 in https://github.com/spatie/holidays/pull/112 +* Added Turkey holidays by @thecaliskan in https://github.com/spatie/holidays/pull/70 +* Added has helper by @thecaliskan in https://github.com/spatie/holidays/pull/170 +* Add Slovakia holidays by @patressz in https://github.com/spatie/holidays/pull/102 +* Add support for multi languages by @Nielsvanpach in https://github.com/spatie/holidays/pull/177 +* Add latvian holidays by @IvarsSaudinis in https://github.com/spatie/holidays/pull/169 +* Added Colombia Holidays by @alvleont in https://github.com/spatie/holidays/pull/55 +* Add Finnish Holidays by @ConnySjoblom in https://github.com/spatie/holidays/pull/85 +* Add Japan support by @mkokio in https://github.com/spatie/holidays/pull/160 +* Add United States Holidays by @arcdigital in https://github.com/spatie/holidays/pull/26 +* Add Serbian holidays by @knubbe82 in https://github.com/spatie/holidays/pull/107 +* Add El Salvador Holidays by @vlltr in https://github.com/spatie/holidays/pull/93 +* Belarus Holidays by @Jampire in https://github.com/spatie/holidays/pull/156 +* Adding German holidays by @arnebr in https://github.com/spatie/holidays/pull/8 +* Add Australian Holidays by @patrickomeara in https://github.com/spatie/holidays/pull/43 +* Update Australia.php by @OnyileFelix1 in https://github.com/spatie/holidays/pull/178 +* Bug fix: calculating orthodox easter by @Nielsvanpach in https://github.com/spatie/holidays/pull/180 + +### New Contributors + +* @kapi14 made their first contribution in https://github.com/spatie/holidays/pull/112 +* @patressz made their first contribution in https://github.com/spatie/holidays/pull/102 +* @IvarsSaudinis made their first contribution in https://github.com/spatie/holidays/pull/169 +* @alvleont made their first contribution in https://github.com/spatie/holidays/pull/55 +* @ConnySjoblom made their first contribution in https://github.com/spatie/holidays/pull/85 +* @mkokio made their first contribution in https://github.com/spatie/holidays/pull/160 +* @arcdigital made their first contribution in https://github.com/spatie/holidays/pull/26 +* @knubbe82 made their first contribution in https://github.com/spatie/holidays/pull/107 +* @vlltr made their first contribution in https://github.com/spatie/holidays/pull/93 +* @Jampire made their first contribution in https://github.com/spatie/holidays/pull/156 +* @arnebr made their first contribution in https://github.com/spatie/holidays/pull/8 +* @patrickomeara made their first contribution in https://github.com/spatie/holidays/pull/43 +* @OnyileFelix1 made their first contribution in https://github.com/spatie/holidays/pull/178 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.2.0...1.3.0 + ## 1.2.0 - 2024-01-23 ### What's Changed From c73c665cc6e2bd70557c3c019dcbf8a4b92a1c41 Mon Sep 17 00:00:00 2001 From: Rkishahaha <67111239+Rkishahaha@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:30:05 +0100 Subject: [PATCH 51/99] Add Montenegro holidays (#171) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Montenegro holidays * Add English and Serbian translations for Montenegro holidays --------- Co-authored-by: Marko Ršumović --- lang/montenegro/en/holidays.json | 18 +++++ lang/montenegro/sr/holidays.json | 18 +++++ src/Countries/Montenegro.php | 49 ++++++++++++++ .../it_can_calculate_montenegro_holidays.snap | 66 +++++++++++++++++++ tests/Countries/MontenegroTest.php | 18 +++++ 5 files changed, 169 insertions(+) create mode 100644 lang/montenegro/en/holidays.json create mode 100644 lang/montenegro/sr/holidays.json create mode 100644 src/Countries/Montenegro.php create mode 100644 tests/.pest/snapshots/Countries/MontenegroTest/it_can_calculate_montenegro_holidays.snap create mode 100644 tests/Countries/MontenegroTest.php diff --git a/lang/montenegro/en/holidays.json b/lang/montenegro/en/holidays.json new file mode 100644 index 000000000..8c7424593 --- /dev/null +++ b/lang/montenegro/en/holidays.json @@ -0,0 +1,18 @@ +{ + "Nova godina - prvi dan": "New Year - first day", + "Nova godina - drugi dan": "New Year - second day", + "Badnji dan": "Christmas Eve", + "Božić - prvi dan": "Christmas - first day", + "Božić - drugi dan": "Christmas - second day", + "Praznik rada - prvi dan": "Labour Day - first day", + "Praznik rada - drugi dan": "Labour Day - second day", + "Veliki petak": "Good Friday", + "Vaskrs": "Easter", + "Vaskršnji ponedjeljak": "Easter Monday", + "Dan nezavisnosti - prvi dan": "Independence Day - first day", + "Dan nezavisnosti - drugi dan": "Independence Day - second day", + "Dan državnosti - prvi dan": "National Day - first day", + "Dan državnosti - drugi dan": "National Day - second day", + "Njegošev dan - prvi dan": "Njegoš's Day - first day", + "Njegošev dan - drugi dan": "Njegoš's Day - second day" +} \ No newline at end of file diff --git a/lang/montenegro/sr/holidays.json b/lang/montenegro/sr/holidays.json new file mode 100644 index 000000000..e09ad680a --- /dev/null +++ b/lang/montenegro/sr/holidays.json @@ -0,0 +1,18 @@ +{ + "Nova godina - prvi dan": "Nova godina - prvi dan", + "Nova godina - drugi dan": "Nova godina - drugi dan", + "Badnji dan": "Badnji dan", + "Božić - prvi dan": "Božić - prvi dan", + "Božić - drugi dan": "Božić - drugi dan", + "Praznik rada - prvi dan": "Praznik rada - prvi dan", + "Praznik rada - drugi dan": "Praznik rada - drugi dan", + "Veliki petak": "Veliki petak", + "Vaskrs": "Vaskrs", + "Vaskršnji ponedjeljak": "Vaskršnji ponedeljak", + "Dan nezavisnosti - prvi dan": "Dan nezavisnosti - prvi dan", + "Dan nezavisnosti - drugi dan": "Dan nezavisnosti - drugi dan", + "Dan državnosti - prvi dan": "Dan državnosti - prvi dan", + "Dan državnosti - drugi dan": "Dan državnosti - drugi dan", + "Njegošev dan - prvi dan": "Njegošev dan - prvi dan", + "Njegošev dan - drugi dan": "Njegošev dan - drugi dan" +} \ No newline at end of file diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php new file mode 100644 index 000000000..537a4f9bd --- /dev/null +++ b/src/Countries/Montenegro.php @@ -0,0 +1,49 @@ + '01-01', + 'Nova godina - drugi dan' => '01-02', + 'Badnji dan' => '01-06', + 'Božić - prvi dan' => '01-07', + 'Božić - drugi dan' => '01-08', + 'Praznik rada - prvi dan' => '05-01', + 'Praznik rada - drugi dan' => '05-02', + 'Dan nezavisnosti - prvi dan' => '05-21', + 'Dan nezavisnosti - drugi dan' => '05-22', + 'Dan državnosti - prvi dan' => '07-13', + 'Dan državnosti - drugi dan' => '07-14', + 'Njegošev dan - prvi dan' => '11-13', + 'Njegošev dan - drugi dan' => '11-14', + + ], $this->variableHolidays($year)); + } + + /** @return array */ + public function variableHolidays(int $year) : array + { + // Orthodox Easter calculation needs to be in the same timezone as the country + $orthodoxEaster = $this->orthodoxEaster($year)->setTimezone('Europe/Podgorica'); + $goodFriday = $orthodoxEaster->copy()->subDays(2); + $orthodoxEasterMonday = $orthodoxEaster->copy()->addDay(); + + return [ + 'Vaskrs' => $orthodoxEaster, + 'Vaskršnji ponedjeljak' => $orthodoxEasterMonday, + 'Veliki petak' => $goodFriday, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/MontenegroTest/it_can_calculate_montenegro_holidays.snap b/tests/.pest/snapshots/Countries/MontenegroTest/it_can_calculate_montenegro_holidays.snap new file mode 100644 index 000000000..1e39c5b16 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MontenegroTest/it_can_calculate_montenegro_holidays.snap @@ -0,0 +1,66 @@ +[ + { + "name": "Nova godina - prvi dan", + "date": "2024-01-01" + }, + { + "name": "Nova godina - drugi dan", + "date": "2024-01-02" + }, + { + "name": "Badnji dan", + "date": "2024-01-06" + }, + { + "name": "Bo\u017ei\u0107 - prvi dan", + "date": "2024-01-07" + }, + { + "name": "Bo\u017ei\u0107 - drugi dan", + "date": "2024-01-08" + }, + { + "name": "Praznik rada - prvi dan", + "date": "2024-05-01" + }, + { + "name": "Praznik rada - drugi dan", + "date": "2024-05-02" + }, + { + "name": "Veliki petak", + "date": "2024-05-03" + }, + { + "name": "Vaskrs", + "date": "2024-05-05" + }, + { + "name": "Vaskr\u0161nji ponedjeljak", + "date": "2024-05-06" + }, + { + "name": "Dan nezavisnosti - prvi dan", + "date": "2024-05-21" + }, + { + "name": "Dan nezavisnosti - drugi dan", + "date": "2024-05-22" + }, + { + "name": "Dan dr\u017eavnosti - prvi dan", + "date": "2024-07-13" + }, + { + "name": "Dan dr\u017eavnosti - drugi dan", + "date": "2024-07-14" + }, + { + "name": "Njego\u0161ev dan - prvi dan", + "date": "2024-11-13" + }, + { + "name": "Njego\u0161ev dan - drugi dan", + "date": "2024-11-14" + } +] \ No newline at end of file diff --git a/tests/Countries/MontenegroTest.php b/tests/Countries/MontenegroTest.php new file mode 100644 index 000000000..d28c000b4 --- /dev/null +++ b/tests/Countries/MontenegroTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); \ No newline at end of file From 941fbfbda35c717bccbc41643244c80b84eb2c4d Mon Sep 17 00:00:00 2001 From: Monteiro Futila Domingos <91145941+monteirofutila@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:30:16 +0100 Subject: [PATCH 52/99] Add Angola Holidays (#89) --- src/Countries/Angola.php | 42 ++++++++++++++++ .../it_can_calculate_angola_holidays.snap | 50 +++++++++++++++++++ tests/Countries/AngolaTest.php | 18 +++++++ 3 files changed, 110 insertions(+) create mode 100644 src/Countries/Angola.php create mode 100644 tests/.pest/snapshots/Countries/AngolaTest/it_can_calculate_angola_holidays.snap create mode 100644 tests/Countries/AngolaTest.php diff --git a/src/Countries/Angola.php b/src/Countries/Angola.php new file mode 100644 index 000000000..e83aa55ed --- /dev/null +++ b/src/Countries/Angola.php @@ -0,0 +1,42 @@ + '01-01', + 'Dia do Inicio da Luta Armada de Libertação Nacional' => '02-04', + 'Dia Internacional da Mulher' => '03-08', + 'Dia da Paz' => '04-04', + 'Dia Internacional do Trabalhador' => '05-01', + 'Dia do Fundador da Nação e do Herói Nacional' => '09-17', + 'Dia dos Finados' => '11-02', + 'Dia da Independência Nacional' => '11-11', + 'Dia do Natal' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Luanda'); + + return [ + 'Carnaval' => $easter->subDays(47), + 'Sexta Feira Santa' => $easter->subDays(2), + 'Páscoa' => $easter, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/AngolaTest/it_can_calculate_angola_holidays.snap b/tests/.pest/snapshots/Countries/AngolaTest/it_can_calculate_angola_holidays.snap new file mode 100644 index 000000000..a97d32a98 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AngolaTest/it_can_calculate_angola_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "Dia de Ano Novo", + "date": "2024-01-01" + }, + { + "name": "Dia do Inicio da Luta Armada de Liberta\u00e7\u00e3o Nacional", + "date": "2024-02-04" + }, + { + "name": "Carnaval", + "date": "2024-02-13" + }, + { + "name": "Dia Internacional da Mulher", + "date": "2024-03-08" + }, + { + "name": "Sexta Feira Santa", + "date": "2024-03-29" + }, + { + "name": "P\u00e1scoa", + "date": "2024-03-31" + }, + { + "name": "Dia da Paz", + "date": "2024-04-04" + }, + { + "name": "Dia Internacional do Trabalhador", + "date": "2024-05-01" + }, + { + "name": "Dia do Fundador da Na\u00e7\u00e3o e do Her\u00f3i Nacional", + "date": "2024-09-17" + }, + { + "name": "Dia dos Finados", + "date": "2024-11-02" + }, + { + "name": "Dia da Independ\u00eancia Nacional", + "date": "2024-11-11" + }, + { + "name": "Dia do Natal", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/AngolaTest.php b/tests/Countries/AngolaTest.php new file mode 100644 index 000000000..ae0e07518 --- /dev/null +++ b/tests/Countries/AngolaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From d084b1c55347e958aa451516f0a24fffa2ab9df5 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 11:30:35 +0000 Subject: [PATCH 53/99] Fix styling --- src/Countries/Montenegro.php | 98 +++++++++++++++--------------- tests/Countries/MontenegroTest.php | 36 +++++------ 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php index 537a4f9bd..2423f1e81 100644 --- a/src/Countries/Montenegro.php +++ b/src/Countries/Montenegro.php @@ -1,49 +1,49 @@ - '01-01', - 'Nova godina - drugi dan' => '01-02', - 'Badnji dan' => '01-06', - 'Božić - prvi dan' => '01-07', - 'Božić - drugi dan' => '01-08', - 'Praznik rada - prvi dan' => '05-01', - 'Praznik rada - drugi dan' => '05-02', - 'Dan nezavisnosti - prvi dan' => '05-21', - 'Dan nezavisnosti - drugi dan' => '05-22', - 'Dan državnosti - prvi dan' => '07-13', - 'Dan državnosti - drugi dan' => '07-14', - 'Njegošev dan - prvi dan' => '11-13', - 'Njegošev dan - drugi dan' => '11-14', - - ], $this->variableHolidays($year)); - } - - /** @return array */ - public function variableHolidays(int $year) : array - { - // Orthodox Easter calculation needs to be in the same timezone as the country - $orthodoxEaster = $this->orthodoxEaster($year)->setTimezone('Europe/Podgorica'); - $goodFriday = $orthodoxEaster->copy()->subDays(2); - $orthodoxEasterMonday = $orthodoxEaster->copy()->addDay(); - - return [ - 'Vaskrs' => $orthodoxEaster, - 'Vaskršnji ponedjeljak' => $orthodoxEasterMonday, - 'Veliki petak' => $goodFriday, - ]; - } -} + '01-01', + 'Nova godina - drugi dan' => '01-02', + 'Badnji dan' => '01-06', + 'Božić - prvi dan' => '01-07', + 'Božić - drugi dan' => '01-08', + 'Praznik rada - prvi dan' => '05-01', + 'Praznik rada - drugi dan' => '05-02', + 'Dan nezavisnosti - prvi dan' => '05-21', + 'Dan nezavisnosti - drugi dan' => '05-22', + 'Dan državnosti - prvi dan' => '07-13', + 'Dan državnosti - drugi dan' => '07-14', + 'Njegošev dan - prvi dan' => '11-13', + 'Njegošev dan - drugi dan' => '11-14', + + ], $this->variableHolidays($year)); + } + + /** @return array */ + public function variableHolidays(int $year): array + { + // Orthodox Easter calculation needs to be in the same timezone as the country + $orthodoxEaster = $this->orthodoxEaster($year)->setTimezone('Europe/Podgorica'); + $goodFriday = $orthodoxEaster->copy()->subDays(2); + $orthodoxEasterMonday = $orthodoxEaster->copy()->addDay(); + + return [ + 'Vaskrs' => $orthodoxEaster, + 'Vaskršnji ponedjeljak' => $orthodoxEasterMonday, + 'Veliki petak' => $goodFriday, + ]; + } +} diff --git a/tests/Countries/MontenegroTest.php b/tests/Countries/MontenegroTest.php index d28c000b4..9f5078b93 100644 --- a/tests/Countries/MontenegroTest.php +++ b/tests/Countries/MontenegroTest.php @@ -1,18 +1,18 @@ -get(); - - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); - - expect(formatDates($holidays))->toMatchSnapshot(); -}); \ No newline at end of file +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 9f20ab2c4e6e671ffaa0875a4152f7b52a3ca3a4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:33:32 +0100 Subject: [PATCH 54/99] correctly calculate easter + fix el salvador --- src/Countries/Angola.php | 3 +-- src/Countries/ElSalvador.php | 5 ++--- src/Countries/Finland.php | 3 +-- src/Countries/Norway.php | 3 +-- src/Countries/Uganda.php | 2 +- .../it_can_calculate_el_salvador_holidays.snap | 6 +++--- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Countries/Angola.php b/src/Countries/Angola.php index e83aa55ed..0ef3bb72a 100644 --- a/src/Countries/Angola.php +++ b/src/Countries/Angola.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('Africa/Luanda'); + $easter = $this->easter($year); return [ 'Carnaval' => $easter->subDays(47), diff --git a/src/Countries/ElSalvador.php b/src/Countries/ElSalvador.php index c3a84a224..7766745b7 100644 --- a/src/Countries/ElSalvador.php +++ b/src/Countries/ElSalvador.php @@ -28,13 +28,12 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('America/El_Salvador'); + $easter = $this->easter($year); return [ 'Jueves Santo' => $easter->subDays(3), 'Viernes Santo' => $easter->subDays(2), - 'Sábado de Gloria' => $easter->subDays(1), + 'Sábado de Gloria' => $easter->subDay(), ]; } } diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 103fda86f..69fa1fd39 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -32,8 +32,7 @@ protected function fixedHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Helsinki'); + $easter = $this->easter($year); $midsummerDay = CarbonImmutable::createFromDate($year, 6, 20) ->next(CarbonImmutable::SATURDAY); diff --git a/src/Countries/Norway.php b/src/Countries/Norway.php index c4d09737b..f2115d0c1 100644 --- a/src/Countries/Norway.php +++ b/src/Countries/Norway.php @@ -25,8 +25,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Oslo'); + $easter = $this->easter($year); $holidays = [ 'Skjærtorsdag' => $easter->subDays(3), diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 90a0af5bf..bbff49416 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -32,7 +32,7 @@ protected function allHolidays(int $year): array */ private function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + $easter = $this->easter($year); return [ 'Good Friday' => $easter->subDays(2), diff --git a/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap b/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap index 2586f7686..63c794a4e 100644 --- a/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap +++ b/tests/.pest/snapshots/Countries/ElSalvadorTest/it_can_calculate_el_salvador_holidays.snap @@ -5,15 +5,15 @@ }, { "name": "Jueves Santo", - "date": "2024-03-27" + "date": "2024-03-28" }, { "name": "Viernes Santo", - "date": "2024-03-28" + "date": "2024-03-29" }, { "name": "S\u00e1bado de Gloria", - "date": "2024-03-29" + "date": "2024-03-30" }, { "name": "D\u00eda del Trabajo", From b5bb47f88c44f40e578981d854a48423c4e60bd9 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:34:54 +0100 Subject: [PATCH 55/99] run code styling on PRs --- .github/workflows/fix-php-code-style-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 30e62c774..99b82e963 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -1,6 +1,6 @@ name: Fix PHP code style issues -on: [push] +on: [push, pull_request] permissions: contents: write From b41b7d1cf4fe52d33c51f108d4ba960895826b47 Mon Sep 17 00:00:00 2001 From: Simon Barrett Date: Thu, 25 Jan 2024 17:53:52 +0000 Subject: [PATCH 56/99] add wales, england, scotland and northern ireland (#162) --- src/Countries/England.php | 11 ++ src/Countries/NorthernIreland.php | 90 ++++++++++++ src/Countries/Scotland.php | 94 +++++++++++++ src/Countries/Wales.php | 133 ++++++++++++++++++ .../it_can_calculate_holidays_for_2020.snap | 34 +++++ .../it_can_calculate_welsh_holidays.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_friday.snap | 34 +++++ ...olidays_if_christmas_is_on_a_saturday.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 42 ++++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 34 +++++ ...can_calculate_northern_irish_for_2020.snap | 34 +++++ ...can_calculate_northern_irish_holidays.snap | 42 ++++++ ..._holidays_if_christmas_is_on_a_friday.snap | 42 ++++++ ...olidays_if_christmas_is_on_a_saturday.snap | 42 ++++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 50 +++++++ ...ry_if_new_years_day_falls_on_a_friday.snap | 42 ++++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 42 ++++++ .../it_can_calculate_holidays_for_2020.snap | 34 +++++ .../it_can_calculate_scottish_holidays.snap | 38 +++++ ..._holidays_if_christmas_is_on_a_friday.snap | 38 +++++ ...olidays_if_christmas_is_on_a_saturday.snap | 38 +++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 46 ++++++ ...ry_if_new_years_day_falls_on_a_friday.snap | 38 +++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 38 +++++ .../it_can_calculate_holidays_for_2020.snap | 34 +++++ .../it_can_calculate_welsh_holidays.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_friday.snap | 34 +++++ ...olidays_if_christmas_is_on_a_saturday.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 42 ++++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 34 +++++ tests/Countries/EnglandTest.php | 98 +++++++++++++ tests/Countries/NorthernIrelandTest.php | 111 +++++++++++++++ tests/Countries/ScotlandTest.php | 108 ++++++++++++++ tests/Countries/WalesTest.php | 117 +++++++++++++++ 34 files changed, 1750 insertions(+) create mode 100644 src/Countries/England.php create mode 100644 src/Countries/NorthernIreland.php create mode 100644 src/Countries/Scotland.php create mode 100644 src/Countries/Wales.php create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/Countries/EnglandTest.php create mode 100644 tests/Countries/NorthernIrelandTest.php create mode 100644 tests/Countries/ScotlandTest.php create mode 100644 tests/Countries/WalesTest.php diff --git a/src/Countries/England.php b/src/Countries/England.php new file mode 100644 index 000000000..efd62adba --- /dev/null +++ b/src/Countries/England.php @@ -0,0 +1,11 @@ + */ + private function stPatricksDay(int $year): array + { + $stPatricksDay = new CarbonImmutable($year . "-03-17", 'Europe/London'); + $key = 'St Patrick\'s Day'; + + if ($stPatricksDay->isWeekend()) { + $key .= ' (substitute day)'; + $stPatricksDay = $stPatricksDay->next('monday'); + } + + return [$key => $stPatricksDay]; + } + + /** @return array */ + private function battleOfTheBoyne(int $year): array + { + $battleOfTheBoyne = new CarbonImmutable($year . "-07-12", 'Europe/London'); + $key = 'Battle of the Boyne (Orangemen\'s Day)'; + + if ($battleOfTheBoyne->isWeekend()) { + $key .= ' (substitute day)'; + $battleOfTheBoyne = $battleOfTheBoyne->next('monday'); + } + + return [$key => $battleOfTheBoyne]; + } + + /** @return array */ + protected function oneOffHolidays(int $year): array + { + return match ($year) { + 2022 => [ + 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + ], + default => [], + }; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->stPatricksDay($year), + $this->earlyMayBankHoliday($year), + $this->battleOfTheBoyne($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + ], + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easterSunday = $this->easter($year); + + $goodFriday = $easterSunday->subDays(2); + $easterMonday = $easterSunday->addDay(); + + return [ + 'Good Friday' => $goodFriday, + 'Easter Monday' => $easterMonday, + ]; + } +} diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php new file mode 100644 index 000000000..31f5aef8c --- /dev/null +++ b/src/Countries/Scotland.php @@ -0,0 +1,94 @@ + */ + protected function secondOfJanuary(int $year): array + { + $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); + $secondOfJanuary = new CarbonImmutable($year . "-01-02", 'Europe/London'); + $key = '2nd January'; + + if ($newYearsDay->isFriday()) { + $key .= ' (substitute day)'; + $secondOfJanuary = $secondOfJanuary->next('monday'); + } + + if ($newYearsDay->isWeekend()) { + $key .= ' (substitute day)'; + $secondOfJanuary = $secondOfJanuary->next('tuesday'); + } + + return [$key => $secondOfJanuary]; + } + + /** @return array */ + private function stAndrewsDay(int $year): array + { + $stAndrewsDay = new CarbonImmutable($year . "-11-30", 'Europe/London'); + $key = 'St Andrew\'s Day'; + + if ($stAndrewsDay->isWeekend()) { + $key .= ' (substitute day)'; + $stAndrewsDay = $stAndrewsDay->next('monday'); + } + + return [$key => $stAndrewsDay]; + } + + /** @return array */ + protected function oneOffHolidays(int $year): array + { + return match ($year) { + 2022 => [ + 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + ], + default => [], + }; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->secondOfJanuary($year), + $this->earlyMayBankHoliday($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("first monday of august {$year}", 'Europe/London'), + ], + $this->stAndrewsDay($year), + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easterSunday = $this->easter($year); + + $goodFriday = $easterSunday->subDays(2); + + return [ + 'Good Friday' => $goodFriday, + ]; + } +} diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php new file mode 100644 index 000000000..0a05fd29d --- /dev/null +++ b/src/Countries/Wales.php @@ -0,0 +1,133 @@ + */ + protected function christmasDay(int $year): array + { + $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); + $key = 'Christmas Day'; + + if ($christmasDay->isSaturday()) { + $key .= ' (substitute day)'; + $christmasDay = $christmasDay->next('monday'); + } + + if ($christmasDay->isSunday()) { + $key .= ' (substitute day)'; + $christmasDay = $christmasDay->next('tuesday'); + } + + return [$key => $christmasDay]; + } + + /** @return array */ + protected function boxingDay(int $year): array + { + $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); + $boxingDay = new CarbonImmutable($year . "-12-26", 'Europe/London'); + $key = 'Boxing Day'; + + if ($christmasDay->isFriday()) { + $key .= ' (substitute day)'; + $boxingDay = $boxingDay->next('monday'); + } + + if ($christmasDay->isSaturday()) { + $key .= ' (substitute day)'; + $boxingDay = $boxingDay->next('tuesday'); + } + + return [$key => $boxingDay]; + } + + /** @return array */ + protected function newYearsDay(int $year): array + { + $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); + $key = 'New Year\'s Day'; + + if ($newYearsDay->isWeekend()) { + $key .= ' (substitute day)'; + $newYearsDay = $newYearsDay->next('monday'); + } + + return [$key => $newYearsDay]; + } + + /** @return array */ + protected function earlyMayBankHoliday(int $year): array + { + if ($year === 2020) { + return [ + 'Early May bank holiday (VE day)' => new CarbonImmutable("2020-05-08", 'Europe/London'), + ]; + } + + if ($year === 2023) { + return [ + 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable("2020-05-08", 'Europe/London'), + ]; + } + + return ['Early May bank holiday' => new CarbonImmutable("first monday of may {$year}", 'Europe/London')]; + } + + /** + * @param int $year + * @return array|CarbonImmutable[] + */ + protected function oneOffHolidays(int $year): array + { + return match ($year) { + 2022 => [ + 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + ], + default => [], + }; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->earlyMayBankHoliday($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + ], + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easterSunday = $this->easter($year); + + $goodFriday = $easterSunday->subDays(2); + $easterMonday = $easterSunday->addDay(); + + return [ + 'Good Friday' => $goodFriday, + 'Easter Monday' => $easterMonday, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap new file mode 100644 index 000000000..7a2079d12 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Early May bank holiday", + "date": "2024-05-06" + }, + { + "name": "Spring bank holiday", + "date": "2024-05-27" + }, + { + "name": "Summer bank holiday", + "date": "2024-08-26" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..4757ed990 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..6448e0c3d --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Easter Monday", + "date": "2022-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-29" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..75a852ff2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Easter Monday", + "date": "2033-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-29" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap new file mode 100644 index 000000000..960f4faf3 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2025-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2025-03-17" + }, + { + "name": "Good Friday", + "date": "2025-04-18" + }, + { + "name": "Easter Monday", + "date": "2025-04-21" + }, + { + "name": "Early May bank holiday", + "date": "2025-05-05" + }, + { + "name": "Spring bank holiday", + "date": "2025-05-26" + }, + { + "name": "Battle of the Boyne (Orangemen's Day) (substitute day)", + "date": "2025-07-14" + }, + { + "name": "Summer bank holiday", + "date": "2025-08-25" + }, + { + "name": "Christmas Day", + "date": "2025-12-25" + }, + { + "name": "Boxing Day", + "date": "2025-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..0e20a5c69 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2020-03-17" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Battle of the Boyne (Orangemen's Day) (substitute day)", + "date": "2020-07-13" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..eb0db835f --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2021-03-17" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2021-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..0548d752f --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,50 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "St Patrick's Day", + "date": "2022-03-17" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Easter Monday", + "date": "2022-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2022-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-29" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap new file mode 100644 index 000000000..eb0db835f --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2021-03-17" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2021-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..f2c4691c4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "St Patrick's Day", + "date": "2033-03-17" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Easter Monday", + "date": "2033-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2033-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-29" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap new file mode 100644 index 000000000..8587a1d8b --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2025-01-01" + }, + { + "name": "2nd January", + "date": "2025-01-02" + }, + { + "name": "Good Friday", + "date": "2025-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2025-05-05" + }, + { + "name": "Spring bank holiday", + "date": "2025-05-26" + }, + { + "name": "Summer bank holiday", + "date": "2025-08-04" + }, + { + "name": "St Andrew's Day (substitute day)", + "date": "2025-12-01" + }, + { + "name": "Christmas Day", + "date": "2025-12-25" + }, + { + "name": "Boxing Day", + "date": "2025-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..94688f4f9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "2nd January", + "date": "2020-01-02" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-03" + }, + { + "name": "St Andrew's Day", + "date": "2020-11-30" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..37cb3f2f8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "2nd January (substitute day)", + "date": "2021-01-04" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-02" + }, + { + "name": "St Andrew's Day", + "date": "2021-11-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..4da1e2157 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "2nd January (substitute day)", + "date": "2022-01-04" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-01" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "St Andrew's Day", + "date": "2022-11-30" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap new file mode 100644 index 000000000..37cb3f2f8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "2nd January (substitute day)", + "date": "2021-01-04" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-02" + }, + { + "name": "St Andrew's Day", + "date": "2021-11-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..6a4fe70dd --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "2nd January (substitute day)", + "date": "2033-01-04" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-01" + }, + { + "name": "St Andrew's Day", + "date": "2033-11-30" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap new file mode 100644 index 000000000..7a2079d12 --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Early May bank holiday", + "date": "2024-05-06" + }, + { + "name": "Spring bank holiday", + "date": "2024-05-27" + }, + { + "name": "Summer bank holiday", + "date": "2024-08-26" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..4757ed990 --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..6448e0c3d --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Easter Monday", + "date": "2022-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-29" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..75a852ff2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Easter Monday", + "date": "2033-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-29" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/Countries/EnglandTest.php b/tests/Countries/EnglandTest.php new file mode 100644 index 000000000..366d52322 --- /dev/null +++ b/tests/Countries/EnglandTest.php @@ -0,0 +1,98 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-eng')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Summer bank holiday', '2024-08-26'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Summer bank holiday', '2025-08-25'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Summer bank holiday', '2026-08-31'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], +]); + +it( 'can calculate welsh holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + + +it('can calculate welsh holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate holidays for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/NorthernIrelandTest.php b/tests/Countries/NorthernIrelandTest.php new file mode 100644 index 000000000..a75511256 --- /dev/null +++ b/tests/Countries/NorthernIrelandTest.php @@ -0,0 +1,111 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-nir')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['St Patrick\'s Day (substitute day)', '2024-03-18'], + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Battle of the Boyne (Orangemen\'s Day)', '2024-07-12'], + ['Summer bank holiday', '2024-08-26'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['St Patrick\'s Day', '2025-03-17'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Battle of the Boyne (Orangemen\'s Day) (substitute day)', '2025-07-14'], + ['Summer bank holiday', '2025-08-25'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['St Patrick\'s Day', '2026-03-17'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Battle of the Boyne (Orangemen\'s Day) (substitute day)', '2026-07-13'], + ['Summer bank holiday', '2026-08-31'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], + +]); + +it( 'can calculate northern irish holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('returns a substitute day for second of january if new years day falls on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/ScotlandTest.php b/tests/Countries/ScotlandTest.php new file mode 100644 index 000000000..17e50cb71 --- /dev/null +++ b/tests/Countries/ScotlandTest.php @@ -0,0 +1,108 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-sct')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['2nd January', '2024-01-02'], + ['Good Friday', '2024-03-29'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Summer bank holiday', '2024-08-05'], + ['St Andrew\'s Day (substitute day)', '2024-12-02'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['2nd January', '2025-01-02'], + ['Good Friday', '2025-04-18'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Summer bank holiday', '2025-08-04'], + ['St Andrew\'s Day (substitute day)', '2025-12-01'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['2nd January', '2026-01-02'], + ['Good Friday', '2026-04-03'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Summer bank holiday', '2026-08-03'], + ['St Andrew\'s Day', '2026-11-30'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], +]); + + +it( 'can calculate scottish holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('returns a substitute day for second of january if new years day falls on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate scottish holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate scottish holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate scottish holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate holidays for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/WalesTest.php b/tests/Countries/WalesTest.php new file mode 100644 index 000000000..ac009897b --- /dev/null +++ b/tests/Countries/WalesTest.php @@ -0,0 +1,117 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-cym')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Summer bank holiday', '2024-08-26'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Summer bank holiday', '2025-08-25'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Summer bank holiday', '2026-08-31'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], +]); + +it('calculates welsh easter holidays by date', function (string $name, string $date) { + + $testDate = CarbonImmutable::parse($date); + + $holidayName = Holidays::for('gb-cym')->getName($testDate); + $isHoliday = Holidays::for('gb-cym')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], +]); + +it( 'can calculate welsh holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + + +it('can calculate welsh holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate holidays for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + From 938b22a5d18f43602af3bbe57926bf4c02493e2a Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 17:54:13 +0000 Subject: [PATCH 57/99] Fix styling --- src/Countries/NorthernIreland.php | 8 ++++---- src/Countries/Scotland.php | 10 +++++----- src/Countries/Wales.php | 17 ++++++++--------- tests/Countries/EnglandTest.php | 5 +---- tests/Countries/NorthernIrelandTest.php | 2 +- tests/Countries/ScotlandTest.php | 3 +-- tests/Countries/WalesTest.php | 6 +----- 7 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 6f489cff6..889fa513e 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -14,7 +14,7 @@ public function countryCode(): string /** @return array */ private function stPatricksDay(int $year): array { - $stPatricksDay = new CarbonImmutable($year . "-03-17", 'Europe/London'); + $stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London'); $key = 'St Patrick\'s Day'; if ($stPatricksDay->isWeekend()) { @@ -28,7 +28,7 @@ private function stPatricksDay(int $year): array /** @return array */ private function battleOfTheBoyne(int $year): array { - $battleOfTheBoyne = new CarbonImmutable($year . "-07-12", 'Europe/London'); + $battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London'); $key = 'Battle of the Boyne (Orangemen\'s Day)'; if ($battleOfTheBoyne->isWeekend()) { @@ -44,8 +44,8 @@ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), ], default => [], }; diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index 31f5aef8c..09e2ea097 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -14,8 +14,8 @@ public function countryCode(): string /** @return array */ protected function secondOfJanuary(int $year): array { - $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); - $secondOfJanuary = new CarbonImmutable($year . "-01-02", 'Europe/London'); + $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); + $secondOfJanuary = new CarbonImmutable($year.'-01-02', 'Europe/London'); $key = '2nd January'; if ($newYearsDay->isFriday()) { @@ -34,7 +34,7 @@ protected function secondOfJanuary(int $year): array /** @return array */ private function stAndrewsDay(int $year): array { - $stAndrewsDay = new CarbonImmutable($year . "-11-30", 'Europe/London'); + $stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London'); $key = 'St Andrew\'s Day'; if ($stAndrewsDay->isWeekend()) { @@ -50,8 +50,8 @@ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), ], default => [], }; diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index 0a05fd29d..7468ba889 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -14,7 +14,7 @@ public function countryCode(): string /** @return array */ protected function christmasDay(int $year): array { - $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); + $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); $key = 'Christmas Day'; if ($christmasDay->isSaturday()) { @@ -33,8 +33,8 @@ protected function christmasDay(int $year): array /** @return array */ protected function boxingDay(int $year): array { - $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); - $boxingDay = new CarbonImmutable($year . "-12-26", 'Europe/London'); + $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); + $boxingDay = new CarbonImmutable($year.'-12-26', 'Europe/London'); $key = 'Boxing Day'; if ($christmasDay->isFriday()) { @@ -53,7 +53,7 @@ protected function boxingDay(int $year): array /** @return array */ protected function newYearsDay(int $year): array { - $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); + $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); $key = 'New Year\'s Day'; if ($newYearsDay->isWeekend()) { @@ -69,13 +69,13 @@ protected function earlyMayBankHoliday(int $year): array { if ($year === 2020) { return [ - 'Early May bank holiday (VE day)' => new CarbonImmutable("2020-05-08", 'Europe/London'), + 'Early May bank holiday (VE day)' => new CarbonImmutable('2020-05-08', 'Europe/London'), ]; } if ($year === 2023) { return [ - 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable("2020-05-08", 'Europe/London'), + 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable('2020-05-08', 'Europe/London'), ]; } @@ -83,15 +83,14 @@ protected function earlyMayBankHoliday(int $year): array } /** - * @param int $year * @return array|CarbonImmutable[] */ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), ], default => [], }; diff --git a/tests/Countries/EnglandTest.php b/tests/Countries/EnglandTest.php index 366d52322..ee3d22e80 100644 --- a/tests/Countries/EnglandTest.php +++ b/tests/Countries/EnglandTest.php @@ -1,8 +1,6 @@ get(); @@ -60,7 +58,6 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - it('can calculate welsh holidays if christmas is on a friday', function () { CarbonImmutable::setTestNowAndTimezone('2020-01-01'); diff --git a/tests/Countries/NorthernIrelandTest.php b/tests/Countries/NorthernIrelandTest.php index a75511256..11266d3af 100644 --- a/tests/Countries/NorthernIrelandTest.php +++ b/tests/Countries/NorthernIrelandTest.php @@ -46,7 +46,7 @@ ]); -it( 'can calculate northern irish holidays', function () { +it('can calculate northern irish holidays', function () { CarbonImmutable::setTestNowAndTimezone('2025-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); diff --git a/tests/Countries/ScotlandTest.php b/tests/Countries/ScotlandTest.php index 17e50cb71..f8aa5d926 100644 --- a/tests/Countries/ScotlandTest.php +++ b/tests/Countries/ScotlandTest.php @@ -42,8 +42,7 @@ ['Boxing Day (substitute day)', '2026-12-28'], ]); - -it( 'can calculate scottish holidays', function () { +it('can calculate scottish holidays', function () { CarbonImmutable::setTestNowAndTimezone('2025-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); diff --git a/tests/Countries/WalesTest.php b/tests/Countries/WalesTest.php index ac009897b..2e840357b 100644 --- a/tests/Countries/WalesTest.php +++ b/tests/Countries/WalesTest.php @@ -1,8 +1,6 @@ get(); @@ -78,7 +76,6 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - it('can calculate welsh holidays if christmas is on a friday', function () { CarbonImmutable::setTestNowAndTimezone('2020-01-01'); @@ -114,4 +111,3 @@ expect($holidays)->toBeArray()->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); }); - From f5acb1e04c021a4396eb7faf389bcd02537aa662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Reyes=20Galgani?= Date: Fri, 26 Jan 2024 05:13:07 -0500 Subject: [PATCH 58/99] Add Chile Holidays (#88) * Add Chile Holidays * Update Chile.php * Update Chile.php --- src/Countries/Chile.php | 47 +++++++++++++ .../it_can_calculate_chile_holidays.snap | 70 +++++++++++++++++++ tests/Countries/ChileTest.php | 18 +++++ 3 files changed, 135 insertions(+) create mode 100644 src/Countries/Chile.php create mode 100644 tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap create mode 100644 tests/Countries/ChileTest.php diff --git a/src/Countries/Chile.php b/src/Countries/Chile.php new file mode 100644 index 000000000..37e0f7255 --- /dev/null +++ b/src/Countries/Chile.php @@ -0,0 +1,47 @@ + '01-01', + 'Viernes Santo' => '03-29', + 'Sábado Santo' => '03-30', + 'Día del Trabajador' => '05-01', + 'Día de las Glorias Navales' => '05-21', + 'Día Nacional de los Pueblos Indígenas' => '06-20', + 'San Pedro y San Pablo' => '06-29', + 'Día de la Virgen del Carmen' => '07-16', + 'Asunción de la Virgen' => '08-15', + 'Independencia Nacional' => '09-18', + 'Día de las Glorias del Ejército' => '09-19', + 'Feriado añadido de Fiestas Patrias' => '09-20', + 'Encuentro de Dos Mundos' => '10-12', + 'Día de las Iglesias Evangélicas' => '10-31', + 'Día de Todos los Santos' => '11-01', + 'Inmaculada Concepción' => '12-08', + 'Navidad' => '12-25', + ]; + } + + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Santiago'); + + return [ + 'Jueves santo' => $easter->subDays(3), + 'Viernes santo' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap b/tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap new file mode 100644 index 000000000..88339584a --- /dev/null +++ b/tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap @@ -0,0 +1,70 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "S\u00e1bado Santo", + "date": "2024-03-30" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de las Glorias Navales", + "date": "2024-05-21" + }, + { + "name": "D\u00eda Nacional de los Pueblos Ind\u00edgenas", + "date": "2024-06-20" + }, + { + "name": "San Pedro y San Pablo", + "date": "2024-06-29" + }, + { + "name": "D\u00eda de la Virgen del Carmen", + "date": "2024-07-16" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-15" + }, + { + "name": "Independencia Nacional", + "date": "2024-09-18" + }, + { + "name": "D\u00eda de las Glorias del Ej\u00e9rcito", + "date": "2024-09-19" + }, + { + "name": "Feriado a\u00f1adido de Fiestas Patrias", + "date": "2024-09-20" + }, + { + "name": "Encuentro de Dos Mundos", + "date": "2024-10-12" + }, + { + "name": "D\u00eda de las Iglesias Evang\u00e9licas", + "date": "2024-10-31" + }, + { + "name": "D\u00eda de Todos los Santos", + "date": "2024-11-01" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ChileTest.php b/tests/Countries/ChileTest.php new file mode 100644 index 000000000..aed6f880f --- /dev/null +++ b/tests/Countries/ChileTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 664960223d4a8f1d2e85933dd4e8e01e9dc16a96 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:14:03 +0100 Subject: [PATCH 59/99] cleanup Chile --- src/Countries/Chile.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Chile.php b/src/Countries/Chile.php index 37e0f7255..d4ee5a343 100644 --- a/src/Countries/Chile.php +++ b/src/Countries/Chile.php @@ -34,10 +34,10 @@ protected function allHolidays(int $year): array ]; } + /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('America/Santiago'); + $easter = $this->easter($year); return [ 'Jueves santo' => $easter->subDays(3), From 0ed82081a7602cf507480d8cbc3b045ed13def39 Mon Sep 17 00:00:00 2001 From: PhilN8 <85251946+PhilN8@users.noreply.github.com> Date: Sat, 27 Jan 2024 13:03:10 +0300 Subject: [PATCH 60/99] Added Kenyan holidays (#69) * feat: kenyan holidays added * added Utamaduni Day and Easter holidays * fix:phpstan errors * fix: removed buggy line --- src/Countries/Kenya.php | 39 +++++++++++++++++ .../it_can_calculate_kenyan_holidays.snap | 42 +++++++++++++++++++ tests/Countries/KenyaTest.php | 18 ++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/Countries/Kenya.php create mode 100644 tests/.pest/snapshots/Countries/KenyaTest/it_can_calculate_kenyan_holidays.snap create mode 100644 tests/Countries/KenyaTest.php diff --git a/src/Countries/Kenya.php b/src/Countries/Kenya.php new file mode 100644 index 000000000..f4c506648 --- /dev/null +++ b/src/Countries/Kenya.php @@ -0,0 +1,39 @@ + "01-01", + "Labour" => "05-01", + "Madaraka" => "06-01", + "Utamaduni" => "10-10", + "Mashujaa" => "10-20", + "Jamhuri" => "12-01", + "Christmas" => "12-25", + "Boxing" => "12-26", + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected 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/KenyaTest/it_can_calculate_kenyan_holidays.snap b/tests/.pest/snapshots/Countries/KenyaTest/it_can_calculate_kenyan_holidays.snap new file mode 100644 index 000000000..8ca55adb8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/KenyaTest/it_can_calculate_kenyan_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour", + "date": "2024-05-01" + }, + { + "name": "Madaraka", + "date": "2024-06-01" + }, + { + "name": "Utamaduni", + "date": "2024-10-10" + }, + { + "name": "Mashujaa", + "date": "2024-10-20" + }, + { + "name": "Jamhuri", + "date": "2024-12-01" + }, + { + "name": "Christmas", + "date": "2024-12-25" + }, + { + "name": "Boxing", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/KenyaTest.php b/tests/Countries/KenyaTest.php new file mode 100644 index 000000000..96d17cdf3 --- /dev/null +++ b/tests/Countries/KenyaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From db1952bafe266ef6393d223ac444130e02605cf6 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:03:27 +0000 Subject: [PATCH 61/99] Fix styling --- src/Countries/Kenya.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Countries/Kenya.php b/src/Countries/Kenya.php index f4c506648..82a7ad3d8 100644 --- a/src/Countries/Kenya.php +++ b/src/Countries/Kenya.php @@ -14,14 +14,14 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - "New Year's" => "01-01", - "Labour" => "05-01", - "Madaraka" => "06-01", - "Utamaduni" => "10-10", - "Mashujaa" => "10-20", - "Jamhuri" => "12-01", - "Christmas" => "12-25", - "Boxing" => "12-26", + "New Year's" => '01-01', + 'Labour' => '05-01', + 'Madaraka' => '06-01', + 'Utamaduni' => '10-10', + 'Mashujaa' => '10-20', + 'Jamhuri' => '12-01', + 'Christmas' => '12-25', + 'Boxing' => '12-26', ], $this->variableHolidays($year)); } @@ -32,8 +32,8 @@ protected function variableHolidays(int $year): array ->setTimezone('Africa/Nairobi'); return [ - "Good Friday" => $easter->subDays(2), - "Easter Monday" => $easter->addDay(), + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), ]; } } From 81f1927b06a0991e21b0e335e597355498cae19c Mon Sep 17 00:00:00 2001 From: Kevin Bui Date: Sat, 27 Jan 2024 21:20:13 +1100 Subject: [PATCH 62/99] Add vietnamese holidays (#115) * add Vietnamese holidays according to the standard calendar. * include Vietnamese holidays according to Chinese Calendar. * refactor the a Chinese calendar trait. * update the Lunar New Year's Eve. * re-add snapshots for countries other than Vietnam. * use Vietnamese to name the holidays, English names commented. * For Vietnam, use the country code of vn instead of vi. * refactor according to PHPStan. * specify a type for the $timezone parameter. * Refactor according to PHPStan. * In Vietnam, a day before or after the Independence Day can be a public holiday. * work out some logics to calculate the extra day off for Independence Day. * add a few test cases to make sure the Lunar New Year holiday in Vietnam is calculated correctly. * Add test cases for the holiday of independence. * add doc blocks. * remove empty line. * rename an instance variable. * add two more days to the Lunar Year Year holiday. * refactor from Y/m/d to Y-m-d for Chinese Calendar. * add a few more test cases for Lunar New Year. * refactor the Lunar New Year holiday. * refactor and add a few more test cases. * add translations for vietnam --- lang/vietnam/en/holidays.json | 16 +++ src/Calendars/ChineseCalendar.php | 39 ++++++ src/Countries/Vietnam.php | 117 ++++++++++++++++++ .../it_can_calculate_vietnamese_holidays.snap | 54 ++++++++ tests/Countries/VietnamTest.php | 57 +++++++++ 5 files changed, 283 insertions(+) create mode 100644 lang/vietnam/en/holidays.json create mode 100644 src/Calendars/ChineseCalendar.php create mode 100644 src/Countries/Vietnam.php create mode 100644 tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap create mode 100644 tests/Countries/VietnamTest.php diff --git a/lang/vietnam/en/holidays.json b/lang/vietnam/en/holidays.json new file mode 100644 index 000000000..b074514b0 --- /dev/null +++ b/lang/vietnam/en/holidays.json @@ -0,0 +1,16 @@ +{ + "Tết Dương Lịch":"New Year's Day", + "Ngày Hai Mươi Chín Tết":"12-29 the previous year (in Chinese Calendar)", + "Ngày Ba Mươi Tết":"Lunar New Year's Eve (12-30 in Chinese Calendar)", + "Mùng Một Tết Âm Lịch":"Lunar New Year Day 1", + "Mùng Hai Tết Âm Lịch":"Lunar New Year Day 2", + "Mùng Ba Tết Âm Lịch":"Lunar New Year Day 3", + "Mùng Bốn Tết Âm Lịch":"Lunar New Year Day 4", + "Mùng Năm Tết Âm Lịch":"Lunar New Year Day 5", + "Ngày Giỗ Tổ Hùng Vương":"Hung Kings' Festival", + "Ngày Giải Phóng Miền Nam, Thống Nhất Đất Nước":"Day of Southern Liberation and National Reunification", + "Ngày Quốc Tế Lao Động":"Labour Day", + "Ngày Trước Quốc Khánh":"The Day Before Independence Day", + "Ngày Quốc Khánh":"Independence Day", + "Ngày Sau Quốc Khánh":"The Day After Independence Day" +} \ No newline at end of file diff --git a/src/Calendars/ChineseCalendar.php b/src/Calendars/ChineseCalendar.php new file mode 100644 index 000000000..5ce9996bb --- /dev/null +++ b/src/Calendars/ChineseCalendar.php @@ -0,0 +1,39 @@ +asianTimezone = $asianTimezone; + + return $this; + } + + protected function chineseToGregorianDate(string $input, int $year): CarbonImmutable + { + $timestamp = (int) $this->getFormatter()->parse($year . '-' . $input); + + return (new CarbonImmutable()) + ->setTimeStamp($timestamp) + ->setTimezone(new DateTimeZone($this->asianTimezone)); + } + + protected function getFormatter(): IntlDateFormatter + { + return new IntlDateFormatter( + locale: 'zh-CN@calendar=chinese', + dateType: IntlDateFormatter::SHORT, + timeType: IntlDateFormatter::NONE, + timezone: $this->asianTimezone, + calendar: IntlDateFormatter::TRADITIONAL + ); + } +} \ No newline at end of file diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php new file mode 100644 index 000000000..e99f75919 --- /dev/null +++ b/src/Countries/Vietnam.php @@ -0,0 +1,117 @@ + '01-01', + // Day of Southern Liberation and National Reunification + 'Ngày Giải Phóng Miền Nam, Thống Nhất Đất Nước' => '04-30', + // Labour Day + 'Ngày Quốc Tế Lao Động' => '05-01', + // Independence Day + 'Ngày Quốc Khánh' => '09-02', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $this->setTimezoneForChineseCalendar('Asia/Ho_Chi_Minh'); + + return array_merge( + $this->getHungKingsFestival($year), + $this->getLunarNewYearHoliday($year), + $this->getTheExtraDayForIndependenceDay($year), + ); + } + + /** @return array */ + protected function getHungKingsFestival(int $year): array + { + return [ + // Hung Kings' Festival + 'Ngày Giỗ Tổ Hùng Vương' => $this->chineseToGregorianDate('03-10', $year), + ]; + } + + /** @return array */ + protected function getLunarNewYearHoliday(int $year): array + { + $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); + + return [ + // 12-29 the previous year (in Chinese Calendar) + 'Ngày Hai Mươi Chín Tết' => $firstOfJanInChineseCalendar->subDays(2), + // Lunar New Year's Eve (12-30 in Chinese Calendar) + 'Ngày Ba Mươi Tết' => $firstOfJanInChineseCalendar->subDay(), + // Lunar New Year Day 1 + 'Mùng Một Tết Âm Lịch' => $firstOfJanInChineseCalendar, + // Lunar New Year Day 2 + 'Mùng Hai Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDay(), + // Lunar New Year Day 3 + 'Mùng Ba Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDays(2), + // Lunar New Year Day 4 + 'Mùng Bốn Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDays(3), + // Lunar New Year Day 5 + 'Mùng Năm Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDays(4), + ]; + } + + /** @return array */ + protected function getTheExtraDayForIndependenceDay(int $year): array + { + if ($year < 2021) { + return []; + } + + $independenceDay = CarbonImmutable::parse("$year-09-02") + ->setTimeZone("Asia/Ho_Chi_Minh"); + + if ($independenceDay->dayOfWeek == CarbonImmutable::MONDAY) { + return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::TUESDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::WEDNESDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::THURSDAY) { + return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::FRIDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::SATURDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::SUNDAY) { + return ['Ngày Sau Quốc Khánh' => $independenceDay->addDays(2)]; + } + + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap b/tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap new file mode 100644 index 000000000..3b7cc36f9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "T\u1ebft D\u01b0\u01a1ng L\u1ecbch", + "date": "2024-01-01" + }, + { + "name": "Ng\u00e0y Hai M\u01b0\u01a1i Ch\u00edn T\u1ebft", + "date": "2024-02-08" + }, + { + "name": "Ng\u00e0y Ba M\u01b0\u01a1i T\u1ebft", + "date": "2024-02-09" + }, + { + "name": "M\u00f9ng M\u1ed9t T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-10" + }, + { + "name": "M\u00f9ng Hai T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-11" + }, + { + "name": "M\u00f9ng Ba T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-12" + }, + { + "name": "M\u00f9ng B\u1ed1n T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-13" + }, + { + "name": "M\u00f9ng N\u0103m T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-14" + }, + { + "name": "Ng\u00e0y Gi\u1ed7 T\u1ed5 H\u00f9ng V\u01b0\u01a1ng", + "date": "2024-04-18" + }, + { + "name": "Ng\u00e0y Gi\u1ea3i Ph\u00f3ng Mi\u1ec1n Nam, Th\u1ed1ng Nh\u1ea5t \u0110\u1ea5t N\u01b0\u1edbc", + "date": "2024-04-30" + }, + { + "name": "Ng\u00e0y Qu\u1ed1c T\u1ebf Lao \u0110\u1ed9ng", + "date": "2024-05-01" + }, + { + "name": "Ng\u00e0y Qu\u1ed1c Kh\u00e1nh", + "date": "2024-09-02" + }, + { + "name": "Ng\u00e0y Sau Qu\u1ed1c Kh\u00e1nh", + "date": "2024-09-03" + } +] \ No newline at end of file diff --git a/tests/Countries/VietnamTest.php b/tests/Countries/VietnamTest.php new file mode 100644 index 000000000..edb13028d --- /dev/null +++ b/tests/Countries/VietnamTest.php @@ -0,0 +1,57 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate the Lunar New Year holiday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + + $holidays = Holidays::for(country: 'vn')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $lunarNewYearHoliday = array_map(fn ($date) => $date['date'], formatDates($holidays)); + + expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); +})->with([ + ['year' => 2023, 'expected_holiday' => ['2023-01-20', '2023-01-21', '2023-01-22', '2023-01-23', '2023-01-24', '2023-01-25', '2023-01-26']], + ['year' => 2022, 'expected_holiday' => ['2022-01-30', '2022-01-31', '2022-02-01', '2022-02-02', '2022-02-03', '2022-02-04', '2022-02-05']], + ['year' => 2021, 'expected_holiday' => ['2021-02-10', '2021-02-11', '2021-02-12', '2021-02-13', '2021-02-14', '2021-02-15', '2021-02-16']], + ['year' => 2020, 'expected_holiday' => ['2020-01-23', '2020-01-24', '2020-01-25', '2020-01-26', '2020-01-27', '2020-01-28', '2020-01-29']], + ['year' => 2019, 'expected_holiday' => ['2019-02-03', '2019-02-04', '2019-02-05', '2019-02-06', '2019-02-07', '2019-02-08', '2019-02-08']], +]); + +it('can calculate the holiday of independence', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + + $holidays = Holidays::for(country: 'vn')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $dates = array_map(fn ($date) => $date['date'], formatDates($holidays)); + + expect($dates)->toContain(...$expectedHoliday); +})->with([ + ['year' => 2023, 'expected_holiday' => ['2023-09-01', '2023-09-02']], + ['year' => 2022, 'expected_holiday' => ['2022-09-01', '2022-09-02']], + ['year' => 2021, 'expected_holiday' => ['2021-09-02', '2021-09-03']], +]); From 1ecaacbd7a1be274471f59db1fc5a6e11aaa7a21 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:20:32 +0000 Subject: [PATCH 63/99] Fix styling --- src/Calendars/ChineseCalendar.php | 6 +++--- src/Countries/Vietnam.php | 6 ++---- tests/Countries/VietnamTest.php | 1 - 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Calendars/ChineseCalendar.php b/src/Calendars/ChineseCalendar.php index 5ce9996bb..a19f4d019 100644 --- a/src/Calendars/ChineseCalendar.php +++ b/src/Calendars/ChineseCalendar.php @@ -19,8 +19,8 @@ public function setTimezoneForChineseCalendar(string $asianTimezone): static protected function chineseToGregorianDate(string $input, int $year): CarbonImmutable { - $timestamp = (int) $this->getFormatter()->parse($year . '-' . $input); - + $timestamp = (int) $this->getFormatter()->parse($year.'-'.$input); + return (new CarbonImmutable()) ->setTimeStamp($timestamp) ->setTimezone(new DateTimeZone($this->asianTimezone)); @@ -36,4 +36,4 @@ protected function getFormatter(): IntlDateFormatter calendar: IntlDateFormatter::TRADITIONAL ); } -} \ No newline at end of file +} diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index e99f75919..8f1c9841d 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -3,8 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use DateTimeZone; -use IntlDateFormatter; use Spatie\Holidays\Calendars\ChineseCalendar; class Vietnam extends Country @@ -54,7 +52,7 @@ protected function getHungKingsFestival(int $year): array /** @return array */ protected function getLunarNewYearHoliday(int $year): array { - $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); + $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); return [ // 12-29 the previous year (in Chinese Calendar) @@ -82,7 +80,7 @@ protected function getTheExtraDayForIndependenceDay(int $year): array } $independenceDay = CarbonImmutable::parse("$year-09-02") - ->setTimeZone("Asia/Ho_Chi_Minh"); + ->setTimeZone('Asia/Ho_Chi_Minh'); if ($independenceDay->dayOfWeek == CarbonImmutable::MONDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; diff --git a/tests/Countries/VietnamTest.php b/tests/Countries/VietnamTest.php index edb13028d..d05a4ea4c 100644 --- a/tests/Countries/VietnamTest.php +++ b/tests/Countries/VietnamTest.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Countries\Vietnam; use Spatie\Holidays\Holidays; it('can calculate vietnamese holidays', function () { From 7e912ad1192c4d9df97fd1921417609bc45ac915 Mon Sep 17 00:00:00 2001 From: Arne Breitsprecher Date: Sat, 27 Jan 2024 11:20:44 +0100 Subject: [PATCH 64/99] Germany: Adding local for EN, FR, NL (#183) * Adding germany local for EN, FR, NL * Adding test for local support * Update tests/Countries/GermanyTest.php --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/germany/en/holidays.json | 21 +++++++++++++++++++++ lang/germany/fr/holidays.json | 21 +++++++++++++++++++++ lang/germany/nl/holidays.json | 21 +++++++++++++++++++++ tests/Countries/GermanyTest.php | 15 +++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 lang/germany/en/holidays.json create mode 100644 lang/germany/fr/holidays.json create mode 100644 lang/germany/nl/holidays.json diff --git a/lang/germany/en/holidays.json b/lang/germany/en/holidays.json new file mode 100644 index 000000000..4202f709f --- /dev/null +++ b/lang/germany/en/holidays.json @@ -0,0 +1,21 @@ +{ + "Neujahr": "New Year", + "Heilige Drei Könige": "Epiphany", + "Tag der Arbeit": "Labour Day", + "Himmelfahrt": "Ascension Day", + "Pfingstmontag": "Whit Monday", + "Pfingstsonntag": "Whit Sunday", + "Fronleichnam": "Corpus Christi", + "Mariä Himmelfahrt": "Assumption of Mary", + "Tag der Deutschen Einheit": "German Unity Day", + "Reformationstag": "Reformation Day", + "Allerheiligen": "All Saints' Day", + "Buß- und Bettag": "Repentance and Prayer Day", + "1. Weihnachtstag": "Christmas Day", + "2. Weihnachtstag": "Second Day of Christmas", + "Ostermontag": "Easter Monday", + "Karfreitag": "Good Friday", + "Ostersonntag": "Easter Sunday", + "Internationaler Frauentag": "International Women's Day", + "Weltkindertag": "World Children's Day" +} \ No newline at end of file diff --git a/lang/germany/fr/holidays.json b/lang/germany/fr/holidays.json new file mode 100644 index 000000000..e260be7f5 --- /dev/null +++ b/lang/germany/fr/holidays.json @@ -0,0 +1,21 @@ +{ + "Neujahr": "Jour de l'An", + "Heilige Drei Könige": "Épiphanie", + "Tag der Arbeit": "Fête du Travail", + "Himmelfahrt": "Ascension", + "Pfingstmontag": "Lundi de Pentecôte", + "Pfingstsonntag": "Dimanche de Pentecôte", + "Fronleichnam": "Fête-Dieu", + "Mariä Himmelfahrt": "Assomption", + "Tag der Deutschen Einheit": "Jour de l'Unité allemande", + "Reformationstag": "Fête de la Réformation", + "Allerheiligen": "Toussaint", + "Buß- und Bettag": "Jour de pénitence et de prières", + "1. Weihnachtstag": "Noël", + "2. Weihnachtstag": "Lendemain de Noël", + "Ostermontag": "Lundi de Pâques", + "Karfreitag": "Vendredi Saint", + "Ostersonntag": "Dimanche de Pâques", + "Internationaler Frauentag": "Journée internationale des femmes", + "Weltkindertag": "Journée de l'enfance" +} \ No newline at end of file diff --git a/lang/germany/nl/holidays.json b/lang/germany/nl/holidays.json new file mode 100644 index 000000000..98f8a17cb --- /dev/null +++ b/lang/germany/nl/holidays.json @@ -0,0 +1,21 @@ +{ + "Neujahr": "Nieuwjaar", + "Heilige Drei Könige": "Driekoningen", + "Tag der Arbeit": "Dag van de Arbeid", + "Himmelfahrt": "Hemelvaart", + "Pfingstmontag": "Tweede pinksterdag", + "Pfingstsonntag": "Eerste Pinksterdag", + "Fronleichnam": "Sacramentsdag", + "Mariä Himmelfahrt": "Mariahemelvaart", + "Tag der Deutschen Einheit": "Dag van de Duitse eenheid", + "Reformationstag": "Hervormingsdag", + "Allerheiligen": "Allerheiligen", + "Buß- und Bettag": "Boete- en Biddag", + "1. Weihnachtstag": "Eerste kerstdag", + "2. Weihnachtstag": "Tweede kerstdag", + "Ostermontag": "Tweede paasdag", + "Karfreitag": "Goede Vrijdag", + "Ostersonntag": "Eerste paasdag", + "Internationaler Frauentag": "Internationale vrouwendag", + "Weltkindertag": "Kinderdag" +} \ No newline at end of file diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index b6a4f710f..9ae4e1489 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Countries\Germany; +use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Holidays; it('can calculate german holidays', function () { @@ -78,3 +79,17 @@ ['SH', 10], ['TH', 11]] ); + +it('can calculate german holidays in local', function (string $locale, string $newYearsDayName) { + CarbonImmutable::setTestNow('2024-01-01'); + $result = Holidays::for(country: 'de', year: 2024, locale: $locale)->get(); + + expect($result)->toBeArray(); + expect($result[0]['name'])->toBe($newYearsDayName); +})->with( + [ + ['en','New Year'], + ['nl','Nieuwjaar'], + ['fr','Jour de l\'An'] + ] +); \ No newline at end of file From 57ff3b24e279c239998e8e7c1c28571bd89bbceb Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:21:03 +0000 Subject: [PATCH 65/99] Fix styling --- tests/Countries/GermanyTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index 9ae4e1489..24f2aa199 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Countries\Germany; -use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Holidays; it('can calculate german holidays', function () { @@ -88,8 +87,8 @@ expect($result[0]['name'])->toBe($newYearsDayName); })->with( [ - ['en','New Year'], - ['nl','Nieuwjaar'], - ['fr','Jour de l\'An'] + ['en', 'New Year'], + ['nl', 'Nieuwjaar'], + ['fr', 'Jour de l\'An'], ] -); \ No newline at end of file +); From 9bb7bb2d487f75d56ac00ed29d0e5e2f875d6e61 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:26:45 +0100 Subject: [PATCH 66/99] ChineseCalendar changes --- src/Calendars/ChineseCalendar.php | 10 +++++----- src/Countries/Vietnam.php | 17 +++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Calendars/ChineseCalendar.php b/src/Calendars/ChineseCalendar.php index a19f4d019..689b26874 100644 --- a/src/Calendars/ChineseCalendar.php +++ b/src/Calendars/ChineseCalendar.php @@ -8,11 +8,11 @@ trait ChineseCalendar { - protected string $asianTimezone = 'Asia/Shanghai'; + protected string $chineseCalendarTimezone = 'Asia/Shanghai'; - public function setTimezoneForChineseCalendar(string $asianTimezone): static + public function setChineseCalendarTimezone(string $chineseCalendarTimezone): static { - $this->asianTimezone = $asianTimezone; + $this->chineseCalendarTimezone = $chineseCalendarTimezone; return $this; } @@ -23,7 +23,7 @@ protected function chineseToGregorianDate(string $input, int $year): CarbonImmut return (new CarbonImmutable()) ->setTimeStamp($timestamp) - ->setTimezone(new DateTimeZone($this->asianTimezone)); + ->setTimezone(new DateTimeZone($this->chineseCalendarTimezone)); } protected function getFormatter(): IntlDateFormatter @@ -32,7 +32,7 @@ protected function getFormatter(): IntlDateFormatter locale: 'zh-CN@calendar=chinese', dateType: IntlDateFormatter::SHORT, timeType: IntlDateFormatter::NONE, - timezone: $this->asianTimezone, + timezone: $this->chineseCalendarTimezone, calendar: IntlDateFormatter::TRADITIONAL ); } diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index 8f1c9841d..76ae6f1b5 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; use Spatie\Holidays\Calendars\ChineseCalendar; class Vietnam extends Country @@ -31,7 +32,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $this->setTimezoneForChineseCalendar('Asia/Ho_Chi_Minh'); + $this->setChineseCalendarTimezone('Asia/Ho_Chi_Minh'); return array_merge( $this->getHungKingsFestival($year), @@ -82,31 +83,31 @@ protected function getTheExtraDayForIndependenceDay(int $year): array $independenceDay = CarbonImmutable::parse("$year-09-02") ->setTimeZone('Asia/Ho_Chi_Minh'); - if ($independenceDay->dayOfWeek == CarbonImmutable::MONDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::MONDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::TUESDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::TUESDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::WEDNESDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::WEDNESDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::THURSDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::THURSDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::FRIDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::FRIDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::SATURDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::SATURDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::SUNDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::SUNDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDays(2)]; } From 40048aa869ee512531a542b780ff6b18c99febd9 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:29:53 +0100 Subject: [PATCH 67/99] fix failing tests --- tests/Countries/VietnamTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Countries/VietnamTest.php b/tests/Countries/VietnamTest.php index d05a4ea4c..a83eb01fc 100644 --- a/tests/Countries/VietnamTest.php +++ b/tests/Countries/VietnamTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate vietnamese holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Asia/Ho_Chi_Minh'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'vn')->get(); @@ -18,7 +18,7 @@ }); it('can calculate the Lunar New Year holiday', function ($year, $expectedHoliday) { - CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + CarbonImmutable::setTestNow("{$year}-01-01"); $holidays = Holidays::for(country: 'vn')->get(); @@ -38,7 +38,7 @@ ]); it('can calculate the holiday of independence', function ($year, $expectedHoliday) { - CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + CarbonImmutable::setTestNow("{$year}-01-01"); $holidays = Holidays::for(country: 'vn')->get(); From 3b1c0bd9384bef35a050e75f7345a2808323934f Mon Sep 17 00:00:00 2001 From: Takeshi Yu Date: Sat, 27 Jan 2024 18:57:08 +0800 Subject: [PATCH 68/99] Support for Taiwan holidays (#124) * support Taiwan holidays * Refactor lunarCalendar method to handle parsing errors * Update variableHolidays to correctly return converted dates * Refactor variableHolidays to combine array_map and array_filter * use the Taiwanese language to label the holiday --------- Co-authored-by: Takeshi Yu --- composer.json | 4 +- src/Countries/Taiwan.php | 63 +++++++++++++++++++ .../it_can_calculate_taiwan_holidays.snap | 38 +++++++++++ tests/Countries/TaiwanTest.php | 19 ++++++ 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 src/Countries/Taiwan.php create mode 100644 tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap create mode 100644 tests/Countries/TaiwanTest.php diff --git a/composer.json b/composer.json index 8e0f585dc..d51ff2f1e 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": "^8.1", - "nesbot/carbon": "^2.72.1", - "ext-calendar": "*" + "ext-intl": "*", + "nesbot/carbon": "^2.72.1" }, "require-dev": { "laravel/pint": "^1.0", diff --git a/src/Countries/Taiwan.php b/src/Countries/Taiwan.php new file mode 100644 index 000000000..804c06424 --- /dev/null +++ b/src/Countries/Taiwan.php @@ -0,0 +1,63 @@ + '01-01', + '228和平紀念日' => '02-28', + '兒童節' => '04-04', + '雙十國慶' => '10-10', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + return array_filter(array_map(fn ($date) => $this->lunarCalendar($date, $year), [ + '農曆春節-正月初一' => '01-01', + '農曆春節-正月初二' => '01-02', + '農曆春節-正月初三' => '01-03', + '端午節' => '05-05', + '中秋節' => '08-15', + ])); + } + + protected function lunarCalendar(string $input, int $year): ?string + { + $formatter = new IntlDateFormatter( + locale: 'zh-TW@calendar=chinese', + dateType: IntlDateFormatter::SHORT, + timeType: IntlDateFormatter::NONE, + timezone: $this->timezone, + calendar: IntlDateFormatter::TRADITIONAL + ); + + $lunarDateStr = $year . '-' . $input; + $parsedTimestamp = $formatter->parse($lunarDateStr); + + if ($parsedTimestamp === false) { + return null; + } + + $dateTime = new DateTime; + $dateTime->setTimestamp($parsedTimestamp); + $dateTime->setTimezone(new DateTimeZone($this->timezone)); + + return $dateTime->format('m-d'); + } +} diff --git a/tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap b/tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap new file mode 100644 index 000000000..637abf2c6 --- /dev/null +++ b/tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "\u5143\u65e6", + "date": "2024-01-01" + }, + { + "name": "\u8fb2\u66c6\u6625\u7bc0-\u6b63\u6708\u521d\u4e00", + "date": "2024-02-10" + }, + { + "name": "\u8fb2\u66c6\u6625\u7bc0-\u6b63\u6708\u521d\u4e8c", + "date": "2024-02-11" + }, + { + "name": "\u8fb2\u66c6\u6625\u7bc0-\u6b63\u6708\u521d\u4e09", + "date": "2024-02-12" + }, + { + "name": "228\u548c\u5e73\u7d00\u5ff5\u65e5", + "date": "2024-02-28" + }, + { + "name": "\u5152\u7ae5\u7bc0", + "date": "2024-04-04" + }, + { + "name": "\u7aef\u5348\u7bc0", + "date": "2024-06-10" + }, + { + "name": "\u4e2d\u79cb\u7bc0", + "date": "2024-09-17" + }, + { + "name": "\u96d9\u5341\u570b\u6176", + "date": "2024-10-10" + } +] \ No newline at end of file diff --git a/tests/Countries/TaiwanTest.php b/tests/Countries/TaiwanTest.php new file mode 100644 index 000000000..75c7b6906 --- /dev/null +++ b/tests/Countries/TaiwanTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From d04df737ab7ed0e6c24019b042060f87ccba546c Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:57:27 +0000 Subject: [PATCH 69/99] Fix styling --- src/Countries/Taiwan.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Taiwan.php b/src/Countries/Taiwan.php index 804c06424..762c2c892 100644 --- a/src/Countries/Taiwan.php +++ b/src/Countries/Taiwan.php @@ -47,7 +47,7 @@ protected function lunarCalendar(string $input, int $year): ?string calendar: IntlDateFormatter::TRADITIONAL ); - $lunarDateStr = $year . '-' . $input; + $lunarDateStr = $year.'-'.$input; $parsedTimestamp = $formatter->parse($lunarDateStr); if ($parsedTimestamp === false) { From a3d0e1f685deb1a91fc37f8bce79615255e2ba09 Mon Sep 17 00:00:00 2001 From: Arne Breitsprecher Date: Sat, 27 Jan 2024 16:45:52 +0100 Subject: [PATCH 70/99] Update region parameter in country constructor to a working example (#184) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 508e61d5b..69240bf97 100644 --- a/README.md +++ b/README.md @@ -128,13 +128,13 @@ 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(region: 'de-bw'))->get(); +$holidays = Holidays::for(Germany::make(region: 'DE-BW'))->get(); ``` -The value, `de-bw`, will be passed to the region parameter of the constructor of a country. +The value, `DE-BW`, will be passed to the region parameter of the constructor of a country. ```php -class Austria extends Country +class Germany extends Country { protected function __construct( protected ?string $region = null, From 4c5ff964e6af9a7c53906ead846029d136618afd Mon Sep 17 00:00:00 2001 From: Martin Welte Date: Sat, 27 Jan 2024 16:48:37 +0100 Subject: [PATCH 71/99] Draft: Add Support for Switzerland (#49) * feat: add switzerland * test: add switzerland test * feat: add region and translation Support * test: update tests * test: add snapshots * feat: add translations for switzerland * feat: update switzerland to use global languages * test: update Switzerland tests --- lang/switzerland/de/holidays.json | 18 + lang/switzerland/fr/holidays.json | 18 + lang/switzerland/it/holidays.json | 18 + src/Countries/Switzerland.php | 316 ++++++++++++++++++ src/Exceptions/InvalidRegion.php | 18 + .../it_can_calculate_swiss_holidays.snap | 38 +++ ..._holidays_for_a_specified_region__zh_.snap | 38 +++ ..._translate_swiss_holidays_into_french.snap | 38 +++ ...translate_swiss_holidays_into_italian.snap | 38 +++ tests/Countries/SwitzerlandTest.php | 58 ++++ 10 files changed, 598 insertions(+) create mode 100644 lang/switzerland/de/holidays.json create mode 100644 lang/switzerland/fr/holidays.json create mode 100644 lang/switzerland/it/holidays.json create mode 100644 src/Countries/Switzerland.php create mode 100644 src/Exceptions/InvalidRegion.php create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_calculate_swiss_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_translate_swiss_holidays_into_french.snap create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_translate_swiss_holidays_into_italian.snap create mode 100644 tests/Countries/SwitzerlandTest.php diff --git a/lang/switzerland/de/holidays.json b/lang/switzerland/de/holidays.json new file mode 100644 index 000000000..c294fd7b8 --- /dev/null +++ b/lang/switzerland/de/holidays.json @@ -0,0 +1,18 @@ +{ + "Neujahr": "Neujahr", + "Berchtoldstag": "Berchtoldstag", + "Heilige Drei Könige": "Heilige Drei Könige", + "Josefstag": "Josefstag", + "Karfreitag": "Karfreitag", + "Ostermontag": "Ostermontag", + "Tag der Arbeit": "Tag der Arbeit", + "Auffahrt": "Auffahrt", + "Pfingstmontag": "Pfingstmontag", + "Fronleichnam": "Fronleichnam", + "Bundesfeier": "Bundesfeier", + "Maria Himmelfahrt": "Maria Himmelfahrt", + "Allerheiligen": "Allerheiligen", + "Maria Empfängnis": "Maria Empfängnis", + "Weihnachtstag": "Weihnachtstag", + "Stephanstag": "Stephanstag" +} diff --git a/lang/switzerland/fr/holidays.json b/lang/switzerland/fr/holidays.json new file mode 100644 index 000000000..0fe65215c --- /dev/null +++ b/lang/switzerland/fr/holidays.json @@ -0,0 +1,18 @@ +{ + "Neujahr": "Nouvel An", + "Berchtoldstag": "Saint-Berthold", + "Heilige Drei Könige": "Épiphanie", + "Josefstag": "Saint-Joseph", + "Karfreitag": "Vendredi saint", + "Ostermontag": "Lundi de Pâques", + "Tag der Arbeit": "Fête du travail", + "Auffahrt": "Ascension", + "Pfingstmontag": "Lundi de Pentecôte", + "Fronleichnam": "Fête-Dieu", + "Bundesfeier": "Fête nationale", + "Maria Himmelfahrt": "Assomption", + "Allerheiligen": "Toussaint", + "Maria Empfängnis": "Immaculée Conception", + "Weihnachtstag": "Noël", + "Stephanstag": "Saint-Étienne" +} diff --git a/lang/switzerland/it/holidays.json b/lang/switzerland/it/holidays.json new file mode 100644 index 000000000..e7a30514c --- /dev/null +++ b/lang/switzerland/it/holidays.json @@ -0,0 +1,18 @@ +{ + "Neujahr": "Capodanno", + "Berchtoldstag": "San Silvestro", + "Heilige Drei Könige": "Epifania", + "Josefstag": "San Giuseppe", + "Karfreitag": "Venerdì Santo", + "Ostermontag": "Lunedì di Pasqua", + "Tag der Arbeit": "Festa del lavoro", + "Auffahrt": "Ascensione", + "Pfingstmontag": "Lunedì di Pentecoste", + "Fronleichnam": "Corpus Domini", + "Bundesfeier": "Festa nazionale", + "Maria Himmelfahrt": "Assunzione", + "Allerheiligen": "Ognissanti", + "Maria Empfängnis": "Immacolata Concezione", + "Weihnachtstag": "Natale", + "Stephanstag": "Santo Stefano" +} diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php new file mode 100644 index 000000000..6259e3d9b --- /dev/null +++ b/src/Countries/Switzerland.php @@ -0,0 +1,316 @@ + + */ + public function regionalHolidays(int $year): array + { + if ($this->region === null) { + return []; + } + + $easter = $this->easter($year); + + $sharedHolidays = [ + self::NEW_YEAR => '01-01', + self::ASCENSION_DAY => $easter->addDays(39), + self::FEDERAL_CELEBRATION => '08-01', + self::CHRISTMAS_DAY => '12-25', + ]; + + $regionallyDifferentHolidays = [ + self::SECOND_JANUARY => '01-02', + self::THREE_KINGS => '01-06', + self::DAY_OF_JOSEPH => '03-19', + self::GOOD_FRIDAY => $easter->subDays(2), + self::EASTER_MONDAY => $easter->addDay(), + self::LABOR_DAY => '05-01', + self::WHIT_MONDAY => $easter->addDays(50), + self::CORPUS_CHRISTI => $easter->addDays(60), + self::ASSUMPTION_DAY => '08-15', + self::ALL_SAINTS_DAY => '11-01', + self::IMMACULATE_CONCEPTION => '12-08', + self::ST_STEPHENS_DAY => '12-26', + ]; + + $currentRegion = match($this->region) { + 'ch-ag' => [ + self::GOOD_FRIDAY, + ], + 'ch-ar' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ai' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::CORPUS_CHRISTI, + self::ST_STEPHENS_DAY, + ], + 'ch-bl' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-bs' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-be' => [ + self::SECOND_JANUARY, + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-fr' => [ + self::GOOD_FRIDAY, + ], + 'ch-ge' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + ], + 'ch-gl' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-gr' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ju' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::CORPUS_CHRISTI, + ], + 'ch-lu' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ne' => [ + self::GOOD_FRIDAY, + self::LABOR_DAY, + ], + 'ch-nw' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-ow' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-sh' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-sz' => [ + self::DAY_OF_JOSEPH, + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + ], + 'ch-so' => [ + self::GOOD_FRIDAY, + ], + 'ch-sg' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ALL_SAINTS_DAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ti' => [ + self::THREE_KINGS, + self::EASTER_MONDAY, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::ST_STEPHENS_DAY, + ], + 'ch-tg' => [ + self::SECOND_JANUARY, + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ur' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-vd' => [ + self::SECOND_JANUARY, + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + ], + 'ch-vs' => [ + self::DAY_OF_JOSEPH, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-zg' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-zh' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + default => [], + }; + + $regionalHolidays = array_filter( + $regionallyDifferentHolidays, + fn ($key) => in_array($key, $currentRegion), + ARRAY_FILTER_USE_KEY + ); + + return array_merge($regionalHolidays, $sharedHolidays); + } + + protected function allHolidays(int $year): array + { + if($this->region !== null) { + return $this->regionalHolidays($year); + } + + return array_merge([ + self::NEW_YEAR => '01-01', + self::SECOND_JANUARY => '01-02', + self::FEDERAL_CELEBRATION => '08-01', + self::CHRISTMAS_DAY => '12-25', + self::ST_STEPHENS_DAY => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + self::GOOD_FRIDAY => $easter->subDays(2), + self::EASTER_MONDAY => $easter->addDay(), + self::ASCENSION_DAY => $easter->addDays(39), + self::WHIT_MONDAY => $easter->addDays(50), + ]; + } +} diff --git a/src/Exceptions/InvalidRegion.php b/src/Exceptions/InvalidRegion.php new file mode 100644 index 000000000..7941fe2b5 --- /dev/null +++ b/src/Exceptions/InvalidRegion.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can get swiss holidays for a specified region (zh)', function() { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $switzerland = new Switzerland(region: 'ch-zh'); + + $holidays = Holidays::for($switzerland)->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('throws an error when an invalid region is given', function () { + new Switzerland('ch-xx'); +})->throws(InvalidRegion::class); + +it('can translate swiss holidays into french', function() { + $holidays = Holidays::for(country: 'ch', locale: 'fr', year: 2024)->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can translate swiss holidays into italian', function() { + $holidays = Holidays::for(country: 'ch', locale: 'it', year: 2024)->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From bd6d672ee3dbd307c04558756de4b33e7ca3e581 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 15:48:59 +0000 Subject: [PATCH 72/99] Fix styling --- src/Countries/Switzerland.php | 6 +++--- tests/Countries/SwitzerlandTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index 6259e3d9b..94d52f8c9 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -70,7 +70,7 @@ class Switzerland extends Country public function __construct(protected ?string $region = null) { - if ($region !== null && !in_array($region, self::REGIONS)) { + if ($region !== null && ! in_array($region, self::REGIONS)) { throw InvalidRegion::unsupportedRegion($region); } } @@ -113,7 +113,7 @@ public function regionalHolidays(int $year): array self::ST_STEPHENS_DAY => '12-26', ]; - $currentRegion = match($this->region) { + $currentRegion = match ($this->region) { 'ch-ag' => [ self::GOOD_FRIDAY, ], @@ -288,7 +288,7 @@ public function regionalHolidays(int $year): array protected function allHolidays(int $year): array { - if($this->region !== null) { + if ($this->region !== null) { return $this->regionalHolidays($year); } diff --git a/tests/Countries/SwitzerlandTest.php b/tests/Countries/SwitzerlandTest.php index 1b3ba626a..0e4a97f41 100644 --- a/tests/Countries/SwitzerlandTest.php +++ b/tests/Countries/SwitzerlandTest.php @@ -19,7 +19,7 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); -it('can get swiss holidays for a specified region (zh)', function() { +it('can get swiss holidays for a specified region (zh)', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); $switzerland = new Switzerland(region: 'ch-zh'); @@ -37,7 +37,7 @@ new Switzerland('ch-xx'); })->throws(InvalidRegion::class); -it('can translate swiss holidays into french', function() { +it('can translate swiss holidays into french', function () { $holidays = Holidays::for(country: 'ch', locale: 'fr', year: 2024)->get(); expect($holidays) @@ -47,7 +47,7 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); -it('can translate swiss holidays into italian', function() { +it('can translate swiss holidays into italian', function () { $holidays = Holidays::for(country: 'ch', locale: 'it', year: 2024)->get(); expect($holidays) From db113b099a332fe21037118d1c8ee32303d0fdb4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:49:40 +0100 Subject: [PATCH 73/99] undo code styling on PRs --- .github/workflows/fix-php-code-style-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 99b82e963..30e62c774 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -1,6 +1,6 @@ name: Fix PHP code style issues -on: [push, pull_request] +on: [push] permissions: contents: write From d6701a68bcbab45098dd17cd87590b2fd7bd44a7 Mon Sep 17 00:00:00 2001 From: Alpha Olomi Date: Sat, 27 Jan 2024 18:59:52 +0300 Subject: [PATCH 74/99] Add Tanzania national and religious holiday (#98) * Add Tanzania national and religious holiday Co-Authored-By: Michael Omakei <48096457+omakei@users.noreply.github.com> * feat: revise religious Holidays Co-Authored-By: Michael Omakei <48096457+omakei@users.noreply.github.com> --------- Co-authored-by: Michael Omakei <48096457+omakei@users.noreply.github.com> --- src/Countries/Tanzania.php | 64 +++++++++++++++++++ .../it_can_calculate_tanzania_holidays.snap | 54 ++++++++++++++++ tests/Countries/TanzaniaTest.php | 18 ++++++ 3 files changed, 136 insertions(+) create mode 100644 src/Countries/Tanzania.php create mode 100644 tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap create mode 100644 tests/Countries/TanzaniaTest.php diff --git a/src/Countries/Tanzania.php b/src/Countries/Tanzania.php new file mode 100644 index 000000000..05e16186a --- /dev/null +++ b/src/Countries/Tanzania.php @@ -0,0 +1,64 @@ + '01-01', + 'Labor Day' => '05-01', + 'Saba Saba Day' => '07-07', + 'Farmers Day (Nane Nane Day)' => '08-08', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + $variable_holidays = [ + 'Easter Monday' => $easter->addDay(), + 'Good Friday' => $easter->addDays(-2), + ]; + + // Zanzibar Revolutionary Day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Zanzibar Revolutionary Day'] = '01-12'; + } + + // Karume Day celebrations started in 1973 + if ($year >= 1973) { + $variable_holidays['Karume Day'] = '04-07'; + } + + // 'Union Day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Union Day'] = '04-26'; + } + + // Nyerere Day day celebrations started in 2000 + if ($year >= 2000) { + $variable_holidays['Nyerere Day'] = '10-14'; + } + + // Independence Day celebrations started in 1961 + if ($year >= 1961) { + $variable_holidays['Independence Day'] = '12-09'; + } + + return $variable_holidays; + } +} diff --git a/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap new file mode 100644 index 000000000..d1d187c0d --- /dev/null +++ b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Zanzibar Revolutionary Day", + "date": "2024-01-12" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Karume Day", + "date": "2024-04-07" + }, + { + "name": "Union Day", + "date": "2024-04-26" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Saba Saba Day", + "date": "2024-07-07" + }, + { + "name": "Farmers Day (Nane Nane Day)", + "date": "2024-08-08" + }, + { + "name": "Nyerere Day", + "date": "2024-10-14" + }, + { + "name": "Independence Day", + "date": "2024-12-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/TanzaniaTest.php b/tests/Countries/TanzaniaTest.php new file mode 100644 index 000000000..69777866b --- /dev/null +++ b/tests/Countries/TanzaniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 6e152ff4c77e4584a020259e0299af35e0f73756 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 16:00:12 +0000 Subject: [PATCH 75/99] Fix styling --- src/Countries/Tanzania.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/Tanzania.php b/src/Countries/Tanzania.php index 05e16186a..7b318534a 100644 --- a/src/Countries/Tanzania.php +++ b/src/Countries/Tanzania.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use IntlCalendar; class Tanzania extends Country { @@ -20,7 +19,7 @@ protected function allHolidays(int $year): array 'Saba Saba Day' => '07-07', 'Farmers Day (Nane Nane Day)' => '08-08', 'Christmas Day' => '12-25', - 'Boxing Day' => '12-26' + 'Boxing Day' => '12-26', ], $this->variableHolidays($year)); } From 1d6fdabb246d1190809fc7cea1c5de12ec25e4d2 Mon Sep 17 00:00:00 2001 From: Raiquen Guidotti Date: Mon, 29 Jan 2024 10:08:27 +0100 Subject: [PATCH 76/99] Switzerland: add missing holidays to "ch-ur" region (#191) * style: rename holidays variable names of Switzerland for consistency and correctness * feat: add missing holiday to ch-zh * feat: add missing holidays to ch-ur --- lang/switzerland/de/holidays.json | 1 + lang/switzerland/fr/holidays.json | 1 + lang/switzerland/it/holidays.json | 1 + src/Countries/Switzerland.php | 91 ++++++++++--------- ..._holidays_for_a_specified_region__zh_.snap | 4 + 5 files changed, 57 insertions(+), 41 deletions(-) diff --git a/lang/switzerland/de/holidays.json b/lang/switzerland/de/holidays.json index c294fd7b8..f59358468 100644 --- a/lang/switzerland/de/holidays.json +++ b/lang/switzerland/de/holidays.json @@ -11,6 +11,7 @@ "Fronleichnam": "Fronleichnam", "Bundesfeier": "Bundesfeier", "Maria Himmelfahrt": "Maria Himmelfahrt", + "Buss- und Bettag" : "Buss- und Bettag", "Allerheiligen": "Allerheiligen", "Maria Empfängnis": "Maria Empfängnis", "Weihnachtstag": "Weihnachtstag", diff --git a/lang/switzerland/fr/holidays.json b/lang/switzerland/fr/holidays.json index 0fe65215c..28a04b822 100644 --- a/lang/switzerland/fr/holidays.json +++ b/lang/switzerland/fr/holidays.json @@ -11,6 +11,7 @@ "Fronleichnam": "Fête-Dieu", "Bundesfeier": "Fête nationale", "Maria Himmelfahrt": "Assomption", + "Buss- und Bettag": "Jeûne fédéral", "Allerheiligen": "Toussaint", "Maria Empfängnis": "Immaculée Conception", "Weihnachtstag": "Noël", diff --git a/lang/switzerland/it/holidays.json b/lang/switzerland/it/holidays.json index e7a30514c..e62ec667e 100644 --- a/lang/switzerland/it/holidays.json +++ b/lang/switzerland/it/holidays.json @@ -11,6 +11,7 @@ "Fronleichnam": "Corpus Domini", "Bundesfeier": "Festa nazionale", "Maria Himmelfahrt": "Assunzione", + "Buss- und Bettag": "Digiuno federale", "Allerheiligen": "Ognissanti", "Maria Empfängnis": "Immacolata Concezione", "Weihnachtstag": "Natale", diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index 94d52f8c9..662860019 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -36,19 +36,19 @@ class Switzerland extends Country 'ch-zh', ]; - private const NEW_YEAR = 'Neujahr'; + private const NEW_YEARS_DAY = 'Neujahr'; - private const SECOND_JANUARY = 'Berchtoldstag'; + private const BERCHTOLDS_DAY = 'Berchtoldstag'; - private const THREE_KINGS = 'Heilige Drei Könige'; + private const THREE_KINGS_DAY = 'Heilige Drei Könige'; - private const DAY_OF_JOSEPH = 'Josefstag'; + private const SAINT_JOSEPHS_DAY = 'Josefstag'; private const GOOD_FRIDAY = 'Karfreitag'; private const EASTER_MONDAY = 'Ostermontag'; - private const LABOR_DAY = 'Tag der Arbeit'; + private const LABOUR_DAY = 'Tag der Arbeit'; private const ASCENSION_DAY = 'Auffahrt'; @@ -56,17 +56,19 @@ class Switzerland extends Country private const CORPUS_CHRISTI = 'Fronleichnam'; - private const FEDERAL_CELEBRATION = 'Bundesfeier'; + private const SWISS_NATIONAL_HOLIDAY = 'Bundesfeier'; private const ASSUMPTION_DAY = 'Maria Himmelfahrt'; + private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER = "Buss- und Bettag"; + private const ALL_SAINTS_DAY = 'Allerheiligen'; private const IMMACULATE_CONCEPTION = 'Maria Empfängnis'; private const CHRISTMAS_DAY = 'Weihnachtstag'; - private const ST_STEPHENS_DAY = 'Stephanstag'; + private const SAINT_STEPHENS_DAY = 'Stephanstag'; public function __construct(protected ?string $region = null) { @@ -92,25 +94,26 @@ public function regionalHolidays(int $year): array $easter = $this->easter($year); $sharedHolidays = [ - self::NEW_YEAR => '01-01', + self::NEW_YEARS_DAY => '01-01', self::ASCENSION_DAY => $easter->addDays(39), - self::FEDERAL_CELEBRATION => '08-01', + self::SWISS_NATIONAL_HOLIDAY => '08-01', self::CHRISTMAS_DAY => '12-25', ]; $regionallyDifferentHolidays = [ - self::SECOND_JANUARY => '01-02', - self::THREE_KINGS => '01-06', - self::DAY_OF_JOSEPH => '03-19', + self::BERCHTOLDS_DAY => '01-02', + self::THREE_KINGS_DAY => '01-06', + self::SAINT_JOSEPHS_DAY => '03-19', self::GOOD_FRIDAY => $easter->subDays(2), self::EASTER_MONDAY => $easter->addDay(), - self::LABOR_DAY => '05-01', + self::LABOUR_DAY => '05-01', self::WHIT_MONDAY => $easter->addDays(50), self::CORPUS_CHRISTI => $easter->addDays(60), self::ASSUMPTION_DAY => '08-15', + self::FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER => new CarbonImmutable('third sunday of September '.$year, 'Europe/Zurich'), self::ALL_SAINTS_DAY => '11-01', self::IMMACULATE_CONCEPTION => '12-08', - self::ST_STEPHENS_DAY => '12-26', + self::SAINT_STEPHENS_DAY => '12-26', ]; $currentRegion = match ($this->region) { @@ -121,35 +124,35 @@ public function regionalHolidays(int $year): array self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ai' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, self::CORPUS_CHRISTI, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-bl' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-bs' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-be' => [ - self::SECOND_JANUARY, + self::BERCHTOLDS_DAY, self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-fr' => [ self::GOOD_FRIDAY, @@ -169,12 +172,12 @@ public function regionalHolidays(int $year): array self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ju' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, self::CORPUS_CHRISTI, ], @@ -183,11 +186,11 @@ public function regionalHolidays(int $year): array self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ne' => [ self::GOOD_FRIDAY, - self::LABOR_DAY, + self::LABOUR_DAY, ], 'ch-nw' => [ self::GOOD_FRIDAY, @@ -207,10 +210,10 @@ public function regionalHolidays(int $year): array self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-sz' => [ - self::DAY_OF_JOSEPH, + self::SAINT_JOSEPHS_DAY, self::GOOD_FRIDAY, self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, @@ -224,37 +227,42 @@ public function regionalHolidays(int $year): array self::EASTER_MONDAY, self::WHIT_MONDAY, self::ALL_SAINTS_DAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ti' => [ - self::THREE_KINGS, + self::THREE_KINGS_DAY, self::EASTER_MONDAY, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-tg' => [ - self::SECOND_JANUARY, + self::BERCHTOLDS_DAY, self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ur' => [ + self::THREE_KINGS_DAY, + self::SAINT_JOSEPHS_DAY, self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, self::IMMACULATE_CONCEPTION, + self::SAINT_STEPHENS_DAY ], 'ch-vd' => [ - self::SECOND_JANUARY, + self::BERCHTOLDS_DAY, self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, ], 'ch-vs' => [ - self::DAY_OF_JOSEPH, + self::SAINT_JOSEPHS_DAY, self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, @@ -270,9 +278,10 @@ public function regionalHolidays(int $year): array 'ch-zh' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER, + self::SAINT_STEPHENS_DAY, ], default => [], }; @@ -293,11 +302,11 @@ protected function allHolidays(int $year): array } return array_merge([ - self::NEW_YEAR => '01-01', - self::SECOND_JANUARY => '01-02', - self::FEDERAL_CELEBRATION => '08-01', + self::NEW_YEARS_DAY => '01-01', + self::BERCHTOLDS_DAY => '01-02', + self::SWISS_NATIONAL_HOLIDAY => '08-01', self::CHRISTMAS_DAY => '12-25', - self::ST_STEPHENS_DAY => '12-26', + self::SAINT_STEPHENS_DAY => '12-26', ], $this->variableHolidays($year)); } diff --git a/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap b/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap index f4b753733..f594ea470 100644 --- a/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap +++ b/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap @@ -27,6 +27,10 @@ "name": "Bundesfeier", "date": "2024-08-01" }, + { + "name": "Buss- und Bettag", + "date": "2024-09-15" + }, { "name": "Weihnachtstag", "date": "2024-12-25" From e9445b09a49c45dc447e88a3757a049e21293dc1 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Mon, 29 Jan 2024 09:08:45 +0000 Subject: [PATCH 77/99] Fix styling --- src/Countries/Switzerland.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index 662860019..c2e9d157c 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -60,7 +60,7 @@ class Switzerland extends Country private const ASSUMPTION_DAY = 'Maria Himmelfahrt'; - private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER = "Buss- und Bettag"; + private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER = 'Buss- und Bettag'; private const ALL_SAINTS_DAY = 'Allerheiligen'; @@ -253,7 +253,7 @@ public function regionalHolidays(int $year): array self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, self::IMMACULATE_CONCEPTION, - self::SAINT_STEPHENS_DAY + self::SAINT_STEPHENS_DAY, ], 'ch-vd' => [ self::BERCHTOLDS_DAY, From 34f55ba5befada5a8d2c29ade9b83bcabe244e45 Mon Sep 17 00:00:00 2001 From: Arne Breitsprecher Date: Mon, 29 Jan 2024 10:12:19 +0100 Subject: [PATCH 78/99] Germany: Setting some historical holidays (#188) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update region parameter in country constructor to a working example * Update German holiday date in test case for buß/bettag to correct date * German unity day in 1990 changed * phpstan * Adding DE-BY: Joseftag and DE-BE: Victory in Europe Day --- lang/germany/en/holidays.json | 3 ++- lang/germany/fr/holidays.json | 3 ++- lang/germany/nl/holidays.json | 3 ++- src/Countries/Germany.php | 28 +++++++++++++++++++--------- tests/Countries/GermanyTest.php | 25 ++++++++++++++++++++++++- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/lang/germany/en/holidays.json b/lang/germany/en/holidays.json index 4202f709f..e2431c7e6 100644 --- a/lang/germany/en/holidays.json +++ b/lang/germany/en/holidays.json @@ -17,5 +17,6 @@ "Karfreitag": "Good Friday", "Ostersonntag": "Easter Sunday", "Internationaler Frauentag": "International Women's Day", - "Weltkindertag": "World Children's Day" + "Weltkindertag": "World Children's Day", + "Tag der Befreiung": "Victory in Europe Day" } \ No newline at end of file diff --git a/lang/germany/fr/holidays.json b/lang/germany/fr/holidays.json index e260be7f5..db6056a12 100644 --- a/lang/germany/fr/holidays.json +++ b/lang/germany/fr/holidays.json @@ -17,5 +17,6 @@ "Karfreitag": "Vendredi Saint", "Ostersonntag": "Dimanche de Pâques", "Internationaler Frauentag": "Journée internationale des femmes", - "Weltkindertag": "Journée de l'enfance" + "Weltkindertag": "Journée de l'enfance", + "Tag der Befreiung": "Fête de la Victoire" } \ No newline at end of file diff --git a/lang/germany/nl/holidays.json b/lang/germany/nl/holidays.json index 98f8a17cb..3ef5bc24e 100644 --- a/lang/germany/nl/holidays.json +++ b/lang/germany/nl/holidays.json @@ -17,5 +17,6 @@ "Karfreitag": "Goede Vrijdag", "Ostersonntag": "Eerste paasdag", "Internationaler Frauentag": "Internationale vrouwendag", - "Weltkindertag": "Kinderdag" + "Weltkindertag": "Kinderdag", + "Tag der Befreiung": "Bevrijdingsdag" } \ No newline at end of file diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php index 6bdc0da33..e0b61f282 100644 --- a/src/Countries/Germany.php +++ b/src/Countries/Germany.php @@ -27,6 +27,11 @@ private function getRepentanceAndPrayerDay(int $year): string protected function historicalHolidays(int $year): array { $historicalHolidays = []; + if ($year >= 1954 && $year <= 1990) { + $historicalHolidays['Tag der deutschen Einheit'] = '06-17'; + } else { + $historicalHolidays['Tag der deutschen Einheit'] = '10-03'; + } if ($year >= 1990 && $year <= 1994) { $historicalHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year); } @@ -43,7 +48,6 @@ protected function allHolidays(int $year): array return array_merge([ 'Neujahr' => '01-01', - 'Tag der deutschen Einheit' => '10-03', 'Tag der Arbeit' => '05-01', '1. Weihnachtstag' => '12-25', '2. Weihnachtstag' => '12-26', @@ -77,23 +81,29 @@ protected function regionHolidays(int $year): array 'Allerheiligen' => '11-01', ]; case 'DE-BY': - return [ + $byHolidays = [ 'Heilige Drei Könige' => '01-06', 'Fronleichnam' => $easter->addDays(60), 'Allerheiligen' => '11-01', 'Mariä Himmelfahrt' => '08-15', ]; + if ($year >= 1948 && $year <= 1969) { + $byHolidays['Josefstag'] = '03-19'; + } + + return $byHolidays; case 'DE-BE': + $beHolidays = [ + ]; if ($year >= 2019) { - return [ - 'Internationaler Frauentag' => '03-08', - ]; - } else { - return [ - - ]; + $beHolidays['Internationaler Frauentag'] = '03-08'; + } + if ($year === 2020) { + $beHolidays['Tag der Befreiung'] = '05-08'; } + + return $beHolidays; case 'DE-BB': if ($year >= 1991) { return [ diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index 24f2aa199..a1e77616e 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -18,7 +18,22 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); +it('can calculate german historical unity day in year 1990', function () { + CarbonImmutable::setTestNow('1990-01-01'); + + $holiday = Holidays::for('de')->isHoliday('1990-06-17'); + + expect($holiday)->toBeTrue(); + +}); +it('can calculate german unity day in year 1990', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holiday = Holidays::for('de')->isHoliday('2024-10-03'); + expect($holiday)->toBeTrue(); + +}); it('can calculate german historical reformationstag in year 2017', function () { CarbonImmutable::setTestNow('2017-01-01'); @@ -39,7 +54,15 @@ it('can calculate german buß- und bettag in year 1990', function () { CarbonImmutable::setTestNow('1990-01-01'); - $holiday = Holidays::for('de')->isHoliday('1990-10-03'); + $holiday = Holidays::for('de')->isHoliday('1990-11-21'); + + expect($holiday)->toBeTrue(); + +}); +it('can calculate german berlin holiday Victory in Europe Day in year 2020', function () { + CarbonImmutable::setTestNow('2020-01-01'); + + $holiday = Holidays::for(Germany::make('DE-BE'))->isHoliday('2020-05-08'); expect($holiday)->toBeTrue(); From 17c78494a6114ec5b2a1ab671838836fb1fd5d4c Mon Sep 17 00:00:00 2001 From: Biswajit Biswas Date: Tue, 30 Jan 2024 14:41:11 +0600 Subject: [PATCH 79/99] feat: Add Bangla language support for Bangladeshi holidays (#182) * feat: Add Bangla language support for Bangladeshi holidays * fix: Return Bengali Names in English by default insted Bangla font * fix: Unit testing --- lang/bangladesh/bn/holidays.json | 10 ++++++ lang/bangladesh/en/holidays.json | 10 ++++++ ...lculate_bangladesh_holidays_in_Bangla.snap | 34 +++++++++++++++++++ ...culate_bangladesh_holidays_in_English.snap | 34 +++++++++++++++++++ tests/Countries/BangladeshTest.php | 24 +++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 lang/bangladesh/bn/holidays.json create mode 100644 lang/bangladesh/en/holidays.json create mode 100644 tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap create mode 100644 tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap diff --git a/lang/bangladesh/bn/holidays.json b/lang/bangladesh/bn/holidays.json new file mode 100644 index 000000000..069f2d940 --- /dev/null +++ b/lang/bangladesh/bn/holidays.json @@ -0,0 +1,10 @@ +{ + "International Mother Language Day": "Antorjatik Matribhasha Dibos", + "Birthday of Sheikh Mujibur Rahman": "Shekh Mujibur Rahmaner Jonmodin", + "Independence Day": "Swadhinota Dibos", + "Bengali New Year": "Bangla Noboborsho", + "May Day": "Antorjatik Shrom Dibos", + "National Mourning Day": "Jatiyo Shok Dibos", + "Victory Day": "Bijoy Dibos", + "Christmas Day": "Borodin" +} diff --git a/lang/bangladesh/en/holidays.json b/lang/bangladesh/en/holidays.json new file mode 100644 index 000000000..456af3986 --- /dev/null +++ b/lang/bangladesh/en/holidays.json @@ -0,0 +1,10 @@ +{ + "International Mother Language Day": "International Mother Language Day", + "Birthday of Sheikh Mujibur Rahman": "Birthday of Sheikh Mujibur Rahman", + "Independence Day": "Independence Day", + "Bengali New Year": "Bengali New Year", + "May Day": "May Day", + "National Mourning Day": "National Mourning Day", + "Victory Day": "Victory Day", + "Christmas Day": "Christmas Day" +} diff --git a/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap new file mode 100644 index 000000000..285dbbc3c --- /dev/null +++ b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap @@ -0,0 +1,34 @@ +[ + { + "name": "Antorjatik Matribhasha Dibos", + "date": "2024-02-21" + }, + { + "name": "Shekh Mujibur Rahmaner Jonmodin", + "date": "2024-03-17" + }, + { + "name": "Swadhinota Dibos", + "date": "2024-03-26" + }, + { + "name": "Bangla Noboborsho", + "date": "2024-04-14" + }, + { + "name": "Antorjatik Shrom Dibos", + "date": "2024-05-01" + }, + { + "name": "Jatiyo Shok Dibos", + "date": "2024-08-15" + }, + { + "name": "Bijoy Dibos", + "date": "2024-12-16" + }, + { + "name": "Borodin", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap new file mode 100644 index 000000000..f5a0e91db --- /dev/null +++ b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap @@ -0,0 +1,34 @@ +[ + { + "name": "International Mother Language Day", + "date": "2024-02-21" + }, + { + "name": "Birthday of Sheikh Mujibur Rahman", + "date": "2024-03-17" + }, + { + "name": "Independence Day", + "date": "2024-03-26" + }, + { + "name": "Bengali New Year", + "date": "2024-04-14" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "National Mourning Day", + "date": "2024-08-15" + }, + { + "name": "Victory Day", + "date": "2024-12-16" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BangladeshTest.php b/tests/Countries/BangladeshTest.php index d978a795d..51f7e40f5 100644 --- a/tests/Countries/BangladeshTest.php +++ b/tests/Countries/BangladeshTest.php @@ -16,3 +16,27 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('can calculate bangladesh holidays in English', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'bd', locale: 'en')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate bangladesh holidays in Bangla', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'bd', locale: 'bn')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 363585142b25a5eb3356ed9b0f81a6a3c5549ada Mon Sep 17 00:00:00 2001 From: AditiAld Date: Tue, 30 Jan 2024 15:58:57 +0700 Subject: [PATCH 80/99] add indonesia holiday (#66) * add indonesia holiday * (fix): remove docblock * fix(test): variable holidays * fix(docblock): variableHolidays docblock * refactor(variableHolidays): get easter date from the parent class * fix(variableHolidays): easter date * feat(holiday): add chinese new year holiday to indonesia * fix(IndonesiaTest) --- src/Countries/Indonesia.php | 40 +++++++++++++++++++ .../it_can_calculate_indonesia_holidays.snap | 38 ++++++++++++++++++ tests/Countries/IndonesiaTest.php | 18 +++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/Countries/Indonesia.php create mode 100644 tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap create mode 100644 tests/Countries/IndonesiaTest.php diff --git a/src/Countries/Indonesia.php b/src/Countries/Indonesia.php new file mode 100644 index 000000000..ef19d1d17 --- /dev/null +++ b/src/Countries/Indonesia.php @@ -0,0 +1,40 @@ + '01-01', + 'Hari Buruh Internasional' => '05-01', + 'Hari Lahir Pancasila' => '06-01', + 'Hari Kemerdekaan' => '08-17', + 'Hari Raya Natal' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Tahun Baru Imlek' => $this->chineseToGregorianDate('01-01', $year), + 'Jumat Agung' => $easter->subDays(2), + 'Hari Paskah' => $easter, + 'Kenaikan Yesus Kristus' => $easter->addDays(39), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap b/tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap new file mode 100644 index 000000000..f8c9dd8c1 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "Tahun Baru", + "date": "2024-01-01" + }, + { + "name": "Tahun Baru Imlek", + "date": "2024-02-10" + }, + { + "name": "Jumat Agung", + "date": "2024-03-29" + }, + { + "name": "Hari Paskah", + "date": "2024-03-31" + }, + { + "name": "Hari Buruh Internasional", + "date": "2024-05-01" + }, + { + "name": "Kenaikan Yesus Kristus", + "date": "2024-05-09" + }, + { + "name": "Hari Lahir Pancasila", + "date": "2024-06-01" + }, + { + "name": "Hari Kemerdekaan", + "date": "2024-08-17" + }, + { + "name": "Hari Raya Natal", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/IndonesiaTest.php b/tests/Countries/IndonesiaTest.php new file mode 100644 index 000000000..9cc85dcc7 --- /dev/null +++ b/tests/Countries/IndonesiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 6c3395e7f4f9b25b22afbcab3e8583fe75fdec0b Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Tue, 30 Jan 2024 08:59:54 +0000 Subject: [PATCH 81/99] Update CHANGELOG --- CHANGELOG.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 326828cd5..192aa09a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,42 @@ All notable changes to `holidays` will be documented in this file. +## 1.4.0 - 2024-01-30 + +### What's Changed + +* Add Montenegro holidays by @Rkishahaha in https://github.com/spatie/holidays/pull/171 +* Add Angola Holidays by @monteirofutila in https://github.com/spatie/holidays/pull/89 +* add wales, england, scotland and northern ireland by @SimonBarrettACT in https://github.com/spatie/holidays/pull/162 +* Add Chile Holidays by @AndresReyesDev in https://github.com/spatie/holidays/pull/88 +* Added Kenyan holidays by @PhilN8 in https://github.com/spatie/holidays/pull/69 +* Add vietnamese holidays by @kevinb1989 in https://github.com/spatie/holidays/pull/115 +* Germany: Adding local for EN, FR, NL by @arnebr in https://github.com/spatie/holidays/pull/183 +* Support for Taiwan holidays by @takeshiyu in https://github.com/spatie/holidays/pull/124 +* Fixing README.md to update region parameter in country constructor to a working example by @arnebr in https://github.com/spatie/holidays/pull/184 +* Draft: Add Support for Switzerland by @Martin-Welte in https://github.com/spatie/holidays/pull/49 +* Add Tanzania national holiday by @alphaolomi in https://github.com/spatie/holidays/pull/98 +* Switzerland: add missing holidays to "ch-ur" region by @Kenny1291 in https://github.com/spatie/holidays/pull/191 +* Germany: Setting some historical holidays by @arnebr in https://github.com/spatie/holidays/pull/188 +* feat: Add Bangla language support for Bangladeshi holidays by @jfBiswajit in https://github.com/spatie/holidays/pull/182 +* add indonesia holiday by @ddouble-d in https://github.com/spatie/holidays/pull/66 + +### New Contributors + +* @Rkishahaha made their first contribution in https://github.com/spatie/holidays/pull/171 +* @monteirofutila made their first contribution in https://github.com/spatie/holidays/pull/89 +* @SimonBarrettACT made their first contribution in https://github.com/spatie/holidays/pull/162 +* @AndresReyesDev made their first contribution in https://github.com/spatie/holidays/pull/88 +* @PhilN8 made their first contribution in https://github.com/spatie/holidays/pull/69 +* @kevinb1989 made their first contribution in https://github.com/spatie/holidays/pull/115 +* @takeshiyu made their first contribution in https://github.com/spatie/holidays/pull/124 +* @alphaolomi made their first contribution in https://github.com/spatie/holidays/pull/98 +* @Kenny1291 made their first contribution in https://github.com/spatie/holidays/pull/191 +* @jfBiswajit made their first contribution in https://github.com/spatie/holidays/pull/182 +* @ddouble-d made their first contribution in https://github.com/spatie/holidays/pull/66 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.3.0...1.4.0 + ## 1.3.0 - 2024-01-25 ### What's Changed From 6fde494086a7624a09e42fa83639674c8d6e98cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=B8ndergaard?= Date: Tue, 30 Jan 2024 16:14:14 +0100 Subject: [PATCH 82/99] Fix easter sunday and monday (#197) --- src/Countries/Denmark.php | 4 ++-- .../DenmarkTest/it_can_calculate_danish_holidays.snap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index ee68d1d74..3d4e091eb 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -27,10 +27,10 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); $holidays = [ - 'Påskedag' => $easter->addDay(), 'Skærtorsdag' => $easter->subDays(3), 'Langfredag' => $easter->subDays(2), - 'Anden Påskedag' => $easter->addDays(2), + 'Påskedag' => $easter, + 'Anden Påskedag' => $easter->addDay(), 'Kristi Himmelfartsdag' => $easter->addDays(39), 'Pinse' => $easter->addDays(49), 'Anden Pinsedag' => $easter->addDays(50), diff --git a/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap index b19f23c2d..705cd12ee 100644 --- a/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap +++ b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap @@ -13,11 +13,11 @@ }, { "name": "P\u00e5skedag", - "date": "2024-04-01" + "date": "2024-03-31" }, { "name": "Anden P\u00e5skedag", - "date": "2024-04-02" + "date": "2024-04-01" }, { "name": "Kristi Himmelfartsdag", From feda8ec11b9a960748512d8dc7524da8bb455de5 Mon Sep 17 00:00:00 2001 From: MirilTerolli Date: Wed, 31 Jan 2024 14:31:59 -0500 Subject: [PATCH 83/99] Albanian National Holidays (#157) * Albanian National Holidays - Add Albanian national holidays including tentative dates for islamic holidays that are TBD. - Test coverage. * Albanian National Holidays - Add test coverage for holidays with standard dates. * Enhancements - Add empty line in the end of the testing file. * Enhancements - Fix empty line warning in the end of the file. * Fixes - Fix php stan error. * Fix holiday TYPO. * Language support - Translation for German, English, Spanish, French, Greek, Italian, Portughese, Russian, Turkish. * Filter out some variable holidays when they are not set for the given year. --------- Co-authored-by: Miril Terolli --- src/Countries/Albania.php | 88 +++++++++++++ src/lang/albania/de/holidays.json | 15 +++ src/lang/albania/en/holidays.json | 15 +++ src/lang/albania/es/holidays.json | 15 +++ src/lang/albania/fr/holidays.json | 16 +++ src/lang/albania/gr/holidays.json | 15 +++ src/lang/albania/it/holidays.json | 15 +++ src/lang/albania/pt/holidays.json | 15 +++ src/lang/albania/ru/holidays.json | 15 +++ src/lang/albania/tr/holidays.json | 15 +++ .../it_can_calculate_albanian_holidays.snap | 54 ++++++++ tests/Countries/AlbaniaTest.php | 123 ++++++++++++++++++ 12 files changed, 401 insertions(+) create mode 100644 src/Countries/Albania.php create mode 100644 src/lang/albania/de/holidays.json create mode 100644 src/lang/albania/en/holidays.json create mode 100644 src/lang/albania/es/holidays.json create mode 100644 src/lang/albania/fr/holidays.json create mode 100644 src/lang/albania/gr/holidays.json create mode 100644 src/lang/albania/it/holidays.json create mode 100644 src/lang/albania/pt/holidays.json create mode 100644 src/lang/albania/ru/holidays.json create mode 100644 src/lang/albania/tr/holidays.json create mode 100644 tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap create mode 100644 tests/Countries/AlbaniaTest.php diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php new file mode 100644 index 000000000..42ad87619 --- /dev/null +++ b/src/Countries/Albania.php @@ -0,0 +1,88 @@ + '01-01', + 'Dita e Verës' => '03-14', + 'Dita e Sulltan Nevruzit' => '03-22', + 'Dita Ndërkombëtare e Punëtorëve' => '05-01', + 'Dita e Shenjtërimit të Shenjt Terezës' => '09-05', + 'Dita e Pavarësisë' => '11-28', + 'Dita e Çlirimit' => '11-29', + 'Dita Kombëtare e Rinisë' => '12-08', + 'Krishtlindja' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + return array_filter([ + 'E diela e Pashkëve Katolike' => $this->easter($year), + 'E diela e Pashkëve Ortodokse' => $this->orthodoxEaster($year), + 'Dita e Bajramit të Madh' => $this->getEidAlFitrHoliday($year), + 'Dita e Kurban Bajramit' => $this->getEidAlAdhaHoliday($year), + ]); + } + + /** + * + */ + private function getEidAlFitrHoliday(int $year): ?string + { + /** + * Provided until 2034 by qppstudio.net. + * https://www.qppstudio.net/global-holidays-observances/eid-al-fitr-end-of-ramadan.htm + */ + return match ($year) { + 2024 => '04-10', + 2025 => '03-30', + 2026 => '03-20', + 2027 => '03-09', + 2028 => '02-26', + 2029 => '02-14', + 2030 => '02-04', + 2031 => '01-24', + 2032 => '01-14', + 2033 => '01-02', + 2034 => '12-12', + default => null // Holiday is variable; requires ongoing maintenance. + }; + } + + private function getEidAlAdhaHoliday(int $year): ?string + { + /** + * Tentative dates. + * Provided until 2034 by timeanddate.com. + * https://www.timeanddate.com/holidays/us/eid-al-adha + */ + return match ($year) { + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-01', + default => null // Holiday is variable; requires ongoing maintenance. + }; + } + +} diff --git a/src/lang/albania/de/holidays.json b/src/lang/albania/de/holidays.json new file mode 100644 index 000000000..ec5d24885 --- /dev/null +++ b/src/lang/albania/de/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Neujahr", + "Dita e Verës": "Sommertag", + "Dita e Sulltan Nevruzit": "Tag des Sultan Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Tag der Arbeit", + "Dita e Shenjtërimit të Shenjt Terezës": "Tag der Heiligsprechung der Heiligen Teresa", + "Dita e Pavarësisë": "Unabhängigkeitstag", + "Dita e Çlirimit": "Befreiungstag", + "Dita Kombëtare e Rinisë": "Nationaler Jugendtag", + "Krishtlindja": "Weihnachten", + "E diela e Pashkëve Katolike": "Katholischer Ostersonntag", + "E diela e Pashkëve Ortodokse": "Orthodoxer Ostersonntag", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/en/holidays.json b/src/lang/albania/en/holidays.json new file mode 100644 index 000000000..df15b5c2f --- /dev/null +++ b/src/lang/albania/en/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "New Year's Day", + "Dita e Verës": "Summer Day", + "Dita e Sulltan Nevruzit": "Sultan Nevruz Day", + "Dita Ndërkombëtare e Punëtorëve": "International Workers' Day", + "Dita e Shenjtërimit të Shenjt Terezës": "Saint Teresa Canonization Day", + "Dita e Pavarësisë": "Independence Day", + "Dita e Çlirimit": "Liberation Day", + "Dita Kombëtare e Rinisë": "National Youth Day", + "Krishtlindja": "Christmas", + "E diela e Pashkëve Katolike": "Catholic Easter Sunday", + "E diela e Pashkëve Ortodokse": "Orthodox Easter Sunday", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/es/holidays.json b/src/lang/albania/es/holidays.json new file mode 100644 index 000000000..713b70def --- /dev/null +++ b/src/lang/albania/es/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Año Nuevo", + "Dita e Verës": "Día del Verano", + "Dita e Sulltan Nevruzit": "Día del Sultan Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Día Internacional de los Trabajadores", + "Dita e Shenjtërimit të Shenjt Terezës": "Día de la Canonización de Santa Teresa", + "Dita e Pavarësisë": "Día de la Independencia", + "Dita e Çlirimit": "Día de la Liberación", + "Dita Kombëtare e Rinisë": "Día Nacional de la Juventud", + "Krishtlindja": "Navidad", + "E diela e Pashkëve Katolike": "Domingo de Pascua Católica", + "E diela e Pashkëve Ortodokse": "Domingo de Pascua Ortodoxa", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/fr/holidays.json b/src/lang/albania/fr/holidays.json new file mode 100644 index 000000000..e2a7f2f05 --- /dev/null +++ b/src/lang/albania/fr/holidays.json @@ -0,0 +1,16 @@ +{ + "Viti i Ri": "Jour de l'An", + "Dita e Verës": "Jour de l'Été", + "Dita e Sulltan Nevruzit": "Jour du Sultan Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Fête du Travail", + "Dita e Shenjtërimit të Shenjt Terezës": "Jour de la Canonisation de Sainte Teresa", + "Dita e Pavarësisë": "Jour de l'Indépendance", + "Dita e Çlirimit": "Jour de la Libération", + "Dita Kombëtare e Rinisë": "Journée nationale de la jeunesse", + "Krishtlindja": "Noël", + "E diela e Pashkëve Katolike": "Dimanche de Pâques catholique", + "E diela e Pashkëve Ortodokse": "Dimanche de Pâques orthodoxe", + "Dita e Bajramit të Madh": "Aïd al-Fitr", + "Dita e Kurban Bajramit": "Aïd al-Adha" +} + diff --git a/src/lang/albania/gr/holidays.json b/src/lang/albania/gr/holidays.json new file mode 100644 index 000000000..a2e5d28e5 --- /dev/null +++ b/src/lang/albania/gr/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Πρωτοχρονιά (Protochroniá)", + "Dita e Verës": "Ημέρα του Καλοκαιριού (Iméra tou Kalokairioú)", + "Dita e Sulltan Nevruzit": "Ημέρα του Σουλτάν Nevruz (Iméra tou Soúltan Nevruz)", + "Dita Ndërkombëtare e Punëtorëve": "Διεθνής Ημέρα των Εργαζομένων (Diethnís Iméra ton Ergazoménon)", + "Dita e Shenjtërimit të Shenjt Terezës": "Ημέρα Κανονισμού της Αγίας Τερέζας (Iméra Kanonismoú tis Agías Terézas)", + "Dita e Pavarësisë": "Ημέρα Ανεξαρτησίας (Iméra Anexartisías)", + "Dita e Çlirimit": "Ημέρα Απελευθέρωσης (Iméra Apelafthéroses)", + "Dita Kombëtare e Rinisë": "Εθνική Ημέρα της Νεολαίας (Ethnikí Iméra tis Neoléas)", + "Krishtlindja": "Χριστούγεννα (Christoúgenna)", + "E diela e Pashkëve Katolike": "Κυριακή του Καθολικού Πάσχα (Kyriakí tou Katholikoú Páscha)", + "E diela e Pashkëve Ortodokse": "Κυριακή του Ορθόδοξου Πάσχα (Kyriakí tou Orthódoksi Páscha)", + "Dita e Bajramit të Madh": "Ημέρα του Μεγάλου Βαϊράμ (Iméra tou Megálou Vaïrám)", + "Dita e Kurban Bajramit": "Ημέρα του Κουρμπάν Βαϊράμ (Iméra tou Kourbán Vaïrám)" +} diff --git a/src/lang/albania/it/holidays.json b/src/lang/albania/it/holidays.json new file mode 100644 index 000000000..4e192da2a --- /dev/null +++ b/src/lang/albania/it/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Capodanno", + "Dita e Verës": "Giorno d'Estate", + "Dita e Sulltan Nevruzit": "Giorno del Sultano Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Festa dei Lavoratori", + "Dita e Shenjtërimit të Shenjt Terezës": "Giorno della Canonizzazione di Santa Teresa", + "Dita e Pavarësisë": "Giorno dell'Indipendenza", + "Dita e Çlirimit": "Giorno della Liberazione", + "Dita Kombëtare e Rinisë": "Giornata Nazionale della Gioventù", + "Krishtlindja": "Natale", + "E diela e Pashkëve Katolike": "Domenica di Pasqua Cattolica", + "E diela e Pashkëve Ortodokse": "Domenica di Pasqua Ortodossa", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/pt/holidays.json b/src/lang/albania/pt/holidays.json new file mode 100644 index 000000000..dc3fce2f3 --- /dev/null +++ b/src/lang/albania/pt/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Ano Novo", + "Dita e Verës": "Dia do Verão", + "Dita e Sulltan Nevruzit": "Dia do Sultão Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Dia Internacional dos Trabalhadores", + "Dita e Shenjtërimit të Shenjt Terezës": "Dia da Canonização de Santa Teresa", + "Dita e Pavarësisë": "Dia da Independência", + "Dita e Çlirimit": "Dia da Libertação", + "Dita Kombëtare e Rinisë": "Dia Nacional da Juventude", + "Krishtlindja": "Natal", + "E diela e Pashkëve Katolike": "Domingo de Páscoa Católico", + "E diela e Pashkëve Ortodokse": "Domingo de Páscoa Ortodoxo", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/ru/holidays.json b/src/lang/albania/ru/holidays.json new file mode 100644 index 000000000..2eb3f356d --- /dev/null +++ b/src/lang/albania/ru/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Новий рік", + "Dita e Verës": "День літа", + "Dita e Sulltan Nevruzit": "День Султана Невруза", + "Dita Ndërkombëtare e Punëtorëve": "Міжнародний день праці", + "Dita e Shenjtërimit të Shenjt Terezës": "День канонізації Святої Терези", + "Dita e Pavarësisë": "День Незалежності", + "Dita e Çlirimit": "День Визволення", + "Dita Kombëtare e Rinisë": "Національний день молоді", + "Krishtlindja": "Різдво", + "E diela e Pashkëve Katolike": "Католицька неділя Великодня", + "E diela e Pashkëve Ortodokse": "Православна неділя Великодня", + "Dita e Bajramit të Madh": "Байрам", + "Dita e Kurban Bajramit": "Курбан-байрам" +} diff --git a/src/lang/albania/tr/holidays.json b/src/lang/albania/tr/holidays.json new file mode 100644 index 000000000..ede076e01 --- /dev/null +++ b/src/lang/albania/tr/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Yılbaşı", + "Dita e Verës": "Yaz Günü", + "Dita e Sulltan Nevruzit": "Sultan Nevruz Günü", + "Dita Ndërkombëtare e Punëtorëve": "Uluslararası İşçi Günü", + "Dita e Shenjtërimit të Shenjt Terezës": "Azize Teresa'nın Kanonizasyon Günü", + "Dita e Pavarësisë": "Bağımsızlık Günü", + "Dita e Çlirimit": "Kurtuluş Günü", + "Dita Kombëtare e Rinisë": "Ulusal Gençlik Günü", + "Krishtlindja": "Noel", + "E diela e Pashkëve Katolike": "Katolik Paskalya Pazarı", + "E diela e Pashkëve Ortodokse": "Ortodoks Paskalya Pazarı", + "Dita e Bajramit të Madh": "Ramazan Bayramı", + "Dita e Kurban Bajramit": "Kurban Bayramı" +} diff --git a/tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap b/tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap new file mode 100644 index 000000000..49c936114 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Viti i Ri", + "date": "2024-01-01" + }, + { + "name": "Dita e Ver\u00ebs", + "date": "2024-03-14" + }, + { + "name": "Dita e Sulltan Nevruzit", + "date": "2024-03-22" + }, + { + "name": "E diela e Pashk\u00ebve Katolike", + "date": "2024-03-31" + }, + { + "name": "Dita e Bajramit t\u00eb Madh", + "date": "2024-04-10" + }, + { + "name": "Dita Nd\u00ebrkomb\u00ebtare e Pun\u00ebtor\u00ebve", + "date": "2024-05-01" + }, + { + "name": "E diela e Pashk\u00ebve Ortodokse", + "date": "2024-05-05" + }, + { + "name": "Dita e Kurban Bajramit", + "date": "2024-06-17" + }, + { + "name": "Dita e Shenjt\u00ebrimit t\u00eb Shenjt Terez\u00ebs", + "date": "2024-09-05" + }, + { + "name": "Dita e Pavar\u00ebsis\u00eb", + "date": "2024-11-28" + }, + { + "name": "Dita e \u00c7lirimit", + "date": "2024-11-29" + }, + { + "name": "Dita Komb\u00ebtare e Rinis\u00eb", + "date": "2024-12-08" + }, + { + "name": "Krishtlindja", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php new file mode 100644 index 000000000..e068877b7 --- /dev/null +++ b/tests/Countries/AlbaniaTest.php @@ -0,0 +1,123 @@ +get(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + + +it('does not return a holiday falsely', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); + $holiday = Holidays::for(country: 'al'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeFalse(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBeNull(); +}); + +describe('national holidays with standard dates', function() { + $holiday = Holidays::for(country: 'al'); + + it('can calculate the `Viti i Ri` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-01-01'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Viti i Ri'); + }); + + it('can calculate the `Dita e Verës` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-03-14'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Verës'); + }); + + it('can calculate the `Dita e Sulltan Nevruzit` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-03-22'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Sulltan Nevruzit'); + }); + + it('can calculate the `Dita Ndërkombëtare e Punëtorëve` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-05-01'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita Ndërkombëtare e Punëtorëve'); + }); + + it('can calculate the `Dita e Shenjtërimit të Shenjt Terezës` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-09-05'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Shenjtërimit të Shenjt Terezës'); + }); + + it('can calculate the `Dita e Pavarësisë` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-11-28'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Pavarësisë'); + }); + + it('can calculate the `Dita e Çlirimit` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-11-29'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Çlirimit'); + }); + + it('can calculate the `Dita Kombëtare e Rinisë` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-12-08'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita Kombëtare e Rinisë'); + }); + + it('can calculate the `Krishtlindja` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-12-25'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Krishtlindja'); + }); + }); From 5d5ad2485b4b8c5ce058e40b074be1169e833cdd Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 19:32:20 +0000 Subject: [PATCH 84/99] Fix styling --- src/Countries/Albania.php | 4 -- tests/Countries/AlbaniaTest.php | 79 ++++++++++++++++----------------- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php index 42ad87619..2d7424dbf 100644 --- a/src/Countries/Albania.php +++ b/src/Countries/Albania.php @@ -37,9 +37,6 @@ protected function variableHolidays(int $year): array ]); } - /** - * - */ private function getEidAlFitrHoliday(int $year): ?string { /** @@ -84,5 +81,4 @@ private function getEidAlAdhaHoliday(int $year): ?string default => null // Holiday is variable; requires ongoing maintenance. }; } - } diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php index e068877b7..461e5e126 100644 --- a/tests/Countries/AlbaniaTest.php +++ b/tests/Countries/AlbaniaTest.php @@ -16,108 +16,107 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - -it('does not return a holiday falsely', function() use ($holiday) { +it('does not return a holiday falsely', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); $holiday = Holidays::for(country: 'al'); $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeFalse(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBeNull(); }); -describe('national holidays with standard dates', function() { +describe('national holidays with standard dates', function () { $holiday = Holidays::for(country: 'al'); - it('can calculate the `Viti i Ri` holiday as expected', function() use ($holiday) { + it('can calculate the `Viti i Ri` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-01-01'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Viti i Ri'); }); - - it('can calculate the `Dita e Verës` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Verës` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-03-14'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Verës'); }); - - it('can calculate the `Dita e Sulltan Nevruzit` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Sulltan Nevruzit` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-03-22'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Sulltan Nevruzit'); }); - - it('can calculate the `Dita Ndërkombëtare e Punëtorëve` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita Ndërkombëtare e Punëtorëve` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-05-01'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita Ndërkombëtare e Punëtorëve'); }); - - it('can calculate the `Dita e Shenjtërimit të Shenjt Terezës` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Shenjtërimit të Shenjt Terezës` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-09-05'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Shenjtërimit të Shenjt Terezës'); }); - - it('can calculate the `Dita e Pavarësisë` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Pavarësisë` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-11-28'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Pavarësisë'); }); - - it('can calculate the `Dita e Çlirimit` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Çlirimit` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-11-29'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Çlirimit'); }); - - it('can calculate the `Dita Kombëtare e Rinisë` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita Kombëtare e Rinisë` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-12-08'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita Kombëtare e Rinisë'); }); - - it('can calculate the `Krishtlindja` holiday as expected', function() use ($holiday) { + + it('can calculate the `Krishtlindja` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-12-25'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Krishtlindja'); }); - }); +}); From b21b11d90dcc0e1781b5aa537e1d6549e78c0418 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:36:16 +0100 Subject: [PATCH 85/99] cleanup Albania --- src/Countries/Albania.php | 9 +++++---- src/Exceptions/InvalidYear.php | 5 +++++ tests/Countries/AlbaniaTest.php | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php index 2d7424dbf..dd0e05d32 100644 --- a/src/Countries/Albania.php +++ b/src/Countries/Albania.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Exceptions\InvalidYear; class Albania extends Country { @@ -37,7 +38,7 @@ protected function variableHolidays(int $year): array ]); } - private function getEidAlFitrHoliday(int $year): ?string + private function getEidAlFitrHoliday(int $year): string { /** * Provided until 2034 by qppstudio.net. @@ -55,11 +56,11 @@ private function getEidAlFitrHoliday(int $year): ?string 2032 => '01-14', 2033 => '01-02', 2034 => '12-12', - default => null // Holiday is variable; requires ongoing maintenance. + default => throw InvalidYear::range('Albania', 2024, 2034), }; } - private function getEidAlAdhaHoliday(int $year): ?string + private function getEidAlAdhaHoliday(int $year): string { /** * Tentative dates. @@ -78,7 +79,7 @@ private function getEidAlAdhaHoliday(int $year): ?string 2032 => '03-22', 2033 => '03-12', 2034 => '03-01', - default => null // Holiday is variable; requires ongoing maintenance. + default => throw InvalidYear::range('Albania', 2024, 2034), }; } } diff --git a/src/Exceptions/InvalidYear.php b/src/Exceptions/InvalidYear.php index bea3dcbb1..0eac2b9e1 100644 --- a/src/Exceptions/InvalidYear.php +++ b/src/Exceptions/InvalidYear.php @@ -15,4 +15,9 @@ public static function yearTooHigh(): self { return new self('Holidays can only be calculated for years before 2038.'); } + + public static function range(string $country, int $start, int $end): self + { + return new self("Only years between {$start} and {$end} are supported for {$country}."); + } } diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php index 461e5e126..0cc1bf411 100644 --- a/tests/Countries/AlbaniaTest.php +++ b/tests/Countries/AlbaniaTest.php @@ -16,7 +16,7 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); -it('does not return a holiday falsely', function () use ($holiday) { +it('does not return a holiday falsely', function () { $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); $holiday = Holidays::for(country: 'al'); From b57af78f87c25e05f0665943eb9c878a82f55b2f Mon Sep 17 00:00:00 2001 From: Orane Edwards Date: Wed, 31 Jan 2024 14:42:17 -0500 Subject: [PATCH 86/99] Add holidays for Jamaica (#185) * Add Jamaican holidays * Add observed holidays for Jamaica. * Php Stan flagged error. Changed how date is created. * Remove unnecessary test for Ash Wednesday. * Remove timezone specification. --- src/Countries/Jamaica.php | 84 +++++++++++++++++++ .../it_can_calculate_jamaican_holidays.snap | 42 ++++++++++ tests/Countries/JamaicaTest.php | 34 ++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/Countries/Jamaica.php create mode 100644 tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap create mode 100644 tests/Countries/JamaicaTest.php diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php new file mode 100644 index 000000000..a6c955580 --- /dev/null +++ b/src/Countries/Jamaica.php @@ -0,0 +1,84 @@ +fixedHolidays(), + $this->variableHolidays($year), + $this->observedHolidays($year) + ); + + return $holidays; + } + + /** @return array */ + protected function fixedHolidays(): array + { + $holidays = [ + 'New Year\'s Day' => '01-01', + 'Labour Day' => '05-23', + 'Emancipation Day' => '08-01', + 'Independence Day' => '08-06', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; + + return $holidays; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + $heroesDay = new CarbonImmutable("third monday of October $year"); + + return [ + 'Ash Wednesday' => $easter->subDays(46), + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + 'National Heroes Day' => $heroesDay, + ]; + } + + /** @return array */ + protected function observedHolidays(int $year): array + { + + $observedHolidays = []; + + foreach ($this->fixedHolidays() as $name => $date) { + $date = CarbonImmutable::parse("$year-$date"); + + // If any holiday falls on a Sunday, then it is observed on Monday + if($date->dayOfWeek === 0) { + $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); + } + + // If Labour Day falls on a Saturday, then it is observed on Monday + if($name == 'Labour Day' && $date->dayOfWeek === 6) { + $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); + } + + // If Boxing Day falls on a Monday, then it is observed on Tuesday (Christmas Day is observed on Monday) + // https://jis.gov.jm/observance-public-holidays-christmas-day-monday-december-26th-boxing-day-tuesday-december-27th/ + if ($name == 'Boxing Day' && $date->dayOfWeek === 1) { + $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::TUESDAY); + } + } + + return $observedHolidays; + } +} diff --git a/tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap b/tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap new file mode 100644 index 000000000..3d71e806c --- /dev/null +++ b/tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Ash Wednesday", + "date": "2024-02-14" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour Day", + "date": "2024-05-23" + }, + { + "name": "Emancipation Day", + "date": "2024-08-01" + }, + { + "name": "Independence Day", + "date": "2024-08-06" + }, + { + "name": "National Heroes Day", + "date": "2024-10-21" + }, + { + "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/JamaicaTest.php b/tests/Countries/JamaicaTest.php new file mode 100644 index 000000000..1ea7b0237 --- /dev/null +++ b/tests/Countries/JamaicaTest.php @@ -0,0 +1,34 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate observed holidays based on year', function () { + + // Check for Observed New Year's Day + $holidays = Holidays::for(country: 'jm', year: 2023)->get(); + expect(array_search('New Year\'s Day Observed', array_column($holidays, 'name')))->toBeInt(); + + // Check for Observed Labour Day + $holidays = Holidays::for(country: 'jm', year: 2020)->get(); + expect(array_search('Labour Day Observed', array_column($holidays, 'name')))->toBeInt(); + + // Check that there is no Observerd New Year's Day + $holidays = Holidays::for(country: 'jm', year: 2024)->get(); + expect(array_search('Labour Day Observed', array_column($holidays, 'name')))->toBeFalse(); + +}); From 96395a14fe63e3656ba5e5cd86eaa3df3694ad59 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 19:42:38 +0000 Subject: [PATCH 87/99] Fix styling --- src/Countries/Jamaica.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index a6c955580..e9b3af3d4 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use Carbon\CarbonInterface; class Jamaica extends Country { @@ -63,12 +62,12 @@ protected function observedHolidays(int $year): array $date = CarbonImmutable::parse("$year-$date"); // If any holiday falls on a Sunday, then it is observed on Monday - if($date->dayOfWeek === 0) { + if ($date->dayOfWeek === 0) { $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); } // If Labour Day falls on a Saturday, then it is observed on Monday - if($name == 'Labour Day' && $date->dayOfWeek === 6) { + if ($name == 'Labour Day' && $date->dayOfWeek === 6) { $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); } From 60df0844a3dd83923e2d6b483d45012180ecf7c2 Mon Sep 17 00:00:00 2001 From: Peter Sowah Date: Wed, 31 Jan 2024 19:45:26 +0000 Subject: [PATCH 88/99] Add public holidays for Ghana (#175) * add Ghana holidays * add iterable type to variableHolidays method * Update src/Countries/Ghana.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * clean --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- src/Countries/Ghana.php | 39 +++++++++++++++++ ...te_Ghana_date_based_regional_holidays.snap | 42 ++++++++++++++++++ ...te_Ghana_easter_based_region_holidays.snap | 42 ++++++++++++++++++ .../it_can_calculate_Ghana_holidays.snap | 42 ++++++++++++++++++ tests/Countries/GhanaTest.php | 43 +++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 src/Countries/Ghana.php create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap create mode 100644 tests/Countries/GhanaTest.php diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php new file mode 100644 index 000000000..2a32685ca --- /dev/null +++ b/src/Countries/Ghana.php @@ -0,0 +1,39 @@ + '01-01', + 'Constitution Day' => '01-07', + 'Independence Day' => '03-06', + 'May Day' => '05-01', + 'Founder\'s Day' => '08-04', + 'Kwame Nkrumah Memorial Day' => '09-21', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "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/GhanaTest.php b/tests/Countries/GhanaTest.php new file mode 100644 index 000000000..78f05a44b --- /dev/null +++ b/tests/Countries/GhanaTest.php @@ -0,0 +1,43 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate Ghana easter based region holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gh')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate Ghana date based regional holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gh')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 089c5cc271ed359cabd8e7fe7a456fabfa51d15f Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 19:45:46 +0000 Subject: [PATCH 89/99] Fix styling --- src/Countries/Ghana.php | 1 - tests/Countries/GhanaTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 2a32685ca..03342516c 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -6,7 +6,6 @@ class Ghana extends Country { - public function countryCode(): string { return 'gh'; diff --git a/tests/Countries/GhanaTest.php b/tests/Countries/GhanaTest.php index 78f05a44b..3a02ed9d3 100644 --- a/tests/Countries/GhanaTest.php +++ b/tests/Countries/GhanaTest.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Countries\France; use Spatie\Holidays\Holidays; it('can calculate Ghana holidays', function () { From adf73ed2dd5799cc841c90ef5aa013b01d40f357 Mon Sep 17 00:00:00 2001 From: Jure Filipic Date: Wed, 31 Jan 2024 21:01:00 +0100 Subject: [PATCH 90/99] Support for Slovenian langage second PR after rebase problem (#139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jure Filipič --- src/Countries/Slovenia.php | 42 +++++++++++++++ .../it_can_calculate_slovenian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/SloveniaTest.php | 18 +++++++ 3 files changed, 114 insertions(+) create mode 100644 src/Countries/Slovenia.php create mode 100644 tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap create mode 100644 tests/Countries/SloveniaTest.php diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php new file mode 100644 index 000000000..1ed8f5c7d --- /dev/null +++ b/src/Countries/Slovenia.php @@ -0,0 +1,42 @@ + '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 + '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 = $this->easter($year); + + return [ + 'Velikonočni ponedeljek' => $easter->addDay(), // Easter Monday + ]; + } +} 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 000000000..b869f39b7 --- /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-01-02" + }, + { + "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 000000000..d12319061 --- /dev/null +++ b/tests/Countries/SloveniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 30690720a4d7d69d7751d01595bfc032a3dc24dd Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:01:21 +0000 Subject: [PATCH 91/99] Fix styling --- src/Countries/Slovenia.php | 4 ++-- tests/Countries/SloveniaTest.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php index 1ed8f5c7d..4f2171d50 100644 --- a/src/Countries/Slovenia.php +++ b/src/Countries/Slovenia.php @@ -14,7 +14,7 @@ public function countryCode(): string 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 @@ -33,7 +33,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter($year); + $easter = $this->easter($year); return [ 'Velikonočni ponedeljek' => $easter->addDay(), // Easter Monday diff --git a/tests/Countries/SloveniaTest.php b/tests/Countries/SloveniaTest.php index d12319061..0dc846a6e 100644 --- a/tests/Countries/SloveniaTest.php +++ b/tests/Countries/SloveniaTest.php @@ -6,13 +6,13 @@ use Spatie\Holidays\Holidays; it('can calculate slovenian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); - $holidays = Holidays::for(country: 'si')->get(); + $holidays = Holidays::for(country: 'si')->get(); - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); - expect(formatDates($holidays))->toMatchSnapshot(); + expect(formatDates($holidays))->toMatchSnapshot(); }); From 8d7932e724c7939cb069f34df13d0dd8261ba1d8 Mon Sep 17 00:00:00 2001 From: vkosachev Date: Wed, 31 Jan 2024 22:08:48 +0200 Subject: [PATCH 92/99] Add Moldavian Holidays (#95) * Add Moldavian Holidays * Add Moldavian Holidays * change location for tests * updating the snapshots * Remove custom algorithm and use built in "orthodoxEater() method." * update from upstream --------- Co-authored-by: Vitaliy Kosachev --- src/Countries/Moldova.php | 40 ++++++++++++++ .../it_can_calculate_moldavian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/MoldovaTest.php | 19 +++++++ 3 files changed, 113 insertions(+) create mode 100644 src/Countries/Moldova.php create mode 100644 tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap create mode 100644 tests/Countries/MoldovaTest.php diff --git a/src/Countries/Moldova.php b/src/Countries/Moldova.php new file mode 100644 index 000000000..0e7d3d47b --- /dev/null +++ b/src/Countries/Moldova.php @@ -0,0 +1,40 @@ + '01-01', + 'Crăciunul pe stil vechi' => '01-07', + 'A doua zi de Crăciun pe stil vechi' => '01-08', + 'Ziua Internațională a Femeii' => '03-08', + 'Ziua Muncii' => '05-01', + 'Ziua Europei' => '05-09', + 'Ziua Internațională a Copilului' => '06-01', + 'Ziua Independenței' => '08-27', + 'Ziua Limbii Române' => '08-31', + 'Crăciunul pe stil nou' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->orthodoxEaster($year); + return [ + 'Prima zi de Paște' => $easter, + 'A doua zi de Paște' => $easter->addDay(), + 'Paștele Blajinilor' => $easter->addDays(8), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap b/tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap new file mode 100644 index 000000000..9d18ecd37 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Anul Nou", + "date": "2024-01-01" + }, + { + "name": "Cr\u0103ciunul pe stil vechi", + "date": "2024-01-07" + }, + { + "name": "A doua zi de Cr\u0103ciun pe stil vechi", + "date": "2024-01-08" + }, + { + "name": "Ziua Interna\u021bional\u0103 a Femeii", + "date": "2024-03-08" + }, + { + "name": "Ziua Muncii", + "date": "2024-05-01" + }, + { + "name": "Prima zi de Pa\u0219te", + "date": "2024-05-05" + }, + { + "name": "A doua zi de Pa\u0219te", + "date": "2024-05-06" + }, + { + "name": "Ziua Europei", + "date": "2024-05-09" + }, + { + "name": "Pa\u0219tele Blajinilor", + "date": "2024-05-13" + }, + { + "name": "Ziua Interna\u021bional\u0103 a Copilului", + "date": "2024-06-01" + }, + { + "name": "Ziua Independen\u021bei", + "date": "2024-08-27" + }, + { + "name": "Ziua Limbii Rom\u00e2ne", + "date": "2024-08-31" + }, + { + "name": "Cr\u0103ciunul pe stil nou", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/MoldovaTest.php b/tests/Countries/MoldovaTest.php new file mode 100644 index 000000000..02ac0db64 --- /dev/null +++ b/tests/Countries/MoldovaTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 976518c67ff6049f045853b163367e57b91248af Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:09:20 +0000 Subject: [PATCH 93/99] Fix styling --- src/Countries/Moldova.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Countries/Moldova.php b/src/Countries/Moldova.php index 0e7d3d47b..aadae2468 100644 --- a/src/Countries/Moldova.php +++ b/src/Countries/Moldova.php @@ -30,7 +30,8 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->orthodoxEaster($year); + $easter = $this->orthodoxEaster($year); + return [ 'Prima zi de Paște' => $easter, 'A doua zi de Paște' => $easter->addDay(), From c2ce9ce0b70b1cae5f1e556b32916388abe550e0 Mon Sep 17 00:00:00 2001 From: Michael Nabil <46572405+michaelnabil230@users.noreply.github.com> Date: Wed, 31 Jan 2024 22:20:19 +0200 Subject: [PATCH 94/99] Add `Egypt` Holidays (#35) * Add `Egypt` Holidays * Clean * Fix * Update src/Countries/Egypt.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Fix test * Added a translation --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/egypt/ar/holidays.json | 23 +++++ src/Countries/Egypt.php | 47 ++++++++++ .../it_can_calculate_egypt_holidays.snap | 86 +++++++++++++++++++ tests/Countries/EgyptTest.php | 17 ++++ 4 files changed, 173 insertions(+) create mode 100644 lang/egypt/ar/holidays.json create mode 100644 src/Countries/Egypt.php create mode 100644 tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap create mode 100644 tests/Countries/EgyptTest.php diff --git a/lang/egypt/ar/holidays.json b/lang/egypt/ar/holidays.json new file mode 100644 index 000000000..2ca7af8d3 --- /dev/null +++ b/lang/egypt/ar/holidays.json @@ -0,0 +1,23 @@ +{ + "New Year\n's Day": "يوم رأس السنة", + "Coptic Christmas": "عيد الميلاد القبطي", + "Revolution Day January 25": "عيد ثورة 25 يناير", + "March Equinox": "اعتدال مارس", + "Sinai Liberation": "تحرير سيناء", + "Labor": "العمل", + "Coptic Good": "الصالح القبطي", + "Coptic Holy": "المقدس القبطي", + "Coptic Easter": "عيد الفصح القبطي", + "Spring Festival": "مهرجان الربيع", + "June Solstice": "انقلاب يونيو", + "June 30 Revolution": "ثورة 30 يونيو", + "Day off for June 30 Revolution": "يوم عطلة بمناسبة ثورة 30 يونيو", + "Revolution Day July 23": "عيد ثورة 23 يوليو", + "Day off for Revolution Day July 23": "يوم عطلة بمناسبة عيد ثورة 23 يوليو", + "Flooding of the Nile": "فيضان النيل", + "Nayrouz": "النيروز", + "September Equinox": "الاعتدال في سبتمبر", + "Armed Forces": "القوات المسلحة", + "Day off for Armed Forces": "يوم عطلة للقوات المسلحة", + "December Solstice": "الانقلاب الشمسي في ديسمبر" +} \ No newline at end of file diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php new file mode 100644 index 000000000..4154b53f4 --- /dev/null +++ b/src/Countries/Egypt.php @@ -0,0 +1,47 @@ + '01-01', + 'Coptic Christmas' => '01-07', + 'Revolution Day January 25' => '01-25', + 'March Equinox' => '03-20', + 'Sinai Liberation' => '04-25', + 'Labor' => '05-01', + 'Coptic Good' => '05-03', + 'Coptic Holy' => '05-04', + 'Coptic Easter' => '05-05', + 'Spring Festival' => '05-06', + 'June Solstice' => '06-20', + 'June 30 Revolution' => '06-30', + 'Day off for June 30 Revolution' => '07-04', + 'Revolution Day July 23' => '07-23', + 'Day off for Revolution Day July 23' => '07-25', + 'Flooding of the Nile' => '08-15', + 'Nayrouz' => '09-11', + 'September Equinox' => '09-22', + 'Armed Forces' => '10-06', + 'Day off for Armed Forces' => '10-10', + 'December Solstice' => '12-21', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + // The variable holidays all follow the lunar calendar, so their dates are not confirmed. + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap new file mode 100644 index 000000000..97a3a8144 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap @@ -0,0 +1,86 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Coptic Christmas", + "date": "2024-01-07" + }, + { + "name": "Revolution Day January 25", + "date": "2024-01-25" + }, + { + "name": "March Equinox", + "date": "2024-03-20" + }, + { + "name": "Sinai Liberation", + "date": "2024-04-25" + }, + { + "name": "Labor", + "date": "2024-05-01" + }, + { + "name": "Coptic Good", + "date": "2024-05-03" + }, + { + "name": "Coptic Holy", + "date": "2024-05-04" + }, + { + "name": "Coptic Easter", + "date": "2024-05-05" + }, + { + "name": "Spring Festival", + "date": "2024-05-06" + }, + { + "name": "June Solstice", + "date": "2024-06-20" + }, + { + "name": "June 30 Revolution", + "date": "2024-06-30" + }, + { + "name": "Day off for June 30 Revolution", + "date": "2024-07-04" + }, + { + "name": "Revolution Day July 23", + "date": "2024-07-23" + }, + { + "name": "Day off for Revolution Day July 23", + "date": "2024-07-25" + }, + { + "name": "Flooding of the Nile", + "date": "2024-08-15" + }, + { + "name": "Nayrouz", + "date": "2024-09-11" + }, + { + "name": "September Equinox", + "date": "2024-09-22" + }, + { + "name": "Armed Forces", + "date": "2024-10-06" + }, + { + "name": "Day off for Armed Forces", + "date": "2024-10-10" + }, + { + "name": "December Solstice", + "date": "2024-12-21" + } +] \ No newline at end of file diff --git a/tests/Countries/EgyptTest.php b/tests/Countries/EgyptTest.php new file mode 100644 index 000000000..24f5d9ea5 --- /dev/null +++ b/tests/Countries/EgyptTest.php @@ -0,0 +1,17 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); From c7b2e09a84a53baa07c76c0c96c6d85590452b87 Mon Sep 17 00:00:00 2001 From: Ye Thu Soe Date: Thu, 1 Feb 2024 02:53:39 +0630 Subject: [PATCH 95/99] add myanmar holidays (#29) * add myanmar holidays * test: update myanmar holidays * fix: remove unnecessary attribute declared --------- Co-authored-by: yethusoe91 <> --- src/Countries/Myanmar.php | 42 ++++++++ .../it_can_calculate_myanmar_holidays.snap | 102 ++++++++++++++++++ tests/Countries/MyanmarTest.php | 21 ++++ 3 files changed, 165 insertions(+) create mode 100644 src/Countries/Myanmar.php create mode 100644 tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap create mode 100644 tests/Countries/MyanmarTest.php diff --git a/src/Countries/Myanmar.php b/src/Countries/Myanmar.php new file mode 100644 index 000000000..7e7a79b74 --- /dev/null +++ b/src/Countries/Myanmar.php @@ -0,0 +1,42 @@ + '01-04', + 'ကရင်နှစ်သစ်ကူးနေ့' => '01-11', + 'ပြည်ထောင်စုနေ့' => '02-12', + 'တောင်သူလယ်သမားနေ့' => '03-02', + 'တပေါင်းလပြည့်နေ့' => '03-24', + 'တပ်မတော်နေ့' => '03-27', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၁' => '04-13', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၂' => '04-14', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၃' => '04-15', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၄' => '04-16', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၅' => '04-17', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၆' => '04-18', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၇' => '04-19', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၈' => '04-20', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၉' => '04-21', + 'အလုပ်သမားနေ့' => '05-01', + 'ကဆုန်လပြည့်နေ့' => '05-22', + 'အာဇာနည်နေ့' => '07-19', + 'ဝါဆိုလပြည့်နေ့' => '07-20', + 'သီတင်းကျွတ်ရုံးပိတ်ရက် ၁' => '10-16', + 'သီတင်းကျွတ်ရုံးပိတ်ရက် ၂' => '10-17', + 'သီတင်းကျွတ်ရုံးပိတ်ရက် ၃' => '10-18', + 'တန်ဆောင်မုန်းလပြည့်နေ့' => '11-15', + 'အမျိုးသားအောင်ပွဲနေ့' => '11-25', + 'ခရစ်စမတ်နေ့' => '12-25', + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap b/tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap new file mode 100644 index 000000000..e0da2f2a4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap @@ -0,0 +1,102 @@ +[ + { + "name": "\u101c\u103d\u1010\u103a\u101c\u1015\u103a\u101b\u1031\u1038\u1014\u1031\u1037", + "date": "2024-01-04" + }, + { + "name": "\u1000\u101b\u1004\u103a\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u1014\u1031\u1037", + "date": "2024-01-11" + }, + { + "name": "\u1015\u103c\u100a\u103a\u1011\u1031\u102c\u1004\u103a\u1005\u102f\u1014\u1031\u1037", + "date": "2024-02-12" + }, + { + "name": "\u1010\u1031\u102c\u1004\u103a\u101e\u1030\u101c\u101a\u103a\u101e\u1019\u102c\u1038\u1014\u1031\u1037", + "date": "2024-03-02" + }, + { + "name": "\u1010\u1015\u1031\u102b\u1004\u103a\u1038\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-03-24" + }, + { + "name": "\u1010\u1015\u103a\u1019\u1010\u1031\u102c\u103a\u1014\u1031\u1037", + "date": "2024-03-27" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1041", + "date": "2024-04-13" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1042", + "date": "2024-04-14" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1043", + "date": "2024-04-15" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1044", + "date": "2024-04-16" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1045", + "date": "2024-04-17" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1046", + "date": "2024-04-18" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1047", + "date": "2024-04-19" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1048", + "date": "2024-04-20" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1049", + "date": "2024-04-21" + }, + { + "name": "\u1021\u101c\u102f\u1015\u103a\u101e\u1019\u102c\u1038\u1014\u1031\u1037", + "date": "2024-05-01" + }, + { + "name": "\u1000\u1006\u102f\u1014\u103a\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-05-22" + }, + { + "name": "\u1021\u102c\u1007\u102c\u1014\u100a\u103a\u1014\u1031\u1037", + "date": "2024-07-19" + }, + { + "name": "\u101d\u102b\u1006\u102d\u102f\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-07-20" + }, + { + "name": "\u101e\u102e\u1010\u1004\u103a\u1038\u1000\u103b\u103d\u1010\u103a\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1041", + "date": "2024-10-16" + }, + { + "name": "\u101e\u102e\u1010\u1004\u103a\u1038\u1000\u103b\u103d\u1010\u103a\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1042", + "date": "2024-10-17" + }, + { + "name": "\u101e\u102e\u1010\u1004\u103a\u1038\u1000\u103b\u103d\u1010\u103a\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1043", + "date": "2024-10-18" + }, + { + "name": "\u1010\u1014\u103a\u1006\u1031\u102c\u1004\u103a\u1019\u102f\u1014\u103a\u1038\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-11-15" + }, + { + "name": "\u1021\u1019\u103b\u102d\u102f\u1038\u101e\u102c\u1038\u1021\u1031\u102c\u1004\u103a\u1015\u103d\u1032\u1014\u1031\u1037", + "date": "2024-11-25" + }, + { + "name": "\u1001\u101b\u1005\u103a\u1005\u1019\u1010\u103a\u1014\u1031\u1037", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/MyanmarTest.php b/tests/Countries/MyanmarTest.php new file mode 100644 index 000000000..cee3463f1 --- /dev/null +++ b/tests/Countries/MyanmarTest.php @@ -0,0 +1,21 @@ +get(); + + $result = Holidays::for('mm')->getName(CarbonImmutable::parse('2024-12-25')); + + expect($result)->toBe('ခရစ်စမတ်နေ့'); + + $result = Holidays::for('mm')->getName(CarbonImmutable::parse('2024-01-02')); + expect($result)->toBeNull(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From e2889785b61c13b426ebd889ef35693446d7d4b6 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:22:05 +0100 Subject: [PATCH 96/99] cleanup exceptions --- src/Countries/Country.php | 4 ++-- src/Countries/SriLanka.php | 4 ++-- src/Countries/Switzerland.php | 2 +- .../{UnsupportedCountry.php => InvalidCountry.php} | 4 ++-- src/Exceptions/InvalidRegion.php | 7 +------ tests/Countries/SriLankaTest.php | 4 ++-- tests/HolidaysTest.php | 4 ++-- 7 files changed, 12 insertions(+), 17 deletions(-) rename src/Exceptions/{UnsupportedCountry.php => InvalidCountry.php} (59%) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 9e9a85533..9934a7972 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; abstract class Country { @@ -93,7 +93,7 @@ public static function findOrFail(string $countryCode): Country $country = self::find($countryCode); if (! $country) { - throw UnsupportedCountry::make($countryCode); + throw InvalidCountry::notFound($countryCode); } return $country; diff --git a/src/Countries/SriLanka.php b/src/Countries/SriLanka.php index a94f46cdf..10413e49d 100644 --- a/src/Countries/SriLanka.php +++ b/src/Countries/SriLanka.php @@ -2,7 +2,7 @@ namespace Spatie\Holidays\Countries; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; class SriLanka extends Country { @@ -16,6 +16,6 @@ protected function allHolidays(int $year): array // Sri lanka has a committee that decides the holidays for the year // instead of following a full moon calendar. - throw UnsupportedCountry::make($this->countryCode()); + throw InvalidCountry::notFound($this->countryCode()); } } diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index c2e9d157c..d4d710689 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -73,7 +73,7 @@ class Switzerland extends Country public function __construct(protected ?string $region = null) { if ($region !== null && ! in_array($region, self::REGIONS)) { - throw InvalidRegion::unsupportedRegion($region); + throw InvalidRegion::notFound($region); } } diff --git a/src/Exceptions/UnsupportedCountry.php b/src/Exceptions/InvalidCountry.php similarity index 59% rename from src/Exceptions/UnsupportedCountry.php rename to src/Exceptions/InvalidCountry.php index 79bcabb34..451910b25 100644 --- a/src/Exceptions/UnsupportedCountry.php +++ b/src/Exceptions/InvalidCountry.php @@ -4,9 +4,9 @@ use RuntimeException; -class UnsupportedCountry extends RuntimeException +class InvalidCountry extends RuntimeException { - public static function make(string $countryCode): self + public static function notFound(string $countryCode): self { return new self("Country code `{$countryCode}` is not supported."); } diff --git a/src/Exceptions/InvalidRegion.php b/src/Exceptions/InvalidRegion.php index 7941fe2b5..d27ed70d7 100644 --- a/src/Exceptions/InvalidRegion.php +++ b/src/Exceptions/InvalidRegion.php @@ -6,13 +6,8 @@ class InvalidRegion extends RuntimeException { - public static function unsupportedRegion(string $region): self + public static function notFound(string $region): self { return new self("Region '$region' is not supported."); } - - public static function unsupportedLocale(string $locale): self - { - return new self("Locale '$locale' is not supported."); - } } diff --git a/tests/Countries/SriLankaTest.php b/tests/Countries/SriLankaTest.php index ab8eefe4a..5989f52e3 100644 --- a/tests/Countries/SriLankaTest.php +++ b/tests/Countries/SriLankaTest.php @@ -2,9 +2,9 @@ namespace Spatie\Holidays\Tests\Countries; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('cannot calculate sri lanka holidays', function () { Holidays::for(country: 'lk')->get(); -})->throws(UnsupportedCountry::class); +})->throws(InvalidCountry::class); diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index c09d7db67..c5a462123 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -5,7 +5,7 @@ use Spatie\Holidays\Countries\Netherlands; use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('can get all holidays of the current year', function () { @@ -43,7 +43,7 @@ it('cannot get all holidays of an unknown country code', function () { Holidays::for(country: 'unknown'); -})->throws(UnsupportedCountry::class); +})->throws(InvalidCountry::class); it('cannot get holidays for years before 1970', function () { Holidays::for(country: 'be', year: 1969)->get(); From 0ee271a4f1cc4edcee0d0ef5e524b5875a3ff4f5 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:24:24 +0000 Subject: [PATCH 97/99] Fix styling --- src/Countries/Country.php | 2 +- tests/HolidaysTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 9934a7972..538b89675 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -4,8 +4,8 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Concerns\Translatable; -use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\InvalidCountry; +use Spatie\Holidays\Exceptions\InvalidYear; abstract class Country { diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index c5a462123..99f8a792a 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -3,9 +3,9 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Countries\Belgium; use Spatie\Holidays\Countries\Netherlands; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('can get all holidays of the current year', function () { From e30a34d631b24cd7981b55a7c7a759a2d64d4311 Mon Sep 17 00:00:00 2001 From: Joshua Paul <52431939+cybernerdie@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:31:16 +0100 Subject: [PATCH 98/99] Added support for holidays in Nigeria (#10) * Added support for holidays in Nigeria * fix name of the test case * remove children's day from list of official holiday * fix code styling issues * Update src/Countries/Nigeria.php --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- src/Countries/Nigeria.php | 36 +++++++++++++++++++ .../it_can_calculate_nigerian_holidays.snap | 34 ++++++++++++++++++ tests/Countries/NigeriaTest.php | 18 ++++++++++ 3 files changed, 88 insertions(+) create mode 100644 src/Countries/Nigeria.php create mode 100644 tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap create mode 100644 tests/Countries/NigeriaTest.php diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php new file mode 100644 index 000000000..21ead05d6 --- /dev/null +++ b/src/Countries/Nigeria.php @@ -0,0 +1,36 @@ + "01-01", + 'Worker\'s Day' => "05-01", + 'Democracy Day' => "06-12", + 'Independence Day' => "10-01", + 'Christmas Day' => "12-25", + 'Boxing Day' => "12-26", + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap new file mode 100644 index 000000000..ee5d39b48 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Worker's Day", + "date": "2024-05-01" + }, + { + "name": "Democracy Day", + "date": "2024-06-12" + }, + { + "name": "Independence Day", + "date": "2024-10-01" + }, + { + "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/NigeriaTest.php b/tests/Countries/NigeriaTest.php new file mode 100644 index 000000000..8fdb2a32a --- /dev/null +++ b/tests/Countries/NigeriaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 914ae68e4dd979172182fb60058ae914db12c0f8 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:31:34 +0000 Subject: [PATCH 99/99] Fix styling --- src/Countries/Nigeria.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php index 21ead05d6..7721b0d06 100644 --- a/src/Countries/Nigeria.php +++ b/src/Countries/Nigeria.php @@ -14,12 +14,12 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => "01-01", - 'Worker\'s Day' => "05-01", - 'Democracy Day' => "06-12", - 'Independence Day' => "10-01", - 'Christmas Day' => "12-25", - 'Boxing Day' => "12-26", + 'New Year\'s Day' => '01-01', + 'Worker\'s Day' => '05-01', + 'Democracy Day' => '06-12', + 'Independence Day' => '10-01', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', ], $this->variableHolidays($year)); }