From 9f54f4f17d7448c9b9dc9deb39407201deb5c7b4 Mon Sep 17 00:00:00 2001 From: Alpha Olomi Date: Thu, 18 Jan 2024 21:40:53 +0300 Subject: [PATCH 1/2] Add Tanzania national and religious holiday Co-Authored-By: Michael Omakei <48096457+omakei@users.noreply.github.com> --- src/Countries/Tanzania.php | 99 +++++++++++++++++++ .../it_can_calculate_tanzania_holidays.snap | 66 +++++++++++++ tests/Countries/TanzaniaTest.php | 18 ++++ 3 files changed, 183 insertions(+) create mode 100644 src/Countries/Tanzania.php create mode 100644 tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap create mode 100644 tests/Countries/TanzaniaTest.php diff --git a/src/Countries/Tanzania.php b/src/Countries/Tanzania.php new file mode 100644 index 000000000..b01787dab --- /dev/null +++ b/src/Countries/Tanzania.php @@ -0,0 +1,99 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'New Year\'s Day' => '01-01', + 'Labor Day' => '05-01', + 'Saba Saba Day' => '07-07', + 'Farmers Day (Nane Nane Day)' => '08-08', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Dar_es_Salaam'); + + // Eid al-Fitr is on the first day of the 10th month in the calendar + // since the PHP array index begins at 0, it is the 9th month + $eid_al_fitr_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-rgsa'); + $eid_al_fitr_cal->set(IntlCalendar::FIELD_MONTH, 9); + $eid_al_fitr_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 1); + $eid_al_fitr_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); + $eid_al_fitr_cal->clear(IntlCalendar::FIELD_MINUTE); + $eid_al_fitr_cal->clear(IntlCalendar::FIELD_SECOND); + $eid_al_fitr_cal->clear(IntlCalendar::FIELD_MILLISECOND); + + // Eid al-Hajj is on the 10th day of the Dhu al-Hijja the 12th month in the calendar + // since the PHP array index begins at 0, it is the 11th month + $eid_al_hajj_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-civil'); + $eid_al_hajj_cal->set(IntlCalendar::FIELD_MONTH, 11); + $eid_al_hajj_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 10); + $eid_al_hajj_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); + $eid_al_hajj_cal->clear(IntlCalendar::FIELD_MINUTE); + $eid_al_hajj_cal->clear(IntlCalendar::FIELD_SECOND); + $eid_al_hajj_cal->clear(IntlCalendar::FIELD_MILLISECOND); + + // Eid-e-Milad an-Nabi (Mawlid) is on the 12th day of the 3rd month in the calendar + // since the PHP array index begins at 0, it is the 11th month + $mawlid_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-civil'); + $mawlid_cal->set(IntlCalendar::FIELD_MONTH, 2); + $mawlid_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 12); + $mawlid_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); + $mawlid_cal->clear(IntlCalendar::FIELD_MINUTE); + $mawlid_cal->clear(IntlCalendar::FIELD_SECOND); + $mawlid_cal->clear(IntlCalendar::FIELD_MILLISECOND); + + $variable_holidays = [ + 'Easter Monday' => $easter->addDay(), + 'Good Friday' => $easter->addDays(-2), + 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), + 'Eid al-Hajj' => CarbonImmutable::createFromTimestamp($eid_al_hajj_cal->toDateTime()->getTimestamp()), + 'Maulid Day' => CarbonImmutable::createFromTimestamp($mawlid_cal->toDateTime()->getTimestamp()), + ]; + + // Zanzibar Revolutionary Day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Zanzibar Revolutionary Day'] = '01-12'; + } + + // Karume Day celebrations started in 1973 + if ($year >= 1973) { + $variable_holidays['Karume Day'] = '04-07'; + } + + // 'Union Day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Union Day'] = '04-26'; + } + + // Nyerere Day day celebrations started in 2000 + if ($year >= 2000) { + $variable_holidays['Nyerere Day'] = '10-14'; + } + + // Independence Day celebrations started in 1961 + if ($year >= 1961) { + $variable_holidays['Independence Day'] = '12-09'; + } + + return $variable_holidays; + } +} diff --git a/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap new file mode 100644 index 000000000..de51a1fa1 --- /dev/null +++ b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap @@ -0,0 +1,66 @@ +[ + { + "name": "Maulid Day", + "date": "2023-09-27" + }, + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Zanzibar Revolutionary Day", + "date": "2024-01-12" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Karume Day", + "date": "2024-04-07" + }, + { + "name": "Eid al-Fitr", + "date": "2024-04-09" + }, + { + "name": "Union Day", + "date": "2024-04-26" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Eid al-Hajj", + "date": "2024-06-17" + }, + { + "name": "Saba Saba Day", + "date": "2024-07-07" + }, + { + "name": "Farmers Day (Nane Nane Day)", + "date": "2024-08-08" + }, + { + "name": "Nyerere Day", + "date": "2024-10-14" + }, + { + "name": "Independence Day", + "date": "2024-12-09" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/TanzaniaTest.php b/tests/Countries/TanzaniaTest.php new file mode 100644 index 000000000..69777866b --- /dev/null +++ b/tests/Countries/TanzaniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 3d9213598bb99142e4d214137e227fe4d559da97 Mon Sep 17 00:00:00 2001 From: Alpha Olomi Date: Sat, 27 Jan 2024 18:50:55 +0300 Subject: [PATCH 2/2] feat: revise religious Holidays Co-Authored-By: Michael Omakei <48096457+omakei@users.noreply.github.com> --- src/Countries/Tanzania.php | 37 +------------------ .../it_can_calculate_tanzania_holidays.snap | 12 ------ 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/src/Countries/Tanzania.php b/src/Countries/Tanzania.php index b01787dab..05e16186a 100644 --- a/src/Countries/Tanzania.php +++ b/src/Countries/Tanzania.php @@ -12,7 +12,6 @@ public function countryCode(): string return 'tz'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -28,45 +27,11 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Africa/Dar_es_Salaam'); - - // Eid al-Fitr is on the first day of the 10th month in the calendar - // since the PHP array index begins at 0, it is the 9th month - $eid_al_fitr_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-rgsa'); - $eid_al_fitr_cal->set(IntlCalendar::FIELD_MONTH, 9); - $eid_al_fitr_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 1); - $eid_al_fitr_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); - $eid_al_fitr_cal->clear(IntlCalendar::FIELD_MINUTE); - $eid_al_fitr_cal->clear(IntlCalendar::FIELD_SECOND); - $eid_al_fitr_cal->clear(IntlCalendar::FIELD_MILLISECOND); - - // Eid al-Hajj is on the 10th day of the Dhu al-Hijja the 12th month in the calendar - // since the PHP array index begins at 0, it is the 11th month - $eid_al_hajj_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-civil'); - $eid_al_hajj_cal->set(IntlCalendar::FIELD_MONTH, 11); - $eid_al_hajj_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 10); - $eid_al_hajj_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); - $eid_al_hajj_cal->clear(IntlCalendar::FIELD_MINUTE); - $eid_al_hajj_cal->clear(IntlCalendar::FIELD_SECOND); - $eid_al_hajj_cal->clear(IntlCalendar::FIELD_MILLISECOND); - - // Eid-e-Milad an-Nabi (Mawlid) is on the 12th day of the 3rd month in the calendar - // since the PHP array index begins at 0, it is the 11th month - $mawlid_cal = IntlCalendar::createInstance('Africa/Dar_es_Salaam', '@calendar=islamic-civil'); - $mawlid_cal->set(IntlCalendar::FIELD_MONTH, 2); - $mawlid_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 12); - $mawlid_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); - $mawlid_cal->clear(IntlCalendar::FIELD_MINUTE); - $mawlid_cal->clear(IntlCalendar::FIELD_SECOND); - $mawlid_cal->clear(IntlCalendar::FIELD_MILLISECOND); + $easter = $this->easter($year); $variable_holidays = [ 'Easter Monday' => $easter->addDay(), 'Good Friday' => $easter->addDays(-2), - 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), - 'Eid al-Hajj' => CarbonImmutable::createFromTimestamp($eid_al_hajj_cal->toDateTime()->getTimestamp()), - 'Maulid Day' => CarbonImmutable::createFromTimestamp($mawlid_cal->toDateTime()->getTimestamp()), ]; // Zanzibar Revolutionary Day celebrations started in 1964 diff --git a/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap index de51a1fa1..d1d187c0d 100644 --- a/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap +++ b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap @@ -1,8 +1,4 @@ [ - { - "name": "Maulid Day", - "date": "2023-09-27" - }, { "name": "New Year's Day", "date": "2024-01-01" @@ -23,10 +19,6 @@ "name": "Karume Day", "date": "2024-04-07" }, - { - "name": "Eid al-Fitr", - "date": "2024-04-09" - }, { "name": "Union Day", "date": "2024-04-26" @@ -35,10 +27,6 @@ "name": "Labor Day", "date": "2024-05-01" }, - { - "name": "Eid al-Hajj", - "date": "2024-06-17" - }, { "name": "Saba Saba Day", "date": "2024-07-07"