From d7e353dfaa5b0157acce93001bbf127dbdd97bc9 Mon Sep 17 00:00:00 2001 From: maskeynihal <26411488+maskeynihal@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:32:12 +0545 Subject: [PATCH 1/5] feat: add calendar for Nepal --- src/Calendars/NepaliCalendar.php | 282 +++++++++++++++++++++++++++++++ src/Countries/Nepal.php | 25 +++ tests/Countries/NepalTest.php | 17 ++ 3 files changed, 324 insertions(+) create mode 100644 src/Calendars/NepaliCalendar.php create mode 100644 src/Countries/Nepal.php create mode 100644 tests/Countries/NepalTest.php diff --git a/src/Calendars/NepaliCalendar.php b/src/Calendars/NepaliCalendar.php new file mode 100644 index 00000000..ad0c3f3f --- /dev/null +++ b/src/Calendars/NepaliCalendar.php @@ -0,0 +1,282 @@ + 'Nepali New Year', + 'dates' => [ + 2024 => '04-13', + ], + ]; + + /** + * Celebrated on 15 Jestha - 02/15 of the Bikram Sambat calendar. + */ + public const nationalRepublicDay = [ + 'label' => 'National Republic Day', + 'dates' => [ + 2024 => '05-28', + ], + ]; + + /** + * Celebrated on 27 Paush - 09/27 of the Bikram Sambat calendar. + */ + public const prithiviJayanti = [ + 'label' => 'Prithivi Jayanti', + 'dates' => [ + 2025 => '01-11', + ], + ]; + + /** + * Celebrated on 16 Magh - 10/16 of the Bikram Sambat calendar. + */ + public const martyrsDay = [ + 'label' => "Martyrs' Day", + 'dates' => [ + 2025 => '01-29', + ], + ]; + + /** + * Celebrated on 7 Falgun - 11/07 of the Bikram Sambat calendar. + */ + public const democracyDay = [ + 'label' => 'Democracy Day', + 'dates' => [ + 2025 => '02-19', + ], + ]; + + /** + * Celebrated on 3 Ashwin - 04/03 of the Bikram Sambat calendar. + */ + public const constitutionDay = [ + 'label' => 'Constitution Day', + 'dates' => [ + 2024 => '09-19', + ], + ]; + + /** + * Celebrated on 1 Magh - 10/01 of the Bikram Sambat calendar. + */ + public const makarSankrantiHoliday = [ + 'label' => 'Makar Sankranti', + 'dates' => [ + 2025 => '01-14', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the first day of "Dashain" festival. + */ + public const ghatasthapanaHoliday = [ + 'label' => 'Ghatasthapana (Dashain)', + 'dates' => [ + 2024 => '10-03', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 7th day of "Dashain" festival. + */ + public const fulpatiHoliday = [ + 'label' => 'Fulpati (Dashain)', + 'dates' => [ + 2024 => '10-11', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 8th day of "Dashain" festival. + */ + public const mahaNawamiHoliday = [ + 'label' => 'Maha Nawami (Dashain)', + 'dates' => [ + 2024 => '10-12', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 9th day of "Dashain" festival. + */ + public const mahaAsthamiHoliday = [ + 'label' => 'Maha Asthami (Dashain)', + 'dates' => [ + 2024 => '10-12', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 10th day of "Dashain" festival. + */ + public const vijayaDashamiHoliday = [ + 'label' => 'Vijaya Dashami (Dashain)', + 'dates' => [ + 2024 => '10-13', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 11th day of "Dashain" festival. + */ + public const ekadashiHoliday = [ + 'label' => 'Ekadashi (Dashain)', + 'dates' => [ + 2024 => '10-14', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 3rd day of "Tihar" festival. + */ + public const laxmiPujaHoliday = [ + 'label' => 'Laxmi Puja (Tihar)', + 'dates' => [ + 2024 => '11-01', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 4th day of "Tihar" festival. + */ + public const govardhanPujaHoliday = [ + 'label' => 'Govardhan Puja / Mha Puja (Tihar)', + 'dates' => [ + 2024 => '11-02', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Celebrated on the 5th day of "Tihar" festival. + */ + public const bhaiTikaHoliday = [ + 'label' => 'Bhai Tika (Tihar)', + 'dates' => [ + 2024 => '11-03', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Chhat Parva is a festival dedicated to the Sun God. + */ + public const chhatParvaHoliday = [ + 'label' => 'Chhat Parva', + 'dates' => [ + 2024 => '11-07', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Tamu Loshar is the New Year of the Gurung community. + */ + public const tamuLosharHoliday = [ + 'label' => 'Tamu Loshar', + 'dates' => [ + 2024 => '12-30', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Sonam Losar is the New Year of the Tamang community. + */ + public const sonamLosarHoliday = [ + 'label' => 'Sonam Losar', + 'dates' => [ + 2025 => '01-30', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Gyalpo Loshar is the New Year of the Sherpa community. + */ + public const gyalpoLosharHoliday = [ + 'label' => 'Gyalpo Loshar', + 'dates' => [ + 2025 => '02-28', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Udhauli Parva is the festival of the Kirat community. + */ + public const udhauliParvaHoliday = [ + 'label' => 'Udhauli Parva', + 'dates' => [ + 2024 => '12-15', + ], + ]; + + /** + * Celebrated on according to lunar calendar. Mahashivaratri is a Hindu festival dedicated to Lord Shiva. + */ + public const mahashivaratriHoliday = [ + 'label' => 'Maha Shivaratri', + 'dates' => [ + 2025 => '02-26', + ], + ]; + + public const holiHoliday = [ + 'label' => 'Holi / Fagu Purnima', + 'dates' => [ + 2025 => '03-13', + ], + ]; + + public function holidaysAccordingToBikramSambatCalendar(int $year): array + { + $holidays = [ + self::nepaliNewYear['label'] => self::nepaliNewYear['dates'][$year] ?? null, + self::nationalRepublicDay['label'] => self::nationalRepublicDay['dates'][$year] ?? null, + self::prithiviJayanti['label'] => self::prithiviJayanti['dates'][$year] ?? null, + self::martyrsDay['label'] => self::martyrsDay['dates'][$year] ?? null, + self::democracyDay['label'] => self::democracyDay['dates'][$year] ?? null, + self::constitutionDay['label'] => self::constitutionDay['dates'][$year] ?? null, + self::makarSankrantiHoliday['label'] => self::makarSankrantiHoliday['dates'][$year] ?? null, + ]; + + return array_filter($holidays, fn ($holiday) => $holiday !== null); + } + + public function holidaysAccordingToLunarCalendar(int $year): array + { + $holidays = [ + self::ghatasthapanaHoliday['label'] => self::ghatasthapanaHoliday['dates'][$year] ?? null, + self::fulpatiHoliday['label'] => self::fulpatiHoliday['dates'][$year] ?? null, + self::mahaNawamiHoliday['label'] => self::mahaNawamiHoliday['dates'][$year] ?? null, + self::mahaAsthamiHoliday['label'] => self::mahaAsthamiHoliday['dates'][$year] ?? null, + self::vijayaDashamiHoliday['label'] => self::vijayaDashamiHoliday['dates'][$year] ?? null, + self::ekadashiHoliday['label'] => self::ekadashiHoliday['dates'][$year] ?? null, + ]; + + return array_filter($holidays, fn ($holiday) => $holiday !== null); + } + + /** + * Holiday according to Gregorian calendar. + * + * @return array + */ + public function holidayAccordingToGregorianCalendar(): array + { + return [ + 'International Labor Day' => '05-01', + 'Christmas' => '12-25', + ]; + } +} diff --git a/src/Countries/Nepal.php b/src/Countries/Nepal.php new file mode 100644 index 00000000..24ce152a --- /dev/null +++ b/src/Countries/Nepal.php @@ -0,0 +1,25 @@ +holidayAccordingToGregorianCalendar(), $this->variableHolidays($year)); + } + + public function variableHolidays(int $year): array + { + return array_merge($this->holidaysAccordingToBikramSambatCalendar($year), $this->holidaysAccordingToLunarCalendar($year)); + } +} diff --git a/tests/Countries/NepalTest.php b/tests/Countries/NepalTest.php new file mode 100644 index 00000000..5d99a72c --- /dev/null +++ b/tests/Countries/NepalTest.php @@ -0,0 +1,17 @@ +get(year: 2024); + + expect($holidays)->toBeArray()->not->toBeEmpty(); +}); + +it('provides holiday at least according to Bikram Sambat Calendar', function () { + $holidays = Holidays::for(country: 'np')->get(year: 2025); + + expect($holidays)->toBeArray()->not->toBeEmpty(); +}); From 63b24348de89b3744052d234c83a0e65d8289b75 Mon Sep 17 00:00:00 2001 From: maskeynihal <26411488+maskeynihal@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:39:17 +0545 Subject: [PATCH 2/5] chore: add snapshot test for Nepal --- src/Calendars/NepaliCalendar.php | 33 +++++++++ ...ovides_holiday_for_Nepal_in_year_2024.snap | 70 +++++++++++++++++++ tests/Countries/NepalTest.php | 10 +++ 3 files changed, 113 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/NepalTest/it_provides_holiday_for_Nepal_in_year_2024.snap diff --git a/src/Calendars/NepaliCalendar.php b/src/Calendars/NepaliCalendar.php index ad0c3f3f..7dd884c3 100644 --- a/src/Calendars/NepaliCalendar.php +++ b/src/Calendars/NepaliCalendar.php @@ -15,6 +15,7 @@ trait NepaliCalendar * Celebrated on the first day of the Bikram Sambat calendar. (Baishakh - 01/01) */ public const nepaliNewYear = [ + 'calendar' => 'Bikram Sambat', 'label' => 'Nepali New Year', 'dates' => [ 2024 => '04-13', @@ -25,6 +26,7 @@ trait NepaliCalendar * Celebrated on 15 Jestha - 02/15 of the Bikram Sambat calendar. */ public const nationalRepublicDay = [ + 'calendar' => 'Bikram Sambat', 'label' => 'National Republic Day', 'dates' => [ 2024 => '05-28', @@ -35,6 +37,7 @@ trait NepaliCalendar * Celebrated on 27 Paush - 09/27 of the Bikram Sambat calendar. */ public const prithiviJayanti = [ + 'calendar' => 'Bikram Sambat', 'label' => 'Prithivi Jayanti', 'dates' => [ 2025 => '01-11', @@ -45,6 +48,7 @@ trait NepaliCalendar * Celebrated on 16 Magh - 10/16 of the Bikram Sambat calendar. */ public const martyrsDay = [ + 'calendar' => 'Bikram Sambat', 'label' => "Martyrs' Day", 'dates' => [ 2025 => '01-29', @@ -55,6 +59,7 @@ trait NepaliCalendar * Celebrated on 7 Falgun - 11/07 of the Bikram Sambat calendar. */ public const democracyDay = [ + 'calendar' => 'Bikram Sambat', 'label' => 'Democracy Day', 'dates' => [ 2025 => '02-19', @@ -65,6 +70,7 @@ trait NepaliCalendar * Celebrated on 3 Ashwin - 04/03 of the Bikram Sambat calendar. */ public const constitutionDay = [ + 'calendar' => 'Bikram Sambat', 'label' => 'Constitution Day', 'dates' => [ 2024 => '09-19', @@ -75,6 +81,7 @@ trait NepaliCalendar * Celebrated on 1 Magh - 10/01 of the Bikram Sambat calendar. */ public const makarSankrantiHoliday = [ + 'calendar' => 'Bikram Sambat', 'label' => 'Makar Sankranti', 'dates' => [ 2025 => '01-14', @@ -85,6 +92,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the first day of "Dashain" festival. */ public const ghatasthapanaHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Ghatasthapana (Dashain)', 'dates' => [ 2024 => '10-03', @@ -95,6 +103,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 7th day of "Dashain" festival. */ public const fulpatiHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Fulpati (Dashain)', 'dates' => [ 2024 => '10-11', @@ -105,6 +114,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 8th day of "Dashain" festival. */ public const mahaNawamiHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Maha Nawami (Dashain)', 'dates' => [ 2024 => '10-12', @@ -115,6 +125,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 9th day of "Dashain" festival. */ public const mahaAsthamiHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Maha Asthami (Dashain)', 'dates' => [ 2024 => '10-12', @@ -125,6 +136,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 10th day of "Dashain" festival. */ public const vijayaDashamiHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Vijaya Dashami (Dashain)', 'dates' => [ 2024 => '10-13', @@ -135,6 +147,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 11th day of "Dashain" festival. */ public const ekadashiHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Ekadashi (Dashain)', 'dates' => [ 2024 => '10-14', @@ -145,6 +158,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 3rd day of "Tihar" festival. */ public const laxmiPujaHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Laxmi Puja (Tihar)', 'dates' => [ 2024 => '11-01', @@ -155,6 +169,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 4th day of "Tihar" festival. */ public const govardhanPujaHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Govardhan Puja / Mha Puja (Tihar)', 'dates' => [ 2024 => '11-02', @@ -165,6 +180,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Celebrated on the 5th day of "Tihar" festival. */ public const bhaiTikaHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Bhai Tika (Tihar)', 'dates' => [ 2024 => '11-03', @@ -175,6 +191,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Chhat Parva is a festival dedicated to the Sun God. */ public const chhatParvaHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Chhat Parva', 'dates' => [ 2024 => '11-07', @@ -185,6 +202,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Tamu Loshar is the New Year of the Gurung community. */ public const tamuLosharHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Tamu Loshar', 'dates' => [ 2024 => '12-30', @@ -195,6 +213,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Sonam Losar is the New Year of the Tamang community. */ public const sonamLosarHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Sonam Losar', 'dates' => [ 2025 => '01-30', @@ -205,6 +224,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Gyalpo Loshar is the New Year of the Sherpa community. */ public const gyalpoLosharHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Gyalpo Loshar', 'dates' => [ 2025 => '02-28', @@ -215,6 +235,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Udhauli Parva is the festival of the Kirat community. */ public const udhauliParvaHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Udhauli Parva', 'dates' => [ 2024 => '12-15', @@ -225,6 +246,7 @@ trait NepaliCalendar * Celebrated on according to lunar calendar. Mahashivaratri is a Hindu festival dedicated to Lord Shiva. */ public const mahashivaratriHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Maha Shivaratri', 'dates' => [ 2025 => '02-26', @@ -232,6 +254,7 @@ trait NepaliCalendar ]; public const holiHoliday = [ + 'calendar' => 'Lunar Calendar', 'label' => 'Holi / Fagu Purnima', 'dates' => [ 2025 => '03-13', @@ -262,6 +285,16 @@ public function holidaysAccordingToLunarCalendar(int $year): array self::mahaAsthamiHoliday['label'] => self::mahaAsthamiHoliday['dates'][$year] ?? null, self::vijayaDashamiHoliday['label'] => self::vijayaDashamiHoliday['dates'][$year] ?? null, self::ekadashiHoliday['label'] => self::ekadashiHoliday['dates'][$year] ?? null, + self::laxmiPujaHoliday['label'] => self::laxmiPujaHoliday['dates'][$year] ?? null, + self::govardhanPujaHoliday['label'] => self::govardhanPujaHoliday['dates'][$year] ?? null, + self::bhaiTikaHoliday['label'] => self::bhaiTikaHoliday['dates'][$year] ?? null, + self::chhatParvaHoliday['label'] => self::chhatParvaHoliday['dates'][$year] ?? null, + self::tamuLosharHoliday['label'] => self::tamuLosharHoliday['dates'][$year] ?? null, + self::sonamLosarHoliday['label'] => self::sonamLosarHoliday['dates'][$year] ?? null, + self::gyalpoLosharHoliday['label'] => self::gyalpoLosharHoliday['dates'][$year] ?? null, + self::udhauliParvaHoliday['label'] => self::udhauliParvaHoliday['dates'][$year] ?? null, + self::mahashivaratriHoliday['label'] => self::mahashivaratriHoliday['dates'][$year] ?? null, + self::holiHoliday['label'] => self::holiHoliday['dates'][$year] ?? null, ]; return array_filter($holidays, fn ($holiday) => $holiday !== null); diff --git a/tests/.pest/snapshots/Countries/NepalTest/it_provides_holiday_for_Nepal_in_year_2024.snap b/tests/.pest/snapshots/Countries/NepalTest/it_provides_holiday_for_Nepal_in_year_2024.snap new file mode 100644 index 00000000..ce4dbb32 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NepalTest/it_provides_holiday_for_Nepal_in_year_2024.snap @@ -0,0 +1,70 @@ +[ + { + "name": "Nepali New Year", + "date": "2024-04-13" + }, + { + "name": "International Labor Day", + "date": "2024-05-01" + }, + { + "name": "National Republic Day", + "date": "2024-05-28" + }, + { + "name": "Constitution Day", + "date": "2024-09-19" + }, + { + "name": "Ghatasthapana (Dashain)", + "date": "2024-10-03" + }, + { + "name": "Fulpati (Dashain)", + "date": "2024-10-11" + }, + { + "name": "Maha Nawami (Dashain)", + "date": "2024-10-12" + }, + { + "name": "Maha Asthami (Dashain)", + "date": "2024-10-12" + }, + { + "name": "Vijaya Dashami (Dashain)", + "date": "2024-10-13" + }, + { + "name": "Ekadashi (Dashain)", + "date": "2024-10-14" + }, + { + "name": "Laxmi Puja (Tihar)", + "date": "2024-11-01" + }, + { + "name": "Govardhan Puja \/ Mha Puja (Tihar)", + "date": "2024-11-02" + }, + { + "name": "Bhai Tika (Tihar)", + "date": "2024-11-03" + }, + { + "name": "Chhat Parva", + "date": "2024-11-07" + }, + { + "name": "Udhauli Parva", + "date": "2024-12-15" + }, + { + "name": "Christmas", + "date": "2024-12-25" + }, + { + "name": "Tamu Loshar", + "date": "2024-12-30" + } +] \ No newline at end of file diff --git a/tests/Countries/NepalTest.php b/tests/Countries/NepalTest.php index 5d99a72c..b1bf9883 100644 --- a/tests/Countries/NepalTest.php +++ b/tests/Countries/NepalTest.php @@ -15,3 +15,13 @@ expect($holidays)->toBeArray()->not->toBeEmpty(); }); + +it('provides holiday for Nepal in year 2024', function () { + $holidays = Holidays::for(country: 'np')->get(year: 2024); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 77405c5c21c6a87c57a0661be59017158469900e Mon Sep 17 00:00:00 2001 From: maskeynihal <26411488+maskeynihal@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:46:26 +0545 Subject: [PATCH 3/5] chore: add test for checking holiday on specific date --- tests/Countries/NepalTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Countries/NepalTest.php b/tests/Countries/NepalTest.php index b1bf9883..d0d2681c 100644 --- a/tests/Countries/NepalTest.php +++ b/tests/Countries/NepalTest.php @@ -25,3 +25,9 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('checks for holidays in Nepal for 2025', function () { + $isHoliday = Holidays::for('np')->isHoliday('2025-03-13'); + + expect($isHoliday)->toBeTrue(); +}); From db11650377e46605d32839bf093e3787893f3254 Mon Sep 17 00:00:00 2001 From: maskeynihal <26411488+maskeynihal@users.noreply.github.com> Date: Sat, 19 Oct 2024 00:43:29 +0545 Subject: [PATCH 4/5] chore: convert const to variable in trait --- src/Calendars/NepaliCalendar.php | 101 +++++++++++++++++-------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/src/Calendars/NepaliCalendar.php b/src/Calendars/NepaliCalendar.php index 7dd884c3..ce177de6 100644 --- a/src/Calendars/NepaliCalendar.php +++ b/src/Calendars/NepaliCalendar.php @@ -14,7 +14,7 @@ trait NepaliCalendar /** * Celebrated on the first day of the Bikram Sambat calendar. (Baishakh - 01/01) */ - public const nepaliNewYear = [ + public array $nepaliNewYear = [ 'calendar' => 'Bikram Sambat', 'label' => 'Nepali New Year', 'dates' => [ @@ -25,7 +25,7 @@ trait NepaliCalendar /** * Celebrated on 15 Jestha - 02/15 of the Bikram Sambat calendar. */ - public const nationalRepublicDay = [ + public array $nationalRepublicDay = [ 'calendar' => 'Bikram Sambat', 'label' => 'National Republic Day', 'dates' => [ @@ -36,7 +36,7 @@ trait NepaliCalendar /** * Celebrated on 27 Paush - 09/27 of the Bikram Sambat calendar. */ - public const prithiviJayanti = [ + public array $prithiviJayanti = [ 'calendar' => 'Bikram Sambat', 'label' => 'Prithivi Jayanti', 'dates' => [ @@ -47,7 +47,7 @@ trait NepaliCalendar /** * Celebrated on 16 Magh - 10/16 of the Bikram Sambat calendar. */ - public const martyrsDay = [ + public array $martyrsDay = [ 'calendar' => 'Bikram Sambat', 'label' => "Martyrs' Day", 'dates' => [ @@ -58,7 +58,7 @@ trait NepaliCalendar /** * Celebrated on 7 Falgun - 11/07 of the Bikram Sambat calendar. */ - public const democracyDay = [ + public array $democracyDay = [ 'calendar' => 'Bikram Sambat', 'label' => 'Democracy Day', 'dates' => [ @@ -69,7 +69,7 @@ trait NepaliCalendar /** * Celebrated on 3 Ashwin - 04/03 of the Bikram Sambat calendar. */ - public const constitutionDay = [ + public array $constitutionDay = [ 'calendar' => 'Bikram Sambat', 'label' => 'Constitution Day', 'dates' => [ @@ -80,7 +80,7 @@ trait NepaliCalendar /** * Celebrated on 1 Magh - 10/01 of the Bikram Sambat calendar. */ - public const makarSankrantiHoliday = [ + public array $makarSankrantiHoliday = [ 'calendar' => 'Bikram Sambat', 'label' => 'Makar Sankranti', 'dates' => [ @@ -91,7 +91,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the first day of "Dashain" festival. */ - public const ghatasthapanaHoliday = [ + public array $ghatasthapanaHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Ghatasthapana (Dashain)', 'dates' => [ @@ -102,7 +102,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 7th day of "Dashain" festival. */ - public const fulpatiHoliday = [ + public array $fulpatiHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Fulpati (Dashain)', 'dates' => [ @@ -113,7 +113,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 8th day of "Dashain" festival. */ - public const mahaNawamiHoliday = [ + public array $mahaNawamiHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Maha Nawami (Dashain)', 'dates' => [ @@ -124,7 +124,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 9th day of "Dashain" festival. */ - public const mahaAsthamiHoliday = [ + public array $mahaAsthamiHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Maha Asthami (Dashain)', 'dates' => [ @@ -135,7 +135,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 10th day of "Dashain" festival. */ - public const vijayaDashamiHoliday = [ + public array $vijayaDashamiHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Vijaya Dashami (Dashain)', 'dates' => [ @@ -146,7 +146,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 11th day of "Dashain" festival. */ - public const ekadashiHoliday = [ + public array $ekadashiHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Ekadashi (Dashain)', 'dates' => [ @@ -157,7 +157,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 3rd day of "Tihar" festival. */ - public const laxmiPujaHoliday = [ + public array $laxmiPujaHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Laxmi Puja (Tihar)', 'dates' => [ @@ -168,7 +168,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 4th day of "Tihar" festival. */ - public const govardhanPujaHoliday = [ + public array $govardhanPujaHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Govardhan Puja / Mha Puja (Tihar)', 'dates' => [ @@ -179,7 +179,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 5th day of "Tihar" festival. */ - public const bhaiTikaHoliday = [ + public array $bhaiTikaHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Bhai Tika (Tihar)', 'dates' => [ @@ -190,7 +190,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Chhat Parva is a festival dedicated to the Sun God. */ - public const chhatParvaHoliday = [ + public array $chhatParvaHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Chhat Parva', 'dates' => [ @@ -201,7 +201,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Tamu Loshar is the New Year of the Gurung community. */ - public const tamuLosharHoliday = [ + public array $tamuLosharHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Tamu Loshar', 'dates' => [ @@ -212,7 +212,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Sonam Losar is the New Year of the Tamang community. */ - public const sonamLosarHoliday = [ + public array $sonamLosarHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Sonam Losar', 'dates' => [ @@ -223,7 +223,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Gyalpo Loshar is the New Year of the Sherpa community. */ - public const gyalpoLosharHoliday = [ + public array $gyalpoLosharHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Gyalpo Loshar', 'dates' => [ @@ -234,7 +234,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Udhauli Parva is the festival of the Kirat community. */ - public const udhauliParvaHoliday = [ + public array $udhauliParvaHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Udhauli Parva', 'dates' => [ @@ -245,7 +245,7 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Mahashivaratri is a Hindu festival dedicated to Lord Shiva. */ - public const mahashivaratriHoliday = [ + public array $mahashivaratriHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Maha Shivaratri', 'dates' => [ @@ -253,7 +253,10 @@ trait NepaliCalendar ], ]; - public const holiHoliday = [ + /** + * Celebrated on according to lunar calendar. + */ + public array $holiHoliday = [ 'calendar' => 'Lunar Calendar', 'label' => 'Holi / Fagu Purnima', 'dates' => [ @@ -261,40 +264,46 @@ trait NepaliCalendar ], ]; + /** + * Holidays according to Bikram Sambat calendar. + */ public function holidaysAccordingToBikramSambatCalendar(int $year): array { $holidays = [ - self::nepaliNewYear['label'] => self::nepaliNewYear['dates'][$year] ?? null, - self::nationalRepublicDay['label'] => self::nationalRepublicDay['dates'][$year] ?? null, - self::prithiviJayanti['label'] => self::prithiviJayanti['dates'][$year] ?? null, - self::martyrsDay['label'] => self::martyrsDay['dates'][$year] ?? null, - self::democracyDay['label'] => self::democracyDay['dates'][$year] ?? null, - self::constitutionDay['label'] => self::constitutionDay['dates'][$year] ?? null, - self::makarSankrantiHoliday['label'] => self::makarSankrantiHoliday['dates'][$year] ?? null, + $this->nepaliNewYear['label'] => $this->nepaliNewYear['dates'][$year] ?? null, + $this->nationalRepublicDay['label'] => $this->nationalRepublicDay['dates'][$year] ?? null, + $this->prithiviJayanti['label'] => $this->prithiviJayanti['dates'][$year] ?? null, + $this->martyrsDay['label'] => $this->martyrsDay['dates'][$year] ?? null, + $this->democracyDay['label'] => $this->democracyDay['dates'][$year] ?? null, + $this->constitutionDay['label'] => $this->constitutionDay['dates'][$year] ?? null, + $this->makarSankrantiHoliday['label'] => $this->makarSankrantiHoliday['dates'][$year] ?? null, ]; return array_filter($holidays, fn ($holiday) => $holiday !== null); } + /** + * Holidays according to lunar calendar. + */ public function holidaysAccordingToLunarCalendar(int $year): array { $holidays = [ - self::ghatasthapanaHoliday['label'] => self::ghatasthapanaHoliday['dates'][$year] ?? null, - self::fulpatiHoliday['label'] => self::fulpatiHoliday['dates'][$year] ?? null, - self::mahaNawamiHoliday['label'] => self::mahaNawamiHoliday['dates'][$year] ?? null, - self::mahaAsthamiHoliday['label'] => self::mahaAsthamiHoliday['dates'][$year] ?? null, - self::vijayaDashamiHoliday['label'] => self::vijayaDashamiHoliday['dates'][$year] ?? null, - self::ekadashiHoliday['label'] => self::ekadashiHoliday['dates'][$year] ?? null, - self::laxmiPujaHoliday['label'] => self::laxmiPujaHoliday['dates'][$year] ?? null, - self::govardhanPujaHoliday['label'] => self::govardhanPujaHoliday['dates'][$year] ?? null, - self::bhaiTikaHoliday['label'] => self::bhaiTikaHoliday['dates'][$year] ?? null, - self::chhatParvaHoliday['label'] => self::chhatParvaHoliday['dates'][$year] ?? null, - self::tamuLosharHoliday['label'] => self::tamuLosharHoliday['dates'][$year] ?? null, - self::sonamLosarHoliday['label'] => self::sonamLosarHoliday['dates'][$year] ?? null, - self::gyalpoLosharHoliday['label'] => self::gyalpoLosharHoliday['dates'][$year] ?? null, - self::udhauliParvaHoliday['label'] => self::udhauliParvaHoliday['dates'][$year] ?? null, - self::mahashivaratriHoliday['label'] => self::mahashivaratriHoliday['dates'][$year] ?? null, - self::holiHoliday['label'] => self::holiHoliday['dates'][$year] ?? null, + $this->ghatasthapanaHoliday['label'] => $this->ghatasthapanaHoliday['dates'][$year] ?? null, + $this->fulpatiHoliday['label'] => $this->fulpatiHoliday['dates'][$year] ?? null, + $this->mahaNawamiHoliday['label'] => $this->mahaNawamiHoliday['dates'][$year] ?? null, + $this->mahaAsthamiHoliday['label'] => $this->mahaAsthamiHoliday['dates'][$year] ?? null, + $this->vijayaDashamiHoliday['label'] => $this->vijayaDashamiHoliday['dates'][$year] ?? null, + $this->ekadashiHoliday['label'] => $this->ekadashiHoliday['dates'][$year] ?? null, + $this->laxmiPujaHoliday['label'] => $this->laxmiPujaHoliday['dates'][$year] ?? null, + $this->govardhanPujaHoliday['label'] => $this->govardhanPujaHoliday['dates'][$year] ?? null, + $this->bhaiTikaHoliday['label'] => $this->bhaiTikaHoliday['dates'][$year] ?? null, + $this->chhatParvaHoliday['label'] => $this->chhatParvaHoliday['dates'][$year] ?? null, + $this->tamuLosharHoliday['label'] => $this->tamuLosharHoliday['dates'][$year] ?? null, + $this->sonamLosarHoliday['label'] => $this->sonamLosarHoliday['dates'][$year] ?? null, + $this->gyalpoLosharHoliday['label'] => $this->gyalpoLosharHoliday['dates'][$year] ?? null, + $this->udhauliParvaHoliday['label'] => $this->udhauliParvaHoliday['dates'][$year] ?? null, + $this->mahashivaratriHoliday['label'] => $this->mahashivaratriHoliday['dates'][$year] ?? null, + $this->holiHoliday['label'] => $this->holiHoliday['dates'][$year] ?? null, ]; return array_filter($holidays, fn ($holiday) => $holiday !== null); From 7af348941dcce3a349f37e0e3ec0f5dffb0e5690 Mon Sep 17 00:00:00 2001 From: maskeynihal <26411488+maskeynihal@users.noreply.github.com> Date: Sat, 19 Oct 2024 01:01:58 +0545 Subject: [PATCH 5/5] chore: add type for function and variable --- src/Calendars/NepaliCalendar.php | 144 ++++++++++++++++++++++++++++++- src/Countries/Nepal.php | 6 +- 2 files changed, 147 insertions(+), 3 deletions(-) diff --git a/src/Calendars/NepaliCalendar.php b/src/Calendars/NepaliCalendar.php index ce177de6..4aeaa49b 100644 --- a/src/Calendars/NepaliCalendar.php +++ b/src/Calendars/NepaliCalendar.php @@ -13,6 +13,12 @@ trait NepaliCalendar /** * Celebrated on the first day of the Bikram Sambat calendar. (Baishakh - 01/01) + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $nepaliNewYear = [ 'calendar' => 'Bikram Sambat', @@ -24,6 +30,12 @@ trait NepaliCalendar /** * Celebrated on 15 Jestha - 02/15 of the Bikram Sambat calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $nationalRepublicDay = [ 'calendar' => 'Bikram Sambat', @@ -35,6 +47,12 @@ trait NepaliCalendar /** * Celebrated on 27 Paush - 09/27 of the Bikram Sambat calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $prithiviJayanti = [ 'calendar' => 'Bikram Sambat', @@ -46,6 +64,12 @@ trait NepaliCalendar /** * Celebrated on 16 Magh - 10/16 of the Bikram Sambat calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $martyrsDay = [ 'calendar' => 'Bikram Sambat', @@ -57,6 +81,12 @@ trait NepaliCalendar /** * Celebrated on 7 Falgun - 11/07 of the Bikram Sambat calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $democracyDay = [ 'calendar' => 'Bikram Sambat', @@ -68,6 +98,12 @@ trait NepaliCalendar /** * Celebrated on 3 Ashwin - 04/03 of the Bikram Sambat calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $constitutionDay = [ 'calendar' => 'Bikram Sambat', @@ -79,6 +115,12 @@ trait NepaliCalendar /** * Celebrated on 1 Magh - 10/01 of the Bikram Sambat calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $makarSankrantiHoliday = [ 'calendar' => 'Bikram Sambat', @@ -90,6 +132,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the first day of "Dashain" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $ghatasthapanaHoliday = [ 'calendar' => 'Lunar Calendar', @@ -101,6 +149,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 7th day of "Dashain" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $fulpatiHoliday = [ 'calendar' => 'Lunar Calendar', @@ -112,6 +166,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 8th day of "Dashain" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $mahaNawamiHoliday = [ 'calendar' => 'Lunar Calendar', @@ -123,6 +183,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 9th day of "Dashain" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $mahaAsthamiHoliday = [ 'calendar' => 'Lunar Calendar', @@ -134,6 +200,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 10th day of "Dashain" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $vijayaDashamiHoliday = [ 'calendar' => 'Lunar Calendar', @@ -145,6 +217,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 11th day of "Dashain" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $ekadashiHoliday = [ 'calendar' => 'Lunar Calendar', @@ -156,6 +234,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 3rd day of "Tihar" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $laxmiPujaHoliday = [ 'calendar' => 'Lunar Calendar', @@ -167,6 +251,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 4th day of "Tihar" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $govardhanPujaHoliday = [ 'calendar' => 'Lunar Calendar', @@ -178,6 +268,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Celebrated on the 5th day of "Tihar" festival. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $bhaiTikaHoliday = [ 'calendar' => 'Lunar Calendar', @@ -189,6 +285,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Chhat Parva is a festival dedicated to the Sun God. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $chhatParvaHoliday = [ 'calendar' => 'Lunar Calendar', @@ -200,6 +302,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Tamu Loshar is the New Year of the Gurung community. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $tamuLosharHoliday = [ 'calendar' => 'Lunar Calendar', @@ -211,6 +319,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Sonam Losar is the New Year of the Tamang community. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $sonamLosarHoliday = [ 'calendar' => 'Lunar Calendar', @@ -222,6 +336,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Gyalpo Loshar is the New Year of the Sherpa community. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $gyalpoLosharHoliday = [ 'calendar' => 'Lunar Calendar', @@ -233,6 +353,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Udhauli Parva is the festival of the Kirat community. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $udhauliParvaHoliday = [ 'calendar' => 'Lunar Calendar', @@ -244,6 +370,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. Mahashivaratri is a Hindu festival dedicated to Lord Shiva. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $mahashivaratriHoliday = [ 'calendar' => 'Lunar Calendar', @@ -255,6 +387,12 @@ trait NepaliCalendar /** * Celebrated on according to lunar calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } */ public array $holiHoliday = [ 'calendar' => 'Lunar Calendar', @@ -266,6 +404,8 @@ trait NepaliCalendar /** * Holidays according to Bikram Sambat calendar. + * + * @return array */ public function holidaysAccordingToBikramSambatCalendar(int $year): array { @@ -284,6 +424,8 @@ public function holidaysAccordingToBikramSambatCalendar(int $year): array /** * Holidays according to lunar calendar. + * + * @return array */ public function holidaysAccordingToLunarCalendar(int $year): array { @@ -312,7 +454,7 @@ public function holidaysAccordingToLunarCalendar(int $year): array /** * Holiday according to Gregorian calendar. * - * @return array + * @return array */ public function holidayAccordingToGregorianCalendar(): array { diff --git a/src/Countries/Nepal.php b/src/Countries/Nepal.php index 24ce152a..e680c081 100644 --- a/src/Countries/Nepal.php +++ b/src/Countries/Nepal.php @@ -13,12 +13,14 @@ public function countryCode(): string return 'np'; } - public function allHolidays(int $year): array + /** @return array */ + protected function allHolidays(int $year): array { return array_merge($this->holidayAccordingToGregorianCalendar(), $this->variableHolidays($year)); } - public function variableHolidays(int $year): array + /** @return array */ + protected function variableHolidays(int $year): array { return array_merge($this->holidaysAccordingToBikramSambatCalendar($year), $this->holidaysAccordingToLunarCalendar($year)); }