From 97125e76e045b62d7db0bef446895aaf713e91bc Mon Sep 17 00:00:00 2001 From: Stavros Date: Fri, 19 Jan 2024 02:29:45 +0200 Subject: [PATCH 01/14] Add Greece holidays --- src/Countries/Greece.php | 80 +++++++++++++++++++ .../it_can_calculate_hellenic_holidays.snap | 54 +++++++++++++ tests/Countries/GreeceTest.php | 18 +++++ 3 files changed, 152 insertions(+) create mode 100644 src/Countries/Greece.php create mode 100644 tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap create mode 100644 tests/Countries/GreeceTest.php diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php new file mode 100644 index 000000000..14feef3b4 --- /dev/null +++ b/src/Countries/Greece.php @@ -0,0 +1,80 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Πρωτοχρονιά' => '01-01', + 'Θεοφάνια' => '01-06', + '25η Μαρτίου' => '03-25', + 'Πρωτομαγιά' => '05-01', + 'Δεκαπενταύγουστος' => '08-15', + '28η Οκτωβρίου' => '10-28', + 'Χριστούγεννα' => '12-25', + 'Σύναξη της Θεοτόκου' => '12-26', + + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + + $orthodox_easter = CarbonImmutable::createFromTimestamp( + $this->calculateOrthodoxEaster($year) + )->setTimezone("Europe/Athens"); + + + $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); + + if ( + $protomagia == $orthodox_easter->subDays(2) || + $protomagia == $orthodox_easter->subDays(1) || + $protomagia == $orthodox_easter || + $protomagia == $orthodox_easter->addDay() + ) { + $protomagia = $orthodox_easter->addDays(2); + } + if ($protomagia->isSunday()) { + $protomagia = $protomagia->addDay(); + } + + return [ + 'Καθαρά Δευτέρα' => $orthodox_easter->subDays(48), //always Monday + 'Πρωτομαγιά' => $protomagia, + 'Μεγάλη Παρασκευή' => $orthodox_easter->subDays(2), + 'Κυριακή του Πάσχα' => $orthodox_easter, + 'Δευτέρα του Πάσχα' => $orthodox_easter->addDay(), + 'Αγίου Πνεύματος' => $orthodox_easter->addDays(50), //always Monday + ]; + } + + /** @return string */ + protected function calculateOrthodoxEaster(int $year) + { + $a = $year % 4; + $b = $year % 7; + $c = $year % 19; + $d = (19 * $c + 15) % 30; + $e = (2 * $a + 4 * $b - $d + 34) % 7; + $month = (int) (($d + $e + 114) / 31); + $day = (($d + $e + 114) % 31) + 1; + // julian to gregorian + $jtg = (int) ($year / 100) - (int) ($year / 400) - 2; + + $easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year); + + return $easterDate; + } +} \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap b/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap new file mode 100644 index 000000000..14b2e6ab2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Πρωτοχρονιά", + "date": "2024-01-01" + }, + { + "name": "Θεοφάνια", + "date": "2024-01-06" + }, + { + "name": "Καθαρά Δευτέρα", + "date": "2024-03-18" + }, + { + "name": "25η Μαρτίου", + "date": "2024-03-25" + }, + { + "name": "Πρωτομαγιά", + "date": "2024-05-01" + }, + { + "name": "Μεγάλη Παρασκευή", + "date": "2024-05-03" + }, + { + "name": "Κυριακή του Πάσχα", + "date": "2024-05-05" + }, + { + "name": "Δευτέρα του Πάσχα", + "date": "2024-05-06" + }, + { + "name": "Αγίου Πνεύματος", + "date": "2024-06-24" + }, + { + "name": "Δεκαπενταύγουστος", + "date": "2024-08-15" + }, + { + "name": "28η Οκτωβρίου", + "date": "2024-10-28" + }, + { + "name": "Χριστούγεννα", + "date": "2024-12-25" + }, + { + "name": "Σύναξη της Θεοτόκου", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/GreeceTest.php b/tests/Countries/GreeceTest.php new file mode 100644 index 000000000..26805abbe --- /dev/null +++ b/tests/Countries/GreeceTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 3dfb792a0846e463fa07e7879619595c3fae5685 Mon Sep 17 00:00:00 2001 From: Stavros Date: Fri, 19 Jan 2024 13:32:03 +0200 Subject: [PATCH 02/14] Add Greece holidays - phpstan-baseline --- phpstan-baseline.neon | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 51b9330fc..56b63c38f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20,6 +20,26 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Cannot call method addDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 1 + path: src/Countries/Greece.php + + - + message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 1 + path: src/Countries/Greece.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Greece\\:\\:calculateOrthodoxEaster\\(\\) should return string but returns int\\|false\\.$#" + count: 1 + path: src/Countries/Greece.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Greece\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" + count: 1 + path: src/Countries/Greece.php + - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 From 81682ff5dfd8726171fca76b53a871d593bc075e Mon Sep 17 00:00:00 2001 From: Stavros Date: Fri, 19 Jan 2024 14:10:32 +0200 Subject: [PATCH 03/14] Add Greece holidays - phpstan-baseline - fix int --- phpstan-baseline.neon | 5 ----- src/Countries/Greece.php | 7 ++++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 56b63c38f..0f6d531fd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -30,11 +30,6 @@ parameters: count: 1 path: src/Countries/Greece.php - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Greece\\:\\:calculateOrthodoxEaster\\(\\) should return string but returns int\\|false\\.$#" - count: 1 - path: src/Countries/Greece.php - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Greece\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" count: 1 diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 14feef3b4..17e2a29fd 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -60,8 +60,8 @@ protected function variableHolidays(int $year): array ]; } - /** @return string */ - protected function calculateOrthodoxEaster(int $year) + /** @return integer */ + protected function calculateOrthodoxEaster(int $year): int { $a = $year % 4; $b = $year % 7; @@ -75,6 +75,7 @@ protected function calculateOrthodoxEaster(int $year) $easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year); - return $easterDate; + return (int) $easterDate; + } } \ No newline at end of file From 43f1e72592ac0a0aa7a54c12d5c1a4d8ddb7772c Mon Sep 17 00:00:00 2001 From: Stavros Date: Fri, 19 Jan 2024 14:47:51 +0200 Subject: [PATCH 04/14] fix pest --- .../it_can_calculate_hellenic_holidays.snap | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap b/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap index 14b2e6ab2..00c8075cc 100644 --- a/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap +++ b/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap @@ -1,54 +1,54 @@ [ { - "name": "Πρωτοχρονιά", + "name": "\u03a0\u03c1\u03c9\u03c4\u03bf\u03c7\u03c1\u03bf\u03bd\u03b9\u03ac", "date": "2024-01-01" }, { - "name": "Θεοφάνια", + "name": "\u0398\u03b5\u03bf\u03c6\u03ac\u03bd\u03b9\u03b1", "date": "2024-01-06" }, { - "name": "Καθαρά Δευτέρα", + "name": "\u039a\u03b1\u03b8\u03b1\u03c1\u03ac \u0394\u03b5\u03c5\u03c4\u03ad\u03c1\u03b1", "date": "2024-03-18" }, { - "name": "25η Μαρτίου", + "name": "25\u03b7 \u039c\u03b1\u03c1\u03c4\u03af\u03bf\u03c5", "date": "2024-03-25" }, { - "name": "Πρωτομαγιά", + "name": "\u03a0\u03c1\u03c9\u03c4\u03bf\u03bc\u03b1\u03b3\u03b9\u03ac", "date": "2024-05-01" }, { - "name": "Μεγάλη Παρασκευή", + "name": "\u039c\u03b5\u03b3\u03ac\u03bb\u03b7 \u03a0\u03b1\u03c1\u03b1\u03c3\u03ba\u03b5\u03c5\u03ae", "date": "2024-05-03" }, { - "name": "Κυριακή του Πάσχα", + "name": "\u039a\u03c5\u03c1\u03b9\u03b1\u03ba\u03ae \u03c4\u03bf\u03c5 \u03a0\u03ac\u03c3\u03c7\u03b1", "date": "2024-05-05" }, { - "name": "Δευτέρα του Πάσχα", + "name": "\u0394\u03b5\u03c5\u03c4\u03ad\u03c1\u03b1 \u03c4\u03bf\u03c5 \u03a0\u03ac\u03c3\u03c7\u03b1", "date": "2024-05-06" }, { - "name": "Αγίου Πνεύματος", + "name": "\u0391\u03b3\u03af\u03bf\u03c5 \u03a0\u03bd\u03b5\u03cd\u03bc\u03b1\u03c4\u03bf\u03c2", "date": "2024-06-24" }, { - "name": "Δεκαπενταύγουστος", + "name": "\u0394\u03b5\u03ba\u03b1\u03c0\u03b5\u03bd\u03c4\u03b1\u03cd\u03b3\u03bf\u03c5\u03c3\u03c4\u03bf\u03c2", "date": "2024-08-15" }, { - "name": "28η Οκτωβρίου", + "name": "28\u03b7 \u039f\u03ba\u03c4\u03c9\u03b2\u03c1\u03af\u03bf\u03c5", "date": "2024-10-28" }, { - "name": "Χριστούγεννα", + "name": "\u03a7\u03c1\u03b9\u03c3\u03c4\u03bf\u03cd\u03b3\u03b5\u03bd\u03bd\u03b1", "date": "2024-12-25" }, { - "name": "Σύναξη της Θεοτόκου", + "name": "\u03a3\u03cd\u03bd\u03b1\u03be\u03b7 \u03c4\u03b7\u03c2 \u0398\u03b5\u03bf\u03c4\u03cc\u03ba\u03bf\u03c5", "date": "2024-12-26" } ] \ No newline at end of file From 49e0daab56a7b781566cbf4d82097250b69c624f Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 22 Jan 2024 12:36:37 +0200 Subject: [PATCH 05/14] fix conflict phpstan-beseline --- phpstan-baseline.neon | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0f6d531fd..51b9330fc 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20,21 +20,6 @@ parameters: count: 1 path: src/Countries/Country.php - - - message: "#^Cannot call method addDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Greece.php - - - - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Greece.php - - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Greece\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Greece.php - - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 From 2cd3fbf722db4121be9c0d45c76414b356683fa0 Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 22 Jan 2024 12:41:28 +0200 Subject: [PATCH 06/14] fix conflict phpstan-beseline generate again --- phpstan-baseline.neon | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 51b9330fc..0f6d531fd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20,6 +20,21 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Cannot call method addDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 1 + path: src/Countries/Greece.php + + - + message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 1 + path: src/Countries/Greece.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Greece\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" + count: 1 + path: src/Countries/Greece.php + - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 From b2034ac7aa4be905a65bc7e791817bfd5396fda3 Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 22 Jan 2024 14:14:21 +0200 Subject: [PATCH 07/14] update country orthodoxeaster --- src/Countries/Country.php | 17 +++++++++++++++-- src/Countries/Greece.php | 25 +------------------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 3a09768db..85ba9b45a 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -50,10 +50,23 @@ protected function easter(int $year): CarbonImmutable protected function orthodoxEaster(int $year): CarbonImmutable { - $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); + $a = $year % 4; + $b = $year % 7; + $c = $year % 19; + $d = (19 * $c + 15) % 30; + $e = (2 * $a + 4 * $b - $d + 34) % 7; + $month = (int) (($d + $e + 114) / 31); + $day = (($d + $e + 114) % 31) + 1; + // julian to gregorian + $jtg = (int) ($year / 100) - (int) ($year / 400) - 2; + + $easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year); + + /*$timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); + return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp));*/ + return CarbonImmutable::createFromTimestamp($easterDate); } public static function find(string $countryCode): ?Country diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index d05f4f75c..87b63f9e9 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -30,11 +30,7 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { - $orthodox_easter = CarbonImmutable::createFromTimestamp( - $this->calculateOrthodoxEaster($year) - )->setTimezone("Europe/Athens"); - //$orthodox_easter = $this->orthodoxEaster($year); - + $orthodox_easter = $this->orthodoxEaster($year); $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); if ( @@ -58,23 +54,4 @@ protected function variableHolidays(int $year): array 'Αγίου Πνεύματος' => $orthodox_easter->addDays(50), //always Monday ]; } - - /** @return integer */ - protected function calculateOrthodoxEaster(int $year): int - { - $a = $year % 4; - $b = $year % 7; - $c = $year % 19; - $d = (19 * $c + 15) % 30; - $e = (2 * $a + 4 * $b - $d + 34) % 7; - $month = (int) (($d + $e + 114) / 31); - $day = (($d + $e + 114) % 31) + 1; - // julian to gregorian - $jtg = (int) ($year / 100) - (int) ($year / 400) - 2; - - $easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year); - - return (int) $easterDate; - - } } \ No newline at end of file From ad2555d4c465f285e2e99ff088a69380583bf68c Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 22 Jan 2024 15:33:36 +0200 Subject: [PATCH 08/14] Update Country.php cleanup --- src/Countries/Country.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 85ba9b45a..64bc75c13 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -51,21 +51,16 @@ 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 = (int) (($d + $e + 114) / 31); - $day = (($d + $e + 114) % 31) + 1; - // julian to gregorian - $jtg = (int) ($year / 100) - (int) ($year / 400) - 2; + $b = $year % 7; + $c = $year % 19; + $d = (19 * $c + 15) % 30; + $e = (2 * $a + 4 * $b - $d + 34) % 7; + $month = (int) (($d + $e + 114) / 31); + $day = (($d + $e + 114) % 31) + 1; + // julian to gregorian + $jtg = (int) ($year / 100) - (int) ($year / 400) - 2; + $easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year); - $easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year); - - /*$timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); - $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - - return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp));*/ return CarbonImmutable::createFromTimestamp($easterDate); } From e0fff55d9eb4915f17ea37b9406e99b3fd6b5583 Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 22 Jan 2024 16:28:06 +0200 Subject: [PATCH 09/14] reduce baseline errors --- phpstan-baseline.neon | 15 --------------- src/Countries/Greece.php | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 626ee351f..8364bfa96 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,21 +25,6 @@ parameters: count: 1 path: src/Countries/Country.php - - - message: "#^Cannot call method addDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Greece.php - - - - message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Greece.php - - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Greece\\:\\:variableHolidays\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Greece.php - - message: "#^Cannot call method setTimezone\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" count: 1 diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 87b63f9e9..ccf9a685c 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -31,6 +31,7 @@ protected function variableHolidays(int $year): array { $orthodox_easter = $this->orthodoxEaster($year); + /** @var CarbonImmutable $protomagia */ $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); if ( From d8c45403f88134a09688405311890618204099c6 Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 22 Jan 2024 16:43:57 +0200 Subject: [PATCH 10/14] camelCase change --- src/Countries/Greece.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index ccf9a685c..cb268d6d5 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -30,29 +30,29 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { - $orthodox_easter = $this->orthodoxEaster($year); + $orthodoxEaster = $this->orthodoxEaster($year); /** @var CarbonImmutable $protomagia */ $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); if ( - $protomagia == $orthodox_easter->subDays(2) || - $protomagia == $orthodox_easter->subDays(1) || - $protomagia == $orthodox_easter || - $protomagia == $orthodox_easter->addDay() + $protomagia == $orthodoxEaster->subDays(2) || + $protomagia == $orthodoxEaster->subDays(1) || + $protomagia == $orthodoxEaster || + $protomagia == $orthodoxEaster->addDay() ) { - $protomagia = $orthodox_easter->addDays(2); + $protomagia = $orthodoxEaster->addDays(2); } if ($protomagia->isSunday()) { $protomagia = $protomagia->addDay(); } return [ - 'Καθαρά Δευτέρα' => $orthodox_easter->subDays(48), //always Monday + 'Καθαρά Δευτέρα' => $orthodoxEaster->subDays(48), //always Monday 'Πρωτομαγιά' => $protomagia, - 'Μεγάλη Παρασκευή' => $orthodox_easter->subDays(2), - 'Κυριακή του Πάσχα' => $orthodox_easter, - 'Δευτέρα του Πάσχα' => $orthodox_easter->addDay(), - 'Αγίου Πνεύματος' => $orthodox_easter->addDays(50), //always Monday + 'Μεγάλη Παρασκευή' => $orthodoxEaster->subDays(2), + 'Κυριακή του Πάσχα' => $orthodoxEaster, + 'Δευτέρα του Πάσχα' => $orthodoxEaster->addDay(), + 'Αγίου Πνεύματος' => $orthodoxEaster->addDays(50), //always Monday ]; } } \ No newline at end of file From 00c99a7e0fbc839a23e5636a5a1fa01bd5070085 Mon Sep 17 00:00:00 2001 From: Stavros Date: Mon, 22 Jan 2024 18:28:08 +0200 Subject: [PATCH 11/14] restorer Country.php / add timezone --- src/Countries/Country.php | 16 ++++------------ src/Countries/Greece.php | 4 ++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 64bc75c13..3a09768db 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -50,18 +50,10 @@ 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 = (int) (($d + $e + 114) / 31); - $day = (($d + $e + 114) % 31) + 1; - // julian to gregorian - $jtg = (int) ($year / 100) - (int) ($year / 400) - 2; - $easterDate = mktime(0, 0, 0, $month, $day + $jtg, $year); - - return CarbonImmutable::createFromTimestamp($easterDate); + $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); + $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; + + return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); } public static function find(string $countryCode): ?Country diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index cb268d6d5..9f41be52c 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -29,8 +29,8 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - - $orthodoxEaster = $this->orthodoxEaster($year); + // OrthodoxEaster needs to setTimezone + $orthodoxEaster = $this->orthodoxEaster($year)->setTimezone("Europe/Athens"); /** @var CarbonImmutable $protomagia */ $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); From 6342868ce3882c4251ed5043818678f07b634465 Mon Sep 17 00:00:00 2001 From: Stavros Date: Tue, 23 Jan 2024 13:48:05 +0200 Subject: [PATCH 12/14] Common orthodox easter date on all timezones --- src/Countries/Country.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 3a09768db..f23f9ea6c 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -53,7 +53,11 @@ protected function orthodoxEaster(int $year): CarbonImmutable $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); + // Common orthodox easter date on all timezones + return CarbonImmutable::createFromTimestamp($timestamp) + ->setTime(0, 0, 0) + ->addDays($daysDifference + 1); + //return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); } public static function find(string $countryCode): ?Country From 49ddfe3423ed08a2c75b08f204728f482769fc45 Mon Sep 17 00:00:00 2001 From: Stavros Date: Tue, 23 Jan 2024 14:00:48 +0200 Subject: [PATCH 13/14] Common orthodox easter date on all timezones - cleanup --- src/Countries/Country.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index f23f9ea6c..6697d4c3b 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -54,9 +54,7 @@ protected function orthodoxEaster(int $year): CarbonImmutable $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; // Common orthodox easter date on all timezones - return CarbonImmutable::createFromTimestamp($timestamp) - ->setTime(0, 0, 0) - ->addDays($daysDifference + 1); + return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp))->startOfDay()->addDay(); //return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); } From 954ddcac2a3a83b8a8d0afbb1105a1ca964d6f64 Mon Sep 17 00:00:00 2001 From: Stavros Date: Tue, 23 Jan 2024 15:18:03 +0200 Subject: [PATCH 14/14] Greece only with default orthodoxEaster as other OrthodoxCountries --- src/Countries/Country.php | 4 +--- src/Countries/Greece.php | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 6697d4c3b..3a09768db 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -53,9 +53,7 @@ protected function orthodoxEaster(int $year): CarbonImmutable $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2; - // Common orthodox easter date on all timezones - return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp))->startOfDay()->addDay(); - //return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); + return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp)); } public static function find(string $countryCode): ?Country diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 9f41be52c..f6242839c 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -31,28 +31,30 @@ protected function variableHolidays(int $year): array { // OrthodoxEaster needs to setTimezone $orthodoxEaster = $this->orthodoxEaster($year)->setTimezone("Europe/Athens"); + $cleanMonday = $orthodoxEaster->copy()->subDays(48); + $megaliParaskevi = $orthodoxEaster->copy()->subDays(2); + $megaloSavvato = $orthodoxEaster->copy()->subDays(1); + $deuteraPasha = $orthodoxEaster->copy()->addDay(); + $agiouPneumatos = $orthodoxEaster->copy()->addDays(50); + /** @var CarbonImmutable $protomagia */ $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); + $moveProtomagia = [$megaliParaskevi, $megaloSavvato, $orthodoxEaster, $deuteraPasha]; - if ( - $protomagia == $orthodoxEaster->subDays(2) || - $protomagia == $orthodoxEaster->subDays(1) || - $protomagia == $orthodoxEaster || - $protomagia == $orthodoxEaster->addDay() - ) { - $protomagia = $orthodoxEaster->addDays(2); + if ( in_array($protomagia, $moveProtomagia) ) { + $protomagia = $orthodoxEaster->copy()->addDays(2); } if ($protomagia->isSunday()) { - $protomagia = $protomagia->addDay(); + $protomagia = $protomagia->copy()->addDay(); } return [ - 'Καθαρά Δευτέρα' => $orthodoxEaster->subDays(48), //always Monday + 'Καθαρά Δευτέρα' => $cleanMonday, //always Monday 'Πρωτομαγιά' => $protomagia, - 'Μεγάλη Παρασκευή' => $orthodoxEaster->subDays(2), + 'Μεγάλη Παρασκευή' => $megaliParaskevi, 'Κυριακή του Πάσχα' => $orthodoxEaster, - 'Δευτέρα του Πάσχα' => $orthodoxEaster->addDay(), - 'Αγίου Πνεύματος' => $orthodoxEaster->addDays(50), //always Monday + 'Δευτέρα του Πάσχα' => $deuteraPasha, + 'Αγίου Πνεύματος' => $agiouPneumatos, //always Monday ]; } } \ No newline at end of file