From 608ed0df1d353a9783d70204145591b07ea7f3b9 Mon Sep 17 00:00:00 2001 From: Nihal Maskey <26411488+maskeynihal@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:12:17 +0545 Subject: [PATCH] feat: add calendar for Nepal (#247) * feat: add calendar for Nepal * chore: add snapshot test for Nepal * chore: add test for checking holiday on specific date * chore: convert const to variable in trait * chore: add type for function and variable --- src/Calendars/NepaliCalendar.php | 466 ++++++++++++++++++ src/Countries/Nepal.php | 27 + ...ovides_holiday_for_Nepal_in_year_2024.snap | 70 +++ tests/Countries/NepalTest.php | 33 ++ 4 files changed, 596 insertions(+) create mode 100644 src/Calendars/NepaliCalendar.php create mode 100644 src/Countries/Nepal.php create mode 100644 tests/.pest/snapshots/Countries/NepalTest/it_provides_holiday_for_Nepal_in_year_2024.snap 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..4aeaa49b --- /dev/null +++ b/src/Calendars/NepaliCalendar.php @@ -0,0 +1,466 @@ + + * } + */ + public array $nepaliNewYear = [ + 'calendar' => 'Bikram Sambat', + 'label' => 'Nepali New Year', + 'dates' => [ + 2024 => '04-13', + ], + ]; + + /** + * 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', + 'label' => 'National Republic Day', + 'dates' => [ + 2024 => '05-28', + ], + ]; + + /** + * 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', + 'label' => 'Prithivi Jayanti', + 'dates' => [ + 2025 => '01-11', + ], + ]; + + /** + * 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', + 'label' => "Martyrs' Day", + 'dates' => [ + 2025 => '01-29', + ], + ]; + + /** + * 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', + 'label' => 'Democracy Day', + 'dates' => [ + 2025 => '02-19', + ], + ]; + + /** + * 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', + 'label' => 'Constitution Day', + 'dates' => [ + 2024 => '09-19', + ], + ]; + + /** + * 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', + 'label' => 'Makar Sankranti', + 'dates' => [ + 2025 => '01-14', + ], + ]; + + /** + * 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', + 'label' => 'Ghatasthapana (Dashain)', + 'dates' => [ + 2024 => '10-03', + ], + ]; + + /** + * 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', + 'label' => 'Fulpati (Dashain)', + 'dates' => [ + 2024 => '10-11', + ], + ]; + + /** + * 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', + 'label' => 'Maha Nawami (Dashain)', + 'dates' => [ + 2024 => '10-12', + ], + ]; + + /** + * 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', + 'label' => 'Maha Asthami (Dashain)', + 'dates' => [ + 2024 => '10-12', + ], + ]; + + /** + * 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', + 'label' => 'Vijaya Dashami (Dashain)', + 'dates' => [ + 2024 => '10-13', + ], + ]; + + /** + * 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', + 'label' => 'Ekadashi (Dashain)', + 'dates' => [ + 2024 => '10-14', + ], + ]; + + /** + * 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', + 'label' => 'Laxmi Puja (Tihar)', + 'dates' => [ + 2024 => '11-01', + ], + ]; + + /** + * 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', + 'label' => 'Govardhan Puja / Mha Puja (Tihar)', + 'dates' => [ + 2024 => '11-02', + ], + ]; + + /** + * 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', + 'label' => 'Bhai Tika (Tihar)', + 'dates' => [ + 2024 => '11-03', + ], + ]; + + /** + * 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', + 'label' => 'Chhat Parva', + 'dates' => [ + 2024 => '11-07', + ], + ]; + + /** + * 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', + 'label' => 'Tamu Loshar', + 'dates' => [ + 2024 => '12-30', + ], + ]; + + /** + * 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', + 'label' => 'Sonam Losar', + 'dates' => [ + 2025 => '01-30', + ], + ]; + + /** + * 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', + 'label' => 'Gyalpo Loshar', + 'dates' => [ + 2025 => '02-28', + ], + ]; + + /** + * 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', + 'label' => 'Udhauli Parva', + 'dates' => [ + 2024 => '12-15', + ], + ]; + + /** + * 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', + 'label' => 'Maha Shivaratri', + 'dates' => [ + 2025 => '02-26', + ], + ]; + + /** + * Celebrated on according to lunar calendar. + * + * @var array{ + * calendar: string, + * label: string, + * dates: array + * } + */ + public array $holiHoliday = [ + 'calendar' => 'Lunar Calendar', + 'label' => 'Holi / Fagu Purnima', + 'dates' => [ + 2025 => '03-13', + ], + ]; + + /** + * Holidays according to Bikram Sambat calendar. + * + * @return array + */ + public function holidaysAccordingToBikramSambatCalendar(int $year): array + { + $holidays = [ + $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. + * + * @return array + */ + public function holidaysAccordingToLunarCalendar(int $year): array + { + $holidays = [ + $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); + } + + /** + * 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..e680c081 --- /dev/null +++ b/src/Countries/Nepal.php @@ -0,0 +1,27 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge($this->holidayAccordingToGregorianCalendar(), $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + return array_merge($this->holidaysAccordingToBikramSambatCalendar($year), $this->holidaysAccordingToLunarCalendar($year)); + } +} 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 new file mode 100644 index 00000000..d0d2681c --- /dev/null +++ b/tests/Countries/NepalTest.php @@ -0,0 +1,33 @@ +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(); +}); + +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(); +}); + +it('checks for holidays in Nepal for 2025', function () { + $isHoliday = Holidays::for('np')->isHoliday('2025-03-13'); + + expect($isHoliday)->toBeTrue(); +});