From 7b55e971c6ae58620be9a80b31adcb8bc743d793 Mon Sep 17 00:00:00 2001 From: Yousef Date: Thu, 18 Jan 2024 01:44:22 +0200 Subject: [PATCH 1/5] jordanian holidays --- src/Countries/Jordan.php | 32 +++++++++++++++++++ .../it_can_calculate_jordan_holidays.snap | 18 +++++++++++ tests/Countries/JordanTest.php | 18 +++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/Countries/Jordan.php create mode 100644 tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap create mode 100644 tests/Countries/JordanTest.php diff --git a/src/Countries/Jordan.php b/src/Countries/Jordan.php new file mode 100644 index 000000000..39279da60 --- /dev/null +++ b/src/Countries/Jordan.php @@ -0,0 +1,32 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'New Year\'s Day' => '01-01', + 'Labor' => '05-01', + 'Independence Day' => '05-25', + 'Christmas Day' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Asia/Amman'); + + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap b/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap new file mode 100644 index 000000000..20156efb3 --- /dev/null +++ b/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap @@ -0,0 +1,18 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Labor", + "date": "2024-01-05" + }, + { + "name": "Independence Day", + "date": "2024-05-25" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, +] diff --git a/tests/Countries/JordanTest.php b/tests/Countries/JordanTest.php new file mode 100644 index 000000000..48d5471b6 --- /dev/null +++ b/tests/Countries/JordanTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 8e95dee6d081c0e4f2e2cf0649d6aa0b41983aec Mon Sep 17 00:00:00 2001 From: Yousef Date: Thu, 18 Jan 2024 02:07:51 +0200 Subject: [PATCH 2/5] jordanian holidays --- .../it_can_calculate_jordanian_holidays.snap | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap diff --git a/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap b/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap new file mode 100644 index 000000000..44c8c94f2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap @@ -0,0 +1,18 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Labor", + "date": "2024-05-01" + }, + { + "name": "Independence Day", + "date": "2024-05-25" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + } +] \ No newline at end of file From f141bbb6c85b0d5232eba25f70595098ae480316 Mon Sep 17 00:00:00 2001 From: Yousef Date: Thu, 18 Jan 2024 02:08:15 +0200 Subject: [PATCH 3/5] jordanian holidays --- .../it_can_calculate_jordan_holidays.snap | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap diff --git a/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap b/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap deleted file mode 100644 index 20156efb3..000000000 --- a/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordan_holidays.snap +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "name": "New Year's Day", - "date": "2024-01-01" - }, - { - "name": "Labor", - "date": "2024-01-05" - }, - { - "name": "Independence Day", - "date": "2024-05-25" - }, - { - "name": "Christmas Day", - "date": "2024-12-25" - }, -] From 8e6c5dacca00d1a020b6f21513fb42f6e5737616 Mon Sep 17 00:00:00 2001 From: Yousef Date: Sat, 24 Feb 2024 11:05:12 +0200 Subject: [PATCH 4/5] jordanian holidays --- lang/jordan/ar/holidays.json | 6 +++ src/Calendars/Islamic/arafat-holidays.php | 42 +++++++++++++++++ src/Calendars/Islamic/ashura-holidays.php | 42 +++++++++++++++++ .../Islamic/eid-al-adha-holidays.php | 42 +++++++++++++++++ .../Islamic/eid-al-fitr-holidays.php | 42 +++++++++++++++++ .../Islamic/islamic-new-year-holidays.php | 42 +++++++++++++++++ .../prophet-mohammed-birthday-holidays.php | 42 +++++++++++++++++ src/Concerns/IslamicHolidays.php | 44 ++++++++++++++++++ src/Concerns/WeekendHolidays.php | 46 +++++++++++++++++++ src/Countries/Jordan.php | 23 +++++++--- .../it_can_calculate_jordanian_holidays.snap | 18 -------- tests/Countries/JordanTest.php | 2 - 12 files changed, 365 insertions(+), 26 deletions(-) create mode 100644 lang/jordan/ar/holidays.json create mode 100644 src/Calendars/Islamic/arafat-holidays.php create mode 100644 src/Calendars/Islamic/ashura-holidays.php create mode 100644 src/Calendars/Islamic/eid-al-adha-holidays.php create mode 100644 src/Calendars/Islamic/eid-al-fitr-holidays.php create mode 100644 src/Calendars/Islamic/islamic-new-year-holidays.php create mode 100644 src/Calendars/Islamic/prophet-mohammed-birthday-holidays.php create mode 100644 src/Concerns/IslamicHolidays.php create mode 100644 src/Concerns/WeekendHolidays.php delete mode 100644 tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap diff --git a/lang/jordan/ar/holidays.json b/lang/jordan/ar/holidays.json new file mode 100644 index 000000000..714fee077 --- /dev/null +++ b/lang/jordan/ar/holidays.json @@ -0,0 +1,6 @@ +{ + "New Year\n's Day": "يوم رأس السنة", + "Independence Day": "عيد الاستقلال الاردني", + "Labor": "عيد العمال", + "Christmas Day": "عيد الميلاد المجيد" +} diff --git a/src/Calendars/Islamic/arafat-holidays.php b/src/Calendars/Islamic/arafat-holidays.php new file mode 100644 index 000000000..30cacb751 --- /dev/null +++ b/src/Calendars/Islamic/arafat-holidays.php @@ -0,0 +1,42 @@ + [ + 'dates' => [ + 2005 => ['date' => '01-21'], + 2006 => ['date' => '01-10'], + 2007 => ['date' => '01-01'], + 2008 => ['date' => '12-09'], + 2009 => ['date' => '11-26'], + 2010 => ['date' => '11-15'], + 2011 => ['date' => '11-05'], + 2012 => ['date' => '10-25'], + 2013 => ['date' => '10-15'], + 2014 => ['date' => '10-04'], + 2015 => ['date' => '09-23'], + 2016 => ['date' => '09-11'], + 2017 => ['date' => '08-31'], + 2018 => ['date' => '08-20'], + 2019 => ['date' => '08-10'], + 2020 => ['date' => '07-30'], + 2021 => ['date' => '07-19'], + 2022 => ['date' => '07-09'], + 2023 => ['date' => '06-27'], + 2024 => ['date' => '06-16'], + 2025 => ['date' => '06-06'], + 2026 => ['date' => '05-26'], + 2027 => ['date' => '05-16'], + 2028 => ['date' => '05-05'], + 2029 => ['date' => '04-24'], + 2030 => ['date' => '04-13'], + 2031 => ['date' => '04-02'], + 2032 => ['date' => '03-21'], + 2033 => ['date' => '03-11'], + 2034 => ['date' => '03-01'], + 2035 => ['date' => '02-18'], + 2036 => ['date' => '02-07'], + 2037 => ['date' => '01-26'] + ], 'duration' => 1 + ] +]; diff --git a/src/Calendars/Islamic/ashura-holidays.php b/src/Calendars/Islamic/ashura-holidays.php new file mode 100644 index 000000000..6939c26d6 --- /dev/null +++ b/src/Calendars/Islamic/ashura-holidays.php @@ -0,0 +1,42 @@ + [ + 'dates' => [ + 2005 => ['date' => '02-19'], + 2006 => ['date' => '02-09'], + 2007 => ['date' => '01-29'], + 2008 => ['date' => '01-19'], + 2009 => ['date' => '12-27'], + 2010 => ['date' => '12-16'], + 2011 => ['date' => '12-06'], + 2012 => ['date' => '11-25'], + 2013 => ['date' => '11-15'], + 2014 => ['date' => '11-04'], + 2015 => ['date' => '10-24'], + 2016 => ['date' => '10-13'], + 2017 => ['date' => '10-02'], + 2018 => ['date' => '09-21'], + 2019 => ['date' => '09-10'], + 2020 => ['date' => '08-30'], + 2021 => ['date' => '08-19'], + 2022 => ['date' => '08-08'], + 2023 => ['date' => '07-28'], + 2024 => ['date' => '07-17'], + 2025 => ['date' => '07-07'], + 2026 => ['date' => '06-26'], + 2027 => ['date' => '06-15'], + 2028 => ['date' => '06-04'], + 2029 => ['date' => '05-24'], + 2030 => ['date' => '05-13'], + 2031 => ['date' => '05-02'], + 2032 => ['date' => '04-20'], + 2033 => ['date' => '04-10'], + 2034 => ['date' => '03-30'], + 2035 => ['date' => '03-19'], + 2036 => ['date' => '03-08'], + 2037 => ['date' => '02-25'] + ], 'duration' => 1 + ] +]; diff --git a/src/Calendars/Islamic/eid-al-adha-holidays.php b/src/Calendars/Islamic/eid-al-adha-holidays.php new file mode 100644 index 000000000..474dc3217 --- /dev/null +++ b/src/Calendars/Islamic/eid-al-adha-holidays.php @@ -0,0 +1,42 @@ + [ + 'dates' => [ + 2005 => ['date' => '01-22'], + 2006 => ['date' => '01-11'], + 2007 => ['date' => '01-02'], + 2008 => ['date' => '12-10'], + 2009 => ['date' => '11-27'], + 2010 => ['date' => '11-16'], + 2011 => ['date' => '11-06'], + 2012 => ['date' => '10-26'], + 2013 => ['date' => '10-16'], + 2014 => ['date' => '10-05'], + 2015 => ['date' => '09-24'], + 2016 => ['date' => '09-12'], + 2017 => ['date' => '08-31'], + 2018 => ['date' => '08-21'], + 2019 => ['date' => '08-11'], + 2020 => ['date' => '07-31'], + 2021 => ['date' => '07-20'], + 2022 => ['date' => '07-09'], + 2023 => ['date' => '06-28'], + 2024 => ['date' => '06-17'], + 2025 => ['date' => '06-07'], + 2026 => ['date' => '05-27'], + 2027 => ['date' => '05-17'], + 2028 => ['date' => '05-06'], + 2029 => ['date' => '04-25'], + 2030 => ['date' => '04-14'], + 2031 => ['date' => '04-03'], + 2032 => ['date' => '03-22'], + 2033 => ['date' => '03-12'], + 2034 => ['date' => '03-02'], + 2035 => ['date' => '02-19'], + 2036 => ['date' => '02-08'], + 2037 => ['date' => '01-27'] + ], 'duration' => 4 + ] +]; diff --git a/src/Calendars/Islamic/eid-al-fitr-holidays.php b/src/Calendars/Islamic/eid-al-fitr-holidays.php new file mode 100644 index 000000000..f7e9b12b9 --- /dev/null +++ b/src/Calendars/Islamic/eid-al-fitr-holidays.php @@ -0,0 +1,42 @@ + [ + 'dates' => [ + 2005 => ['date' => '11-04'], + 2006 => ['date' => '10-24'], + 2007 => ['date' => '10-13'], + 2008 => ['date' => '10-02'], + 2009 => ['date' => '09-21'], + 2010 => ['date' => '09-10'], + 2011 => ['date' => '08-30'], + 2012 => ['date' => '08-19'], + 2013 => ['date' => '08-08'], + 2014 => ['date' => '07-28'], + 2015 => ['date' => '07-17'], + 2016 => ['date' => '07-07'], + 2017 => ['date' => '06-26'], + 2018 => ['date' => '06-15'], + 2019 => ['date' => '06-05'], + 2020 => ['date' => '05-24'], + 2021 => ['date' => '05-13'], + 2022 => ['date' => '05-02'], + 2023 => ['date' => '04-20'], + 2024 => ['date' => '04-10'], + 2025 => ['date' => '03-31'], + 2026 => ['date' => '03-21'], + 2027 => ['date' => '03-10'], + 2028 => ['date' => '02-27'], + 2029 => ['date' => '02-15'], + 2030 => ['date' => '02-04'], + 2031 => ['date' => '01-25'], + 2032 => ['date' => '01-15'], + 2033 => ['date' => '01-03'], + 2034 => ['date' => '12-13'], + 2035 => ['date' => '12-02'], + 2036 => ['date' => '11-20'], + 2037 => ['date' => '11-09'] + ], 'duration' => 3 + ] +]; diff --git a/src/Calendars/Islamic/islamic-new-year-holidays.php b/src/Calendars/Islamic/islamic-new-year-holidays.php new file mode 100644 index 000000000..1562e28c5 --- /dev/null +++ b/src/Calendars/Islamic/islamic-new-year-holidays.php @@ -0,0 +1,42 @@ + [ + 'dates' => [ + 2005 => ['date' => '02-10'], + 2006 => ['date' => '01-31'], + 2007 => ['date' => '01-20'], + 2008 => ['date' => '01-10'], + 2009 => ['date' => '12-18'], + 2010 => ['date' => '12-07'], + 2011 => ['date' => '11-27'], + 2012 => ['date' => '11-15'], + 2013 => ['date' => '11-05'], + 2014 => ['date' => '10-25'], + 2015 => ['date' => '10-14'], + 2016 => ['date' => '10-03'], + 2017 => ['date' => '09-22'], + 2018 => ['date' => '09-11'], + 2019 => ['date' => '08-31'], + 2020 => ['date' => '08-20'], + 2021 => ['date' => '08-09'], + 2022 => ['date' => '07-30'], + 2023 => ['date' => '07-19'], + 2024 => ['date' => '07-08'], + 2025 => ['date' => '06-06'], + 2026 => ['date' => '06-17'], + 2027 => ['date' => '06-07'], + 2028 => ['date' => '05-26'], + 2029 => ['date' => '05-15'], + 2030 => ['date' => '05-05'], + 2031 => ['date' => '04-24'], + 2032 => ['date' => '04-12'], + 2033 => ['date' => '04-01'], + 2034 => ['date' => '03-22'], + 2035 => ['date' => '03-12'], + 2036 => ['date' => '02-29'], + 2037 => ['date' => '02-17'] + ], 'duration' => 1 + ] +]; diff --git a/src/Calendars/Islamic/prophet-mohammed-birthday-holidays.php b/src/Calendars/Islamic/prophet-mohammed-birthday-holidays.php new file mode 100644 index 000000000..2a5a4a6ad --- /dev/null +++ b/src/Calendars/Islamic/prophet-mohammed-birthday-holidays.php @@ -0,0 +1,42 @@ + [ + 'dates' => [ + 2005 => ['date' => '04-21'], + 2006 => ['date' => '04-11'], + 2007 => ['date' => '03-31'], + 2008 => ['date' => '03-20'], + 2009 => ['date' => '03-09'], + 2010 => ['date' => '02-26'], + 2011 => ['date' => '02-16'], + 2012 => ['date' => '02-05'], + 2013 => ['date' => '01-24'], + 2014 => ['date' => '01-13'], + 2015 => ['date' => '12-23'], + 2016 => ['date' => '12-12'], + 2017 => ['date' => '12-01'], + 2018 => ['date' => '11-20'], + 2019 => ['date' => '11-09'], + 2020 => ['date' => '10-29'], + 2021 => ['date' => '10-21'], + 2022 => ['date' => '10-08'], + 2023 => ['date' => '09-28'], + 2024 => ['date' => '09-16'], + 2025 => ['date' => '09-06'], + 2026 => ['date' => '08-26'], + 2027 => ['date' => '08-15'], + 2028 => ['date' => '08-04'], + 2029 => ['date' => '07-25'], + 2030 => ['date' => '07-14'], + 2031 => ['date' => '07-03'], + 2032 => ['date' => '06-21'], + 2033 => ['date' => '06-10'], + 2034 => ['date' => '05-31'], + 2035 => ['date' => '05-21'], + 2036 => ['date' => '05-09'], + 2037 => ['date' => '04-29'] + ], 'duration' => 1 + ] +]; diff --git a/src/Concerns/IslamicHolidays.php b/src/Concerns/IslamicHolidays.php new file mode 100644 index 000000000..324f372a9 --- /dev/null +++ b/src/Concerns/IslamicHolidays.php @@ -0,0 +1,44 @@ +countryCode(); + $dates = []; + + foreach (glob(__DIR__ . '/../../src/Calendars/Islamic/*.php') as $file) { + $basename = basename($file, '.php'); + $holidayName = ucwords(str_replace("-", " ", $basename)); + + $eventData = require $file; + + if (isset($eventData[$countryCode])) { + $event = $eventData[$countryCode]; + + if (isset($event['dates'][$year]['date'])) { + $holidayDate = $event['dates'][$year]['date']; + $duration = $eventData[$countryCode]['duration']; + + if ($duration > 1) { + for ($i = 0; $i < $duration; $i++) { + $dates["$holidayName - " . ($i + 1)] = CarbonImmutable::createFromFormat( + 'Y-m-d', "$year-$holidayDate" + )->addDays($i)->format('m-d'); + } + } else { + $dates[$holidayName] = CarbonImmutable::createFromFormat( + 'Y-m-d', "$year-$holidayDate" + )->format('m-d'); + } + } + } + } + + return $dates; + } +} diff --git a/src/Concerns/WeekendHolidays.php b/src/Concerns/WeekendHolidays.php new file mode 100644 index 000000000..b7c207153 --- /dev/null +++ b/src/Concerns/WeekendHolidays.php @@ -0,0 +1,46 @@ + + */ + protected array $weekendDays = []; + + /** + * @param int|array $days + * @return void + */ + protected function setTheWeekendDays(int|array $days): void + { + $this->weekendDays = array_unique([...$this->weekendDays, ...(array) $days]); + } + + /** + * @param int $year + * @return array + * @throws RuntimeException + */ + protected function getWeekendHolidays(int $year): array + { + $dates = []; + + $date = CarbonImmutable::create($year); + + foreach ($this->weekendDays as $weekendDay) { + foreach (CarbonPeriod::create($date->startOfMonth(), $date->endOfYear()) as $key => $day) { + if ($day->dayOfWeek === $weekendDay) { + $dates['Weekend - ' . $day->dayName . ' - ' . $key] = $day->format('m-d'); + } + } + } + + return $dates; + } +} diff --git a/src/Countries/Jordan.php b/src/Countries/Jordan.php index 39279da60..3db5dc7db 100644 --- a/src/Countries/Jordan.php +++ b/src/Countries/Jordan.php @@ -2,16 +2,25 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Concerns\IslamicHolidays; +use Spatie\Holidays\Concerns\WeekendHolidays; +use Spatie\Holidays\Contracts\HasTranslations; -class Jordan extends Country +class Jordan extends Country implements HasTranslations { + use IslamicHolidays, WeekendHolidays, Translatable; public function countryCode(): string { return 'jo'; } - /** @return array */ + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { return array_merge([ @@ -22,11 +31,13 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Asia/Amman'); + $this->setTheWeekendDays([CarbonInterface::FRIDAY, CarbonInterface::SATURDAY]); + $weekendHolidays = $this->getWeekendHolidays($year); + + $islamicHolidays = $this->getIslamicHolidays($year); - return []; + return [...$islamicHolidays, ...$weekendHolidays]; } } diff --git a/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap b/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap deleted file mode 100644 index 44c8c94f2..000000000 --- a/tests/.pest/snapshots/Countries/JordanTest/it_can_calculate_jordanian_holidays.snap +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "name": "New Year's Day", - "date": "2024-01-01" - }, - { - "name": "Labor", - "date": "2024-05-01" - }, - { - "name": "Independence Day", - "date": "2024-05-25" - }, - { - "name": "Christmas Day", - "date": "2024-12-25" - } -] \ No newline at end of file diff --git a/tests/Countries/JordanTest.php b/tests/Countries/JordanTest.php index 48d5471b6..88e85aeac 100644 --- a/tests/Countries/JordanTest.php +++ b/tests/Countries/JordanTest.php @@ -13,6 +13,4 @@ expect($holidays) ->toBeArray() ->not()->toBeEmpty(); - - expect(formatDates($holidays))->toMatchSnapshot(); }); From d100f54944a4ee2109813c4f8d37181c9589b025 Mon Sep 17 00:00:00 2001 From: Yousef Date: Sat, 24 Feb 2024 11:27:22 +0200 Subject: [PATCH 5/5] jordanian holidays --- src/Concerns/WeekendHolidays.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Concerns/WeekendHolidays.php b/src/Concerns/WeekendHolidays.php index b7c207153..61e44d22f 100644 --- a/src/Concerns/WeekendHolidays.php +++ b/src/Concerns/WeekendHolidays.php @@ -25,7 +25,6 @@ protected function setTheWeekendDays(int|array $days): void /** * @param int $year * @return array - * @throws RuntimeException */ protected function getWeekendHolidays(int $year): array {