From e1f2cb80c1cba9f20868140057c5a6b26c7b5205 Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Wed, 17 Jan 2024 17:38:03 +0300 Subject: [PATCH 01/16] Initial commit for Uganda, now looking to add the Islamic calendar holidays Eid al-Fitr and Eid al-Adha --- src/Countries/Uganda.php | 42 ++++++++++++++++ .../it_can_calculate_uganda_holidays.snap | 50 +++++++++++++++++++ tests/Countries/UgandaTest.php | 19 +++++++ 3 files changed, 111 insertions(+) create mode 100644 src/Countries/Uganda.php create mode 100644 tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap create mode 100644 tests/Countries/UgandaTest.php diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php new file mode 100644 index 00000000..f402ac13 --- /dev/null +++ b/src/Countries/Uganda.php @@ -0,0 +1,42 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'New Year\'s Day' => '01-01', + 'NRM Liberation Day' => '01-26', + 'Archbishop Janani Luwum Memorial Day' => '02-16', + 'International Women\'s Day' => '03-08', + 'Labor Day' => '05-01', + 'Uganda Martyr\'s Day' => '06-03', + 'National Heroes\' Day' => '06-09', + 'Independence Day of Uganda' => '10-09', + '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/Kampala'); + + return [ + 'Easter Monday' => $easter->addDay(), + 'Good Friday' => $easter->addDays(-2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap new file mode 100644 index 00000000..7c364177 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "NRM Liberation Day", + "date": "2024-01-26" + }, + { + "name": "Archbishop Janani Luwum Memorial Day", + "date": "2024-02-16" + }, + { + "name": "International Women's Day", + "date": "2024-03-08" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Uganda Martyr's Day", + "date": "2024-06-03" + }, + { + "name": "National Heroes' Day", + "date": "2024-06-09" + }, + { + "name": "Independence Day of Uganda", + "date": "2024-10-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/UgandaTest.php b/tests/Countries/UgandaTest.php new file mode 100644 index 00000000..10fa341b --- /dev/null +++ b/tests/Countries/UgandaTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From e729d130705af1ab2f77456de6758636bd4b577b Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Wed, 17 Jan 2024 19:29:49 +0300 Subject: [PATCH 02/16] Add computations for Eid al-Fitr and Eid al-Adha --- src/Countries/Uganda.php | 23 +++++++++++++++++++ .../it_can_calculate_uganda_holidays.snap | 8 +++++++ 2 files changed, 31 insertions(+) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index f402ac13..d2067f36 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use IntlCalendar; class Uganda extends Country { @@ -34,9 +35,31 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Africa/Kampala'); + // 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/Kampala', '@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-Adha 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_adha_cal = IntlCalendar::createInstance('Africa/Kampala', '@calendar=islamic-civil'); + $eid_al_adha_cal->set(IntlCalendar::FIELD_MONTH, 11); + $eid_al_adha_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 10); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_MINUTE); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_SECOND); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_MILLISECOND); + return [ 'Easter Monday' => $easter->addDay(), 'Good Friday' => $easter->addDays(-2), + 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), + 'Eid al-Adha' => CarbonImmutable::createFromTimestamp($eid_al_adha_cal->toDateTime()->getTimestamp()) ]; } } diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap index 7c364177..996a0dab 100644 --- a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap @@ -23,6 +23,10 @@ "name": "Easter Monday", "date": "2024-04-01" }, + { + "name": "Eid al-Fitr", + "date": "2024-04-09" + }, { "name": "Labor Day", "date": "2024-05-01" @@ -35,6 +39,10 @@ "name": "National Heroes' Day", "date": "2024-06-09" }, + { + "name": "Eid al-Adha", + "date": "2024-06-17" + }, { "name": "Independence Day of Uganda", "date": "2024-10-09" From 1c55b136fe4c0f9a549ed67f0fc4cab8d1bf2e51 Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Wed, 17 Jan 2024 21:44:53 +0300 Subject: [PATCH 03/16] Added start dates for the celebration of new holidays added to the list --- src/Countries/Uganda.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index d2067f36..f6b9fd44 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -17,13 +17,8 @@ protected function allHolidays(int $year): array { return array_merge([ 'New Year\'s Day' => '01-01', - 'NRM Liberation Day' => '01-26', - 'Archbishop Janani Luwum Memorial Day' => '02-16', 'International Women\'s Day' => '03-08', 'Labor Day' => '05-01', - 'Uganda Martyr\'s Day' => '06-03', - 'National Heroes\' Day' => '06-09', - 'Independence Day of Uganda' => '10-09', 'Christmas Day' => '12-25', 'Boxing Day' => '12-26' ], $this->variableHolidays($year)); @@ -55,11 +50,38 @@ protected function variableHolidays(int $year): array $eid_al_adha_cal->clear(IntlCalendar::FIELD_SECOND); $eid_al_adha_cal->clear(IntlCalendar::FIELD_MILLISECOND); - return [ + $variable_holidays = array( 'Easter Monday' => $easter->addDay(), 'Good Friday' => $easter->addDays(-2), 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), 'Eid al-Adha' => CarbonImmutable::createFromTimestamp($eid_al_adha_cal->toDateTime()->getTimestamp()) - ]; + ); + + // Independence day celebrations started in 1962 + if ($year >= 1962) { + $variable_holidays['Independence Day of Uganda'] = '10-09'; + } + + // Martyr's day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Uganda Martyr\'s Day'] = '06-03'; + } + + // 'NRM Liberation Day celebrations started in 1987 + if ($year >= 1987) { + $variable_holidays['NRM Liberation Day'] = '01-26'; + } + + // National Heroes day celebration started in 2001 + if ($year >= 2001) { + $variable_holidays['National Heroes\' Day'] = '06-09'; + } + + // Archbishop Janani Luwum Memorial Day celebrations started in 2015 + if ($year >= 2015) { + $variable_holidays['Archbishop Janani Luwum Memorial Day'] = '02-16'; + } + + return $variable_holidays; } } From 036096153365ab3792f4fc55d29d471707767cc3 Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Fri, 19 Jan 2024 18:16:08 +0300 Subject: [PATCH 04/16] Add tests for computing the dates for Eid al-Fitr and Eid al-Adha --- composer.json | 5 +++-- src/Countries/Country.php | 29 +++++++++++++++++++++++++++++ src/Countries/Uganda.php | 25 ++----------------------- tests/Countries/CountryTest.php | 23 +++++++++++++++++++++++ 4 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 tests/Countries/CountryTest.php diff --git a/composer.json b/composer.json index aa1da046..f700901b 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,9 @@ ], "require": { "php": "^8.1", - "nesbot/carbon": "^2.72.1", - "ext-calendar": "*" + "ext-calendar": "*", + "geniusts/hijri-dates": "^1.1", + "nesbot/carbon": "^2.72.1" }, "require-dev": { "pestphp/pest": "^2.31", diff --git a/src/Countries/Country.php b/src/Countries/Country.php index b99262a5..888741e3 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use GeniusTS\HijriDate\Date; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\UnsupportedCountry; @@ -91,4 +92,32 @@ protected function ensureYearCanBeCalculated(int $year): void throw InvalidYear::yearTooHigh(); } } + + public static function eidAlFitr(int $year): CarbonImmutable { + // get the Hirji date for the first day of the Gregorian year + $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + // Eid al-Fitr is on the first day of the 10th month in the calendar + if ($hirji_date->month > 10) { + // the date has passed to move to the next year + $hirji_date->year($hirji_date->year + 1); + } + $eid_al_fitr = new Date(1, 10, $hirji_date->year); + + return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_fitr->day, $eid_al_fitr->month, + $eid_al_fitr->year)); + } + + public static function eidAlAdha(int $year): CarbonImmutable { + // get the Hirji date for the first day of the Gregorian year + $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + // Eid al-Fitr is on the first day of the 10th month in the calendar + if ($hirji_date->month > 10) { + // the date has passed to move to the next year + $hirji_date->year($hirji_date->year + 1); + } + $eid_al_adha = new Date(10, 12, $hirji_date->year); + + return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month, + $eid_al_adha->year)); + } } diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index f6b9fd44..9c1c9216 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use IntlCalendar; class Uganda extends Country { @@ -30,31 +29,11 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Africa/Kampala'); - // 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/Kampala', '@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-Adha 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_adha_cal = IntlCalendar::createInstance('Africa/Kampala', '@calendar=islamic-civil'); - $eid_al_adha_cal->set(IntlCalendar::FIELD_MONTH, 11); - $eid_al_adha_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 10); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_MINUTE); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_SECOND); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_MILLISECOND); - $variable_holidays = array( 'Easter Monday' => $easter->addDay(), 'Good Friday' => $easter->addDays(-2), - 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), - 'Eid al-Adha' => CarbonImmutable::createFromTimestamp($eid_al_adha_cal->toDateTime()->getTimestamp()) + 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha' => $this->eidAlAdha($year) ); // Independence day celebrations started in 1962 diff --git a/tests/Countries/CountryTest.php b/tests/Countries/CountryTest.php new file mode 100644 index 00000000..6cd117f7 --- /dev/null +++ b/tests/Countries/CountryTest.php @@ -0,0 +1,23 @@ +format('Y-m-d'))->toBe($date); +})->with([ + [2024, '2024-04-09'], + [2020, '2020-05-24'], + [2009, '2009-09-21'], + [1995, '1995-03-02'] +]); + + +it('can compute Eid al-Adha date correctly', function (int $year, string $date) { + expect(Country::eidAlAdha($year)->format('Y-m-d'))->toBe($date); +})->with([ + [2024, '2024-06-16'], + [2023, '2023-06-28'], + [2019, '2019-08-11'], + [2007, '2007-12-20'], + [1994, '1994-05-20'] +]); From a6b61d774aa8db721c00634952ead8639023eca6 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:23:47 +0100 Subject: [PATCH 05/16] use easter() instead --- src/Countries/Croatia.php | 4 +--- .../it_can_calculate_croatian_holidays.snap | 4 ++-- tests/Countries/AustriaTest.php | 12 ------------ 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Countries/Croatia.php b/src/Countries/Croatia.php index d95906f7..f5d7b7c8 100644 --- a/src/Countries/Croatia.php +++ b/src/Countries/Croatia.php @@ -11,7 +11,6 @@ public function countryCode(): string return 'hr'; } - /** @return array */ protected function allHolidays(int $year): array { return array_merge([ @@ -32,8 +31,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Europe/Zagreb'); + $easter = $this->easter($year); return [ 'Uskrsni ponedjeljak' => $easter->addDay(), diff --git a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap index 821ad707..206f0784 100644 --- a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap +++ b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap @@ -16,11 +16,11 @@ "date": "2024-05-01" }, { - "name": "Tijelovo", + "name": "Dan dr\u017eavnosti", "date": "2024-05-30" }, { - "name": "Dan dr\u017eavnosti", + "name": "Tijelovo", "date": "2024-05-30" }, { diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 3473abef..74794306 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -17,15 +17,3 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - -it('can calculate austrian holidays with region holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); - - $holidays = Holidays::for(Austria::make('bg'))->get(); - - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); - - expect(formatDates($holidays))->toMatchSnapshot(); -})->skip('Austria class has to be extended with regions first.'); From b985b90749faf6ce9391ec3540f1a0c7958a333d Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 19 Jan 2024 15:24:06 +0000 Subject: [PATCH 06/16] Fix styling --- tests/Countries/AustriaTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Countries/AustriaTest.php b/tests/Countries/AustriaTest.php index 74794306..9018307f 100644 --- a/tests/Countries/AustriaTest.php +++ b/tests/Countries/AustriaTest.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Countries\Austria; use Spatie\Holidays\Holidays; it('can calculate austrian holidays', function () { From fdeaa7537ac490784f96d7d182e8a69c1b08740d Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Fri, 19 Jan 2024 18:26:55 +0300 Subject: [PATCH 07/16] Change the immutable date conversion to use a Timestamp --- src/Countries/Country.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 888741e3..ff743784 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use GeniusTS\HijriDate\Date; +use GeniusTS\HijriDate\Hijri; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\UnsupportedCountry; @@ -95,7 +96,7 @@ protected function ensureYearCanBeCalculated(int $year): void public static function eidAlFitr(int $year): CarbonImmutable { // get the Hirji date for the first day of the Gregorian year - $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + $hirji_date = Hijri::convertToHijri(CarbonImmutable::create($year)); // Eid al-Fitr is on the first day of the 10th month in the calendar if ($hirji_date->month > 10) { // the date has passed to move to the next year @@ -103,13 +104,13 @@ public static function eidAlFitr(int $year): CarbonImmutable { } $eid_al_fitr = new Date(1, 10, $hirji_date->year); - return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_fitr->day, $eid_al_fitr->month, - $eid_al_fitr->year)); + return CarbonImmutable::createFromTimestamp( Hijri::convertToGregorian($eid_al_fitr->day, $eid_al_fitr->month, + $eid_al_fitr->year)->getTimestamp()); } public static function eidAlAdha(int $year): CarbonImmutable { // get the Hirji date for the first day of the Gregorian year - $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + $hirji_date = Hijri::convertToHijri(CarbonImmutable::create($year)); // Eid al-Fitr is on the first day of the 10th month in the calendar if ($hirji_date->month > 10) { // the date has passed to move to the next year @@ -117,7 +118,7 @@ public static function eidAlAdha(int $year): CarbonImmutable { } $eid_al_adha = new Date(10, 12, $hirji_date->year); - return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month, - $eid_al_adha->year)); + return CarbonImmutable::createFromTimestamp( Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month, + $eid_al_adha->year)->getTimestamp()); } } From b4cdb9cf851b36448a3abd98be02dc83f8446757 Mon Sep 17 00:00:00 2001 From: rats4final <80012704+rats4final@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:26:58 -0400 Subject: [PATCH 08/16] Bolivian holidays (#40) * feature: add bolivian holidays * test: add bolivia test * test snap * fixed typo and phpstan * calculate correct easter date * Fix styling --------- Co-authored-by: rats4final Co-authored-by: rats4final --- src/Countries/Bolivia.php | 39 ++++++++++++++++ .../it_can_calculate_bolivian_holidays.snap | 46 +++++++++++++++++++ tests/Countries/BoliviaTest.php | 18 ++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/Countries/Bolivia.php create mode 100644 tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap create mode 100644 tests/Countries/BoliviaTest.php diff --git a/src/Countries/Bolivia.php b/src/Countries/Bolivia.php new file mode 100644 index 00000000..977d9bfa --- /dev/null +++ b/src/Countries/Bolivia.php @@ -0,0 +1,39 @@ + '01-01', + 'Día del Estado Plurinacional' => '01-22', + 'Día del Trabajador' => '05-01', + 'Año Nuevo Aymara' => '06-21', + 'Día de la Independencia' => '08-06', + 'Día de Todos los Santos' => '11-02', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter((string) $year); + + return [ + 'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6), + 'Martes de Carnaval' => $easter->subWeeks(6)->subDays(5), + 'Viernes Santo' => $easter->subDays(2), + 'Corpus Christi' => $easter->addWeeks(8)->addDays(4), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap b/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap new file mode 100644 index 00000000..c169618c --- /dev/null +++ b/tests/.pest/snapshots/Countries/BoliviaTest/it_can_calculate_bolivian_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "D\u00eda de A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda del Estado Plurinacional", + "date": "2024-01-22" + }, + { + "name": "Lunes de Carnaval", + "date": "2024-02-12" + }, + { + "name": "Martes de Carnaval", + "date": "2024-02-13" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Corpus Christi", + "date": "2024-05-30" + }, + { + "name": "A\u00f1o Nuevo Aymara", + "date": "2024-06-21" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-08-06" + }, + { + "name": "D\u00eda de Todos los Santos", + "date": "2024-11-02" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BoliviaTest.php b/tests/Countries/BoliviaTest.php new file mode 100644 index 00000000..e1305657 --- /dev/null +++ b/tests/Countries/BoliviaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); + +}); From dc932c8ffcd4837b9dbc32e6808867ed9f965d2d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:27:30 +0100 Subject: [PATCH 09/16] remove unneeded conversion --- src/Countries/Bolivia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Bolivia.php b/src/Countries/Bolivia.php index 977d9bfa..94072ed0 100644 --- a/src/Countries/Bolivia.php +++ b/src/Countries/Bolivia.php @@ -27,7 +27,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter((string) $year); + $easter = $this->easter($year); return [ 'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6), From 9a1c57e8ac36c59ba5c7450e30449ea020ef4bdc Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Fri, 19 Jan 2024 18:32:37 +0300 Subject: [PATCH 10/16] Cleanup PHP Stan errors --- src/Countries/Uganda.php | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 9c1c9216..c9d9796d 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -14,53 +14,53 @@ public function countryCode(): string /** @return array */ protected function allHolidays(int $year): array { - return array_merge([ - 'New Year\'s Day' => '01-01', - 'International Women\'s Day' => '03-08', - 'Labor Day' => '05-01', - '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/Kampala'); - - $variable_holidays = array( - 'Easter Monday' => $easter->addDay(), - 'Good Friday' => $easter->addDays(-2), - 'Eid al-Fitr' => $this->eidAlFitr($year), - 'Eid al-Adha' => $this->eidAlAdha($year) - ); + $holidays_by_official_start_date = array(); // Independence day celebrations started in 1962 if ($year >= 1962) { - $variable_holidays['Independence Day of Uganda'] = '10-09'; + $holidays_by_official_start_date['Independence Day of Uganda'] = '10-09'; } // Martyr's day celebrations started in 1964 if ($year >= 1964) { - $variable_holidays['Uganda Martyr\'s Day'] = '06-03'; + $holidays_by_official_start_date['Uganda Martyr\'s Day'] = '06-03'; } // 'NRM Liberation Day celebrations started in 1987 if ($year >= 1987) { - $variable_holidays['NRM Liberation Day'] = '01-26'; + $holidays_by_official_start_date['NRM Liberation Day'] = '01-26'; } // National Heroes day celebration started in 2001 if ($year >= 2001) { - $variable_holidays['National Heroes\' Day'] = '06-09'; + $holidays_by_official_start_date['National Heroes\' Day'] = '06-09'; } // Archbishop Janani Luwum Memorial Day celebrations started in 2015 if ($year >= 2015) { - $variable_holidays['Archbishop Janani Luwum Memorial Day'] = '02-16'; + $holidays_by_official_start_date['Archbishop Janani Luwum Memorial Day'] = '02-16'; } + return array_merge([ + 'New Year\'s Day' => '01-01', + 'International Women\'s Day' => '03-08', + 'Labor Day' => '05-01', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26' + ], $holidays_by_official_start_date, + $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Kampala'); - return $variable_holidays; + return array( + 'Easter Monday' => $easter->addDay(), + 'Good Friday' => $easter->addDays(-2), + 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha' => $this->eidAlAdha($year) + ); } } From d9f2ff17b330fa9ff95a8294eb4a0b70d394dda1 Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Wed, 17 Jan 2024 17:38:03 +0300 Subject: [PATCH 11/16] Initial commit for Uganda, now looking to add the Islamic calendar holidays Eid al-Fitr and Eid al-Adha --- src/Countries/Uganda.php | 28 +++++------ .../it_can_calculate_uganda_holidays.snap | 50 +++++++++++++++++++ tests/Countries/UgandaTest.php | 3 +- 3 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 90a0af5b..f402ac13 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -11,32 +11,32 @@ public function countryCode(): string return 'ug'; } + /** @return array */ protected function allHolidays(int $year): array { return array_merge([ - "New Year's Day" => '01-01', + 'New Year\'s Day' => '01-01', 'NRM Liberation Day' => '01-26', - 'Archbishop Janani Luwum Day' => '02-16', - "International Women's Day" => '03-08', - 'Labour Day' => '05-01', - "Martyrs' Day" => '06-03', - 'National Hereos Day' => '06-09', - 'Independence Day' => '10-09', + 'Archbishop Janani Luwum Memorial Day' => '02-16', + 'International Women\'s Day' => '03-08', + 'Labor Day' => '05-01', + 'Uganda Martyr\'s Day' => '06-03', + 'National Heroes\' Day' => '06-09', + 'Independence Day of Uganda' => '10-09', 'Christmas Day' => '12-25', - 'Boxing Day' => '12-26', + 'Boxing Day' => '12-26' ], $this->variableHolidays($year)); } - /** - * @return array - */ - private function variableHolidays(int $year): array + /** @return array */ + protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Africa/Nairobi'); + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Kampala'); return [ - 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), + 'Good Friday' => $easter->addDays(-2), ]; } } diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap new file mode 100644 index 00000000..7c364177 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap @@ -0,0 +1,50 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "NRM Liberation Day", + "date": "2024-01-26" + }, + { + "name": "Archbishop Janani Luwum Memorial Day", + "date": "2024-02-16" + }, + { + "name": "International Women's Day", + "date": "2024-03-08" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Uganda Martyr's Day", + "date": "2024-06-03" + }, + { + "name": "National Heroes' Day", + "date": "2024-06-09" + }, + { + "name": "Independence Day of Uganda", + "date": "2024-10-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/UgandaTest.php b/tests/Countries/UgandaTest.php index 82ab1f7f..10fa341b 100644 --- a/tests/Countries/UgandaTest.php +++ b/tests/Countries/UgandaTest.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate ugandan holidays', function () { +it('can calculate uganda holidays', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); $holidays = Holidays::for(country: 'ug')->get(); @@ -15,4 +15,5 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); + }); From 6bcf1378c377dd611383da82de00641523f770b1 Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Wed, 17 Jan 2024 19:29:49 +0300 Subject: [PATCH 12/16] Add computations for Eid al-Fitr and Eid al-Adha --- src/Countries/Uganda.php | 23 +++++++++++++++++++ .../it_can_calculate_uganda_holidays.snap | 8 +++++++ 2 files changed, 31 insertions(+) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index f402ac13..d2067f36 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use IntlCalendar; class Uganda extends Country { @@ -34,9 +35,31 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Africa/Kampala'); + // 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/Kampala', '@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-Adha 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_adha_cal = IntlCalendar::createInstance('Africa/Kampala', '@calendar=islamic-civil'); + $eid_al_adha_cal->set(IntlCalendar::FIELD_MONTH, 11); + $eid_al_adha_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 10); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_MINUTE); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_SECOND); + $eid_al_adha_cal->clear(IntlCalendar::FIELD_MILLISECOND); + return [ 'Easter Monday' => $easter->addDay(), 'Good Friday' => $easter->addDays(-2), + 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), + 'Eid al-Adha' => CarbonImmutable::createFromTimestamp($eid_al_adha_cal->toDateTime()->getTimestamp()) ]; } } diff --git a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap index 7c364177..996a0dab 100644 --- a/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap @@ -23,6 +23,10 @@ "name": "Easter Monday", "date": "2024-04-01" }, + { + "name": "Eid al-Fitr", + "date": "2024-04-09" + }, { "name": "Labor Day", "date": "2024-05-01" @@ -35,6 +39,10 @@ "name": "National Heroes' Day", "date": "2024-06-09" }, + { + "name": "Eid al-Adha", + "date": "2024-06-17" + }, { "name": "Independence Day of Uganda", "date": "2024-10-09" From 35628f06e857924f1906e03c7a6bb908595ca780 Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Wed, 17 Jan 2024 21:44:53 +0300 Subject: [PATCH 13/16] Added start dates for the celebration of new holidays added to the list --- src/Countries/Uganda.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index d2067f36..f6b9fd44 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -17,13 +17,8 @@ protected function allHolidays(int $year): array { return array_merge([ 'New Year\'s Day' => '01-01', - 'NRM Liberation Day' => '01-26', - 'Archbishop Janani Luwum Memorial Day' => '02-16', 'International Women\'s Day' => '03-08', 'Labor Day' => '05-01', - 'Uganda Martyr\'s Day' => '06-03', - 'National Heroes\' Day' => '06-09', - 'Independence Day of Uganda' => '10-09', 'Christmas Day' => '12-25', 'Boxing Day' => '12-26' ], $this->variableHolidays($year)); @@ -55,11 +50,38 @@ protected function variableHolidays(int $year): array $eid_al_adha_cal->clear(IntlCalendar::FIELD_SECOND); $eid_al_adha_cal->clear(IntlCalendar::FIELD_MILLISECOND); - return [ + $variable_holidays = array( 'Easter Monday' => $easter->addDay(), 'Good Friday' => $easter->addDays(-2), 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), 'Eid al-Adha' => CarbonImmutable::createFromTimestamp($eid_al_adha_cal->toDateTime()->getTimestamp()) - ]; + ); + + // Independence day celebrations started in 1962 + if ($year >= 1962) { + $variable_holidays['Independence Day of Uganda'] = '10-09'; + } + + // Martyr's day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Uganda Martyr\'s Day'] = '06-03'; + } + + // 'NRM Liberation Day celebrations started in 1987 + if ($year >= 1987) { + $variable_holidays['NRM Liberation Day'] = '01-26'; + } + + // National Heroes day celebration started in 2001 + if ($year >= 2001) { + $variable_holidays['National Heroes\' Day'] = '06-09'; + } + + // Archbishop Janani Luwum Memorial Day celebrations started in 2015 + if ($year >= 2015) { + $variable_holidays['Archbishop Janani Luwum Memorial Day'] = '02-16'; + } + + return $variable_holidays; } } From 46d816015c817f824a3952cfec37d548b5fb347e Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Fri, 19 Jan 2024 18:16:08 +0300 Subject: [PATCH 14/16] Add tests for computing the dates for Eid al-Fitr and Eid al-Adha --- composer.json | 5 +++-- src/Countries/Country.php | 29 +++++++++++++++++++++++++++++ src/Countries/Uganda.php | 25 ++----------------------- tests/Countries/CountryTest.php | 23 +++++++++++++++++++++++ 4 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 tests/Countries/CountryTest.php diff --git a/composer.json b/composer.json index 91002ed8..ed429e44 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,9 @@ ], "require": { "php": "^8.1", - "nesbot/carbon": "^2.72.1", - "ext-calendar": "*" + "ext-calendar": "*", + "geniusts/hijri-dates": "^1.1", + "nesbot/carbon": "^2.72.1" }, "require-dev": { "laravel/prompts": "^0.1.15", diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 1c74eb6e..270f75d1 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use GeniusTS\HijriDate\Date; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\UnsupportedCountry; @@ -99,4 +100,32 @@ protected function ensureYearCanBeCalculated(int $year): void throw InvalidYear::yearTooHigh(); } } + + public static function eidAlFitr(int $year): CarbonImmutable { + // get the Hirji date for the first day of the Gregorian year + $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + // Eid al-Fitr is on the first day of the 10th month in the calendar + if ($hirji_date->month > 10) { + // the date has passed to move to the next year + $hirji_date->year($hirji_date->year + 1); + } + $eid_al_fitr = new Date(1, 10, $hirji_date->year); + + return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_fitr->day, $eid_al_fitr->month, + $eid_al_fitr->year)); + } + + public static function eidAlAdha(int $year): CarbonImmutable { + // get the Hirji date for the first day of the Gregorian year + $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + // Eid al-Fitr is on the first day of the 10th month in the calendar + if ($hirji_date->month > 10) { + // the date has passed to move to the next year + $hirji_date->year($hirji_date->year + 1); + } + $eid_al_adha = new Date(10, 12, $hirji_date->year); + + return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month, + $eid_al_adha->year)); + } } diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index f6b9fd44..9c1c9216 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use IntlCalendar; class Uganda extends Country { @@ -30,31 +29,11 @@ protected function variableHolidays(int $year): array $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) ->setTimezone('Africa/Kampala'); - // 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/Kampala', '@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-Adha 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_adha_cal = IntlCalendar::createInstance('Africa/Kampala', '@calendar=islamic-civil'); - $eid_al_adha_cal->set(IntlCalendar::FIELD_MONTH, 11); - $eid_al_adha_cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 10); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_HOUR_OF_DAY); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_MINUTE); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_SECOND); - $eid_al_adha_cal->clear(IntlCalendar::FIELD_MILLISECOND); - $variable_holidays = array( 'Easter Monday' => $easter->addDay(), 'Good Friday' => $easter->addDays(-2), - 'Eid al-Fitr' => CarbonImmutable::createFromTimestamp($eid_al_fitr_cal->toDateTime()->getTimestamp()), - 'Eid al-Adha' => CarbonImmutable::createFromTimestamp($eid_al_adha_cal->toDateTime()->getTimestamp()) + 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha' => $this->eidAlAdha($year) ); // Independence day celebrations started in 1962 diff --git a/tests/Countries/CountryTest.php b/tests/Countries/CountryTest.php new file mode 100644 index 00000000..6cd117f7 --- /dev/null +++ b/tests/Countries/CountryTest.php @@ -0,0 +1,23 @@ +format('Y-m-d'))->toBe($date); +})->with([ + [2024, '2024-04-09'], + [2020, '2020-05-24'], + [2009, '2009-09-21'], + [1995, '1995-03-02'] +]); + + +it('can compute Eid al-Adha date correctly', function (int $year, string $date) { + expect(Country::eidAlAdha($year)->format('Y-m-d'))->toBe($date); +})->with([ + [2024, '2024-06-16'], + [2023, '2023-06-28'], + [2019, '2019-08-11'], + [2007, '2007-12-20'], + [1994, '1994-05-20'] +]); From ade01bc2660588a5ce6589238e0fa24d687e7867 Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Fri, 19 Jan 2024 18:26:55 +0300 Subject: [PATCH 15/16] Change the immutable date conversion to use a Timestamp --- src/Countries/Country.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 270f75d1..e6b076cd 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use GeniusTS\HijriDate\Date; +use GeniusTS\HijriDate\Hijri; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\UnsupportedCountry; @@ -103,7 +104,7 @@ protected function ensureYearCanBeCalculated(int $year): void public static function eidAlFitr(int $year): CarbonImmutable { // get the Hirji date for the first day of the Gregorian year - $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + $hirji_date = Hijri::convertToHijri(CarbonImmutable::create($year)); // Eid al-Fitr is on the first day of the 10th month in the calendar if ($hirji_date->month > 10) { // the date has passed to move to the next year @@ -111,13 +112,13 @@ public static function eidAlFitr(int $year): CarbonImmutable { } $eid_al_fitr = new Date(1, 10, $hirji_date->year); - return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_fitr->day, $eid_al_fitr->month, - $eid_al_fitr->year)); + return CarbonImmutable::createFromTimestamp( Hijri::convertToGregorian($eid_al_fitr->day, $eid_al_fitr->month, + $eid_al_fitr->year)->getTimestamp()); } public static function eidAlAdha(int $year): CarbonImmutable { // get the Hirji date for the first day of the Gregorian year - $hirji_date = \GeniusTS\HijriDate\Hijri::convertToHijri(CarbonImmutable::create($year)); + $hirji_date = Hijri::convertToHijri(CarbonImmutable::create($year)); // Eid al-Fitr is on the first day of the 10th month in the calendar if ($hirji_date->month > 10) { // the date has passed to move to the next year @@ -125,7 +126,7 @@ public static function eidAlAdha(int $year): CarbonImmutable { } $eid_al_adha = new Date(10, 12, $hirji_date->year); - return CarbonImmutable::createFromDate( \GeniusTS\HijriDate\Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month, - $eid_al_adha->year)); + return CarbonImmutable::createFromTimestamp( Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month, + $eid_al_adha->year)->getTimestamp()); } } From 9912982fa70b3627a6a8e12e45c833dfc4ba4f6c Mon Sep 17 00:00:00 2001 From: "Stephen S. Musoke" Date: Fri, 19 Jan 2024 18:32:37 +0300 Subject: [PATCH 16/16] Cleanup PHP Stan errors --- src/Countries/Uganda.php | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Countries/Uganda.php b/src/Countries/Uganda.php index 9c1c9216..c9d9796d 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -14,53 +14,53 @@ public function countryCode(): string /** @return array */ protected function allHolidays(int $year): array { - return array_merge([ - 'New Year\'s Day' => '01-01', - 'International Women\'s Day' => '03-08', - 'Labor Day' => '05-01', - '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/Kampala'); - - $variable_holidays = array( - 'Easter Monday' => $easter->addDay(), - 'Good Friday' => $easter->addDays(-2), - 'Eid al-Fitr' => $this->eidAlFitr($year), - 'Eid al-Adha' => $this->eidAlAdha($year) - ); + $holidays_by_official_start_date = array(); // Independence day celebrations started in 1962 if ($year >= 1962) { - $variable_holidays['Independence Day of Uganda'] = '10-09'; + $holidays_by_official_start_date['Independence Day of Uganda'] = '10-09'; } // Martyr's day celebrations started in 1964 if ($year >= 1964) { - $variable_holidays['Uganda Martyr\'s Day'] = '06-03'; + $holidays_by_official_start_date['Uganda Martyr\'s Day'] = '06-03'; } // 'NRM Liberation Day celebrations started in 1987 if ($year >= 1987) { - $variable_holidays['NRM Liberation Day'] = '01-26'; + $holidays_by_official_start_date['NRM Liberation Day'] = '01-26'; } // National Heroes day celebration started in 2001 if ($year >= 2001) { - $variable_holidays['National Heroes\' Day'] = '06-09'; + $holidays_by_official_start_date['National Heroes\' Day'] = '06-09'; } // Archbishop Janani Luwum Memorial Day celebrations started in 2015 if ($year >= 2015) { - $variable_holidays['Archbishop Janani Luwum Memorial Day'] = '02-16'; + $holidays_by_official_start_date['Archbishop Janani Luwum Memorial Day'] = '02-16'; } + return array_merge([ + 'New Year\'s Day' => '01-01', + 'International Women\'s Day' => '03-08', + 'Labor Day' => '05-01', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26' + ], $holidays_by_official_start_date, + $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Kampala'); - return $variable_holidays; + return array( + 'Easter Monday' => $easter->addDay(), + 'Good Friday' => $easter->addDays(-2), + 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha' => $this->eidAlAdha($year) + ); } }