From 933de857656310d85b0baf7af1928e21ccae90c9 Mon Sep 17 00:00:00 2001 From: Ali Salehi Date: Sat, 20 Jan 2024 15:53:30 +0330 Subject: [PATCH 1/4] Add Iran Holidays --- src/Countries/Iran.php | 40 ++++++++++++++++++ .../it_can_calculate_iran_holidays.snap | 42 +++++++++++++++++++ tests/Countries/IranTest.php | 18 ++++++++ 3 files changed, 100 insertions(+) create mode 100644 src/Countries/Iran.php create mode 100644 tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap create mode 100644 tests/Countries/IranTest.php diff --git a/src/Countries/Iran.php b/src/Countries/Iran.php new file mode 100644 index 000000000..0a36c196b --- /dev/null +++ b/src/Countries/Iran.php @@ -0,0 +1,40 @@ + '02-11', + 'Nationalization of Oil Industry Day' => '03-19', + 'Nowruz First Day' => '03-20', + 'Nowruz Second Day' => '03-21', + 'Nowruz Third Day' => '03-22', + 'Nowruz Fourth Day' => '03-23', + 'Islamic Republic Day' => '03-31', + 'Nature Day' => '04-01', + 'Death of Khomeini Day' => '06-03', + 'Revolt of Khordad 15 Day' => '06-04', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Asia/Tehran'); + + return [ + //add more holidays + ]; + } +} \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap b/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap new file mode 100644 index 000000000..98b64076e --- /dev/null +++ b/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Islamic Revolution Day", + "date": "2024-02-11" + }, + { + "name": "Nationalization of Oil Industry Day", + "date": "2024-03-19" + }, + { + "name": "Nowruz First Day", + "date": "2024-03-20" + }, + { + "name": "Nowruz Second Day", + "date": "2024-03-21" + }, + { + "name": "Nowruz Third Day", + "date": "2024-03-22" + }, + { + "name": "Nowruz Fourth Day", + "date": "2024-03-23" + }, + { + "name": "Islamic Republic Day", + "date": "2024-03-31" + }, + { + "name": "Nature Day", + "date": "2024-04-01" + }, + { + "name": "Death of Khomeini Day", + "date": "2024-06-03" + }, + { + "name": "Revolt of Khordad 15 Day", + "date": "2024-06-04" + } +] \ No newline at end of file diff --git a/tests/Countries/IranTest.php b/tests/Countries/IranTest.php new file mode 100644 index 000000000..2dc29017f --- /dev/null +++ b/tests/Countries/IranTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); \ No newline at end of file From 66bea7c0aa68ad7a7ce451c2e54bc1aee0bc0636 Mon Sep 17 00:00:00 2001 From: Ali Salehi Date: Thu, 1 Feb 2024 12:57:02 +0330 Subject: [PATCH 2/4] Add(lang): Iran Holidays --- lang/Iran/en/holidays.json | 12 ++++++++++++ lang/Iran/fa/holidays.json | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 lang/Iran/en/holidays.json create mode 100644 lang/Iran/fa/holidays.json diff --git a/lang/Iran/en/holidays.json b/lang/Iran/en/holidays.json new file mode 100644 index 000000000..d8ede9c05 --- /dev/null +++ b/lang/Iran/en/holidays.json @@ -0,0 +1,12 @@ +{ + "پیروزی انقلاب اسلامی پنجاه و هفت": "Anniversary of Islamic Revolution Day", + "روز ملی شدن صنعت نفت": "Nationalization of Oil Industry Day", + "نخستین روز نوروز": "Nowruz First Day", + "دومین روز نوروز": "Nowruz Second Day", + "سومین روز نوروز": "Nowruz Third Day", + "چهارمین روز نوروز": "Nowruz Fourth Day", + "روز جمهوری اسلامی": "Islamic Republic Day", + "سیزده بدر": "Sizdah Bedar", + "رحلت روح\u200Cالله خمینی": "Death of Khomeini Day", + "قیام ۱۵ خرداد": "Revolt of Khordad 15 Day" +} \ No newline at end of file diff --git a/lang/Iran/fa/holidays.json b/lang/Iran/fa/holidays.json new file mode 100644 index 000000000..a8f7a256b --- /dev/null +++ b/lang/Iran/fa/holidays.json @@ -0,0 +1,12 @@ +{ + "پیروزی انقلاب اسلامی پنجاه و هفت": "پیروزی انقلاب اسلامی پنجاه و هفت", + "روز ملی شدن صنعت نفت": "روز ملی شدن صنعت نفت", + "نخستین روز نوروز": "نخستین روز نوروز", + "دومین روز نوروز": "دومین روز نوروز", + "سومین روز نوروز": "سومین روز نوروز", + "چهارمین روز نوروز": "چهارمین روز نوروز", + "روز جمهوری اسلامی": "روز جمهوری اسلامی", + "سیزده بدر": "سیزده بدر", + "رحلت روح\u200Cالله خمینی": "رحلت روح\u200Cالله خمینی", + "قیام ۱۵ خرداد": "قیام ۱۵ خرداد" +} \ No newline at end of file From e4d2ecdedad62ba158459edde019dcc2ecd0f482 Mon Sep 17 00:00:00 2001 From: Ali Salehi Date: Thu, 1 Feb 2024 12:58:52 +0330 Subject: [PATCH 3/4] Fix(Countries): remove `variableHolidays` func | rename Iran Holidays to persian --- src/Countries/Iran.php | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/Countries/Iran.php b/src/Countries/Iran.php index 0a36c196b..981f5e618 100644 --- a/src/Countries/Iran.php +++ b/src/Countries/Iran.php @@ -13,28 +13,17 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge([ - 'Islamic Revolution Day' => '02-11', - 'Nationalization of Oil Industry Day' => '03-19', - 'Nowruz First Day' => '03-20', - 'Nowruz Second Day' => '03-21', - 'Nowruz Third Day' => '03-22', - 'Nowruz Fourth Day' => '03-23', - 'Islamic Republic Day' => '03-31', - 'Nature Day' => '04-01', - 'Death of Khomeini Day' => '06-03', - 'Revolt of Khordad 15 Day' => '06-04', - ], $this->variableHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Asia/Tehran'); - return [ - //add more holidays + 'پیروزی انقلاب اسلامی پنجاه و هفت' => '02-11', + 'روز ملی شدن صنعت نفت' => '03-19', + 'نخستین روز نوروز' => '03-20', + 'دومین روز نوروز' => '03-21', + 'سومین روز نوروز' => '03-22', + 'چهارمین روز نوروز' => '03-23', + 'روز جمهوری اسلامی' => '03-31', + 'سیزده بدر' => '04-01', + 'رحلت روح‌الله خمینی' => '06-03', + 'قیام ۱۵ خرداد' => '06-04', ]; } } \ No newline at end of file From a146daafffd17f3d912b1c9291eec32899aac753 Mon Sep 17 00:00:00 2001 From: Ali Salehi Date: Thu, 1 Feb 2024 13:00:07 +0330 Subject: [PATCH 4/4] Add(test): can calculate iran holidays in local | Change setTestNowAndTimezone to setTestNow --- .../it_can_calculate_iran_holidays.snap | 20 +++++++++---------- tests/Countries/IranTest.php | 17 ++++++++++++++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap b/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap index 98b64076e..9309cbd09 100644 --- a/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap +++ b/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap @@ -1,42 +1,42 @@ [ { - "name": "Islamic Revolution Day", + "name": "\u067e\u06cc\u0631\u0648\u0632\u06cc \u0627\u0646\u0642\u0644\u0627\u0628 \u0627\u0633\u0644\u0627\u0645\u06cc \u067e\u0646\u062c\u0627\u0647 \u0648 \u0647\u0641\u062a", "date": "2024-02-11" }, { - "name": "Nationalization of Oil Industry Day", + "name": "\u0631\u0648\u0632 \u0645\u0644\u06cc \u0634\u062f\u0646 \u0635\u0646\u0639\u062a \u0646\u0641\u062a", "date": "2024-03-19" }, { - "name": "Nowruz First Day", + "name": "\u0646\u062e\u0633\u062a\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", "date": "2024-03-20" }, { - "name": "Nowruz Second Day", + "name": "\u062f\u0648\u0645\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", "date": "2024-03-21" }, { - "name": "Nowruz Third Day", + "name": "\u0633\u0648\u0645\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", "date": "2024-03-22" }, { - "name": "Nowruz Fourth Day", + "name": "\u0686\u0647\u0627\u0631\u0645\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", "date": "2024-03-23" }, { - "name": "Islamic Republic Day", + "name": "\u0631\u0648\u0632 \u062c\u0645\u0647\u0648\u0631\u06cc \u0627\u0633\u0644\u0627\u0645\u06cc", "date": "2024-03-31" }, { - "name": "Nature Day", + "name": "\u0633\u06cc\u0632\u062f\u0647 \u0628\u062f\u0631", "date": "2024-04-01" }, { - "name": "Death of Khomeini Day", + "name": "\u0631\u062d\u0644\u062a \u0631\u0648\u062d\u200c\u0627\u0644\u0644\u0647 \u062e\u0645\u06cc\u0646\u06cc", "date": "2024-06-03" }, { - "name": "Revolt of Khordad 15 Day", + "name": "\u0642\u06cc\u0627\u0645 \u06f1\u06f5 \u062e\u0631\u062f\u0627\u062f", "date": "2024-06-04" } ] \ No newline at end of file diff --git a/tests/Countries/IranTest.php b/tests/Countries/IranTest.php index 2dc29017f..7ceb54944 100644 --- a/tests/Countries/IranTest.php +++ b/tests/Countries/IranTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate iran holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ir')->get(); @@ -15,4 +15,17 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); \ No newline at end of file +}); + +it('can calculate iran holidays in local', function (string $locale, string $newYearsDayName) { + CarbonImmutable::setTestNow('2024-01-01'); + $result = Holidays::for(country: 'ir', year: null, locale: $locale)->get(); + + expect($result)->toBeArray(); + expect($result[7]['name'])->toBe($newYearsDayName); +})->with( + [ + ['en', 'Sizdah Bedar'], + ['fa', 'سیزده بدر'], + ] +); \ No newline at end of file