diff --git a/composer.json b/composer.json index 91002ed8c..ed429e44a 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/Tunisia.php b/src/Countries/Tunisia.php index d75716236..b64e2a3c6 100644 --- a/src/Countries/Tunisia.php +++ b/src/Countries/Tunisia.php @@ -3,8 +3,12 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use GeniusTS\HijriDate\Hijri; + class Tunisia extends Country { + private int $adjustmentDays = 1; + public function countryCode(): string { return 'tn'; @@ -33,12 +37,26 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { return [ - 'Eid al-Fitr' => '04-10', - 'Eid al-Fitr 2' => '04-11', - 'Eid al-Adha' => '06-16', - 'Eid al-Adha 2' => '06-17', - 'Islamic New Year' => '07-07', - 'Birthday of the Prophet Muhammad' => '09-16' + 'Islamic new year' => $this->getHijriDateAsGregorian(1, 1, $year + 1), + 'Birthday of the Prophet Muhammad' => $this->getHijriDateAsGregorian(12, 3, $year + 1), + 'Eid al-Fitr' => $this->getHijriDateAsGregorian(1, 10, $year, $this->adjustmentDays), + 'Eid al-Fitr - 2nd day' => $this->getHijriDateAsGregorian(2, 10, $year, $this->adjustmentDays), + 'Eid al-Adha' => $this->getHijriDateAsGregorian(10, 12, $year, $this->adjustmentDays), + 'Eid al-Adha - 2nd day' => $this->getHijriDateAsGregorian(11, 12, $year, $this->adjustmentDays), ]; } + + protected function getHijriDateAsGregorian( + int $hijriDay, + int $hijriMonth, + int $hijriYear, + int $adjustmentDays = 0 + ): CarbonImmutable + { + $gregorianNewYear = CarbonImmutable::create($hijriYear, 1, 1); + $hijriNewYear = Hijri::convertToHijri($gregorianNewYear); + $gregorianDate = Hijri::convertToGregorian($hijriDay, $hijriMonth, $hijriNewYear->year); + return CarbonImmutable::instance($gregorianDate)->addDays($adjustmentDays); + } + } diff --git a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays.snap b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays.snap index 50be9b4a1..793636f64 100644 --- a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays.snap +++ b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays.snap @@ -16,7 +16,7 @@ "date": "2024-04-10" }, { - "name": "Eid al-Fitr 2", + "name": "Eid al-Fitr - 2nd day", "date": "2024-04-11" }, { @@ -25,14 +25,14 @@ }, { "name": "Eid al-Adha", - "date": "2024-06-16" + "date": "2024-06-17" }, { - "name": "Eid al-Adha 2", - "date": "2024-06-17" + "name": "Eid al-Adha - 2nd day", + "date": "2024-06-18" }, { - "name": "Islamic New Year", + "name": "Islamic new year", "date": "2024-07-07" }, { @@ -45,7 +45,7 @@ }, { "name": "Birthday of the Prophet Muhammad", - "date": "2024-09-16" + "date": "2024-09-15" }, { "name": "Evacuation Day",