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/Bolivia.php b/src/Countries/Bolivia.php new file mode 100644 index 00000000..94072ed0 --- /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($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/src/Countries/Country.php b/src/Countries/Country.php index 1c74eb6e..e6b076cd 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,6 +3,8 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use GeniusTS\HijriDate\Date; +use GeniusTS\HijriDate\Hijri; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\UnsupportedCountry; @@ -99,4 +101,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 = 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::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 = 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::createFromTimestamp( Hijri::convertToGregorian($eid_al_adha->day, $eid_al_adha->month, + $eid_al_adha->year)->getTimestamp()); + } } 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/src/Countries/Uganda.php b/src/Countries/Uganda.php index 90a0af5b..c9d9796d 100644 --- a/src/Countries/Uganda.php +++ b/src/Countries/Uganda.php @@ -11,32 +11,56 @@ public function countryCode(): string return 'ug'; } + /** @return array */ protected function allHolidays(int $year): array { + $holidays_by_official_start_date = array(); + + // Independence day celebrations started in 1962 + if ($year >= 1962) { + $holidays_by_official_start_date['Independence Day of Uganda'] = '10-09'; + } + + // Martyr's day celebrations started in 1964 + if ($year >= 1964) { + $holidays_by_official_start_date['Uganda Martyr\'s Day'] = '06-03'; + } + + // 'NRM Liberation Day celebrations started in 1987 + if ($year >= 1987) { + $holidays_by_official_start_date['NRM Liberation Day'] = '01-26'; + } + + // National Heroes day celebration started in 2001 + if ($year >= 2001) { + $holidays_by_official_start_date['National Heroes\' Day'] = '06-09'; + } + + // Archbishop Janani Luwum Memorial Day celebrations started in 2015 + if ($year >= 2015) { + $holidays_by_official_start_date['Archbishop Janani Luwum Memorial Day'] = '02-16'; + } return array_merge([ - "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', + '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)); + 'Boxing Day' => '12-26' + ], $holidays_by_official_start_date, + $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), + return array( 'Easter Monday' => $easter->addDay(), - ]; + 'Good Friday' => $easter->addDays(-2), + 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha' => $this->eidAlAdha($year) + ); } } 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/.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/.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..996a0dab --- /dev/null +++ b/tests/.pest/snapshots/Countries/UgandaTest/it_can_calculate_uganda_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "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": "Eid al-Fitr", + "date": "2024-04-09" + }, + { + "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": "Eid al-Adha", + "date": "2024-06-17" + }, + { + "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/AustriaTest.php b/tests/Countries/AustriaTest.php index 3473abef..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 () { @@ -17,15 +16,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.'); 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(); + +}); 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'] +]); 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(); + });