diff --git a/lang/tunisia/ar/holidays.json b/lang/tunisia/ar/holidays.json index 94279f8fd..6739b6ad4 100644 --- a/lang/tunisia/ar/holidays.json +++ b/lang/tunisia/ar/holidays.json @@ -7,10 +7,16 @@ "Women's Day": "عيد المرأة", "Evacuation Day": "عيد الجلاء", "Revolution and Youth Day": "عيد الثورة والشباب", - "Islamic new year": "رأس السنة الهجرية", - "Birthday of the Prophet Mohamed": "المولد النبوي الشريف", - "Eid al-Fitr": "عيد الفطر", - "Eid al-Adha": "عيد الإضحى", + "Eid al-Fitr": "عيد الفطر المبارك", + "Eid al-Fitr Day 2": "عيد الفطر المبارك", + "Eid al-Fitr Day 3": "عيد الفطر المبارك", + "Eid al-Adha": "عيد الأضحى المبارك", + "Eid al-Adha Day 2": "عيد الأضحى المبارك", + "Eid al-Adha Day 3": "عيد الأضحى المبارك", + "Eid al-Adha Day 4": "عيد الأضحى المبارك", + "Islamic New Year": "رأس السنة الهجرية", + "Birthday of the Prophet Muhammad": "المولد النبوي الشريف", + "Arafat Day": "يوم عرفة (وقفة عيد الأضحى)", "Day": "يوم" } diff --git a/lang/tunisia/en/holidays.json b/lang/tunisia/en/holidays.json index 83b90061c..3cfce7770 100644 --- a/lang/tunisia/en/holidays.json +++ b/lang/tunisia/en/holidays.json @@ -7,10 +7,16 @@ "Women's Day": "Women's Day", "Evacuation Day": "Evacuation Day", "Revolution and Youth Day": "Revolution and Youth Day", - "Islamic new year": "Islamic new year", - "Birthday of the Prophet Mohamed": "Birthday of the Prophet Mohamed", "Eid al-Fitr": "Eid al-Fitr", + "Eid al-Fitr Day 2": "Eid al-Fitr", + "Eid al-Fitr Day 3": "Eid al-Fitr", "Eid al-Adha": "Eid al-Adha", + "Eid al-Adha Day 2": "Eid al-Adha", + "Eid al-Adha Day 3": "Eid al-Adha", + "Eid al-Adha Day 4": "Eid al-Adha", + "Islamic New Year": "Islamic new year", + "Birthday of the Prophet Muhammad": "Birthday of the Prophet Mohamed", + "Arafat Day": "Arafat Day", "Day": "Day" } diff --git a/lang/tunisia/fr/holidays.json b/lang/tunisia/fr/holidays.json index 456634c3b..dfeb7826e 100644 --- a/lang/tunisia/fr/holidays.json +++ b/lang/tunisia/fr/holidays.json @@ -7,10 +7,16 @@ "Women's Day": "Fête de la femme", "Evacuation Day": "Fête d'évacuation", "Revolution and Youth Day": "Fête de la Révolution et de la Jeunesse", - "Islamic new year": "Nouvel an islamique", - "Birthday of the Prophet Mohamed": "Anniversaire du prophète Mohamed", "Eid al-Fitr": "Eid al-Fitr", + "Eid al-Fitr Day 2": "Eid al-Fitr", + "Eid al-Fitr Day 3": "Eid al-Fitr", "Eid al-Adha": "Eid al-Adha", + "Eid al-Adha Day 2": "Eid al-Adha", + "Eid al-Adha Day 3": "Eid al-Adha", + "Eid al-Adha Day 4": "Eid al-Adha", + "Islamic New Year": "Nouvel an islamique", + "Birthday of the Prophet Muhammad": "Anniversaire du prophète Mohamed", + "Arafat Day": "Arafat Day", "Day": "Jour" } diff --git a/src/Countries/Tunisia.php b/src/Countries/Tunisia.php index eafdd7a55..0d142ed24 100644 --- a/src/Countries/Tunisia.php +++ b/src/Countries/Tunisia.php @@ -2,11 +2,17 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; +use Spatie\Holidays\Calendars\IslamicCalendar; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; +use Spatie\Holidays\Contracts\Islamic; -class Tunisia extends Country +class Tunisia extends Country implements HasTranslations, Islamic { - private const IslamicNewYear = [ + use IslamicCalendar; + use Translatable; + + private const islamicNewYear = [ 1970 => "03-08", 1971 => "02-26", 1973 => "02-03", @@ -76,7 +82,7 @@ class Tunisia extends Country 2036 => "02-27", 2037 => "02-16" ]; - public const ProphetMohammedBirthday = [ + public const prophetMuhammadBirthday = [ 1970 => "05-17", 1971 => "05-07", 1972 => "04-25", @@ -146,7 +152,7 @@ class Tunisia extends Country 2036 => "05-07", 2037 => "04-27" ]; - public const EidAlFitr = [ + public const eidAlFitr = [ 1970 => "12-11", 1971 => "11-30", 1972 => "11-20", @@ -216,7 +222,7 @@ class Tunisia extends Country 2036 => "12-02", 2037 => "11-20", ]; - public const EidAlAdha = [ + public const eidAlAdha = [ 1970 => "02-17", 1971 => "02-06", 1972 => "01-27", @@ -295,6 +301,11 @@ public function countryCode(): string return 'tn'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { $revolutionHoliday = []; @@ -315,124 +326,22 @@ protected function allHolidays(int $year): array 'Republic Day' => '07-25', 'Women\'s Day' => '08-13', 'Evacuation Day' => '10-15', - ], $revolutionHoliday, $this->variableHolidays($year)); + ], $revolutionHoliday, $this->islamicHolidays($year)); } - /** - * The following holidays are considered public holidays in Tunisia. However, their dates vary each year, - * as they are based on the Islamic Hijri (lunar) calendar. These holidays do not have a fixed date and - * occur based on the lunar calendar sequence. The order listed reflects the chronological occurrence - * of these holidays throughout the year. - * @param int $year - * @return array - */ - protected function variableHolidays(int $year): array + public function islamicHolidays(int $year): array { + $eidAlFitr = $this->eidAlFitr($year); + $eidAlAdha = $this->eidAlAdha($year); + return array_merge( - $this->getIslamicHolidays( - year: $year, - holidays: self::IslamicNewYear, - label: 'Islamic new year' - ), - $this->getIslamicHolidays( - year: $year, - holidays: self::ProphetMohammedBirthday, - label: 'Birthday of the Prophet Mohamed' - ), - $this->getIslamicHolidays( - year: $year, - holidays: self::EidAlFitr, - label: 'Eid al-Fitr', - day: 2 - ), - $this->getIslamicHolidays( - year: $year, - holidays: self::EidAlAdha, - label: 'Eid al-Adha', - day: 3 - ) + [ + 'Islamic New Year' => $this->islamicNewYear($year), + 'Birthday of the Prophet Muhammad' => $this->prophetMuhammadBirthday($year), + ], + $this->convertPeriods('Eid al-Adha', $year, $eidAlAdha[0]), + $this->convertPeriods('Eid al-Fitr', $year, $eidAlFitr[0]), ); } - /** - * @param array> $holidays - * @return array - */ - protected function getIslamicHolidays( - int $year, - array $holidays, - string $label, - int $day = 1, - ): array - { - $islamicHolidays = []; - $counter = 0; - - if ($year != 1970) { - $previousHoliday = is_array($holidays[$year - 1]) ? $holidays[$year - 1][1] : $holidays[$year - 1]; - - $previousHoliday = CarbonImmutable::createFromFormat('Y-m-d', ($year - 1) . '-' . $previousHoliday); - - if ($previousHoliday->addDays($day - 1)->year == $year) { - $islamicHolidays = $this->prepareHolidays( - holiday: $previousHoliday, - day: $day, - label: $label, - filterYear: $year - ); - $counter++; - } - } - - $currentYearHolidays = is_array($holidays[$year]) ? $holidays[$year] : [$holidays[$year]]; - - foreach ($currentYearHolidays as $currentYearHoliday) { - $currentYearHoliday = CarbonImmutable::createFromFormat('Y-m-d', "$year-$currentYearHoliday"); - - $islamicHolidays = array_merge($islamicHolidays, $this->prepareHolidays( - holiday: $currentYearHoliday, - day: $day, - label: $label, - filterYear: $year, - prefix: $counter ? ($counter + 1) . '. ' : '' - )); - $counter++; - } - - if ($year != 2037) { - $nextHoliday = is_array($holidays[$year + 1]) ? $holidays[$year + 1][1] : $holidays[$year + 1]; - - $nextHoliday = CarbonImmutable::createFromFormat('Y-m-d', ($year + 1) . '-' . $nextHoliday); - - if ($nextHoliday->addDays(-1)->year == $year) { - $islamicHolidays = array_merge($islamicHolidays, $this->prepareHolidays( - holiday: $nextHoliday, - day: $day, - label: $label, - filterYear: $year, - prefix: $counter ? ($counter + 1) . '. ' : '' - )); - } - } - - return $islamicHolidays; - } - - /** @return array */ - protected function prepareHolidays( - CarbonImmutable $holiday, - int $day, - string $label, - int $filterYear, - string $prefix = '' - ): array - { - $holidays = []; - - foreach (range(1, $day) as $range) { - $holidays[$prefix . $label . ' ' . $range . '. Day'] = $holiday->addDays($range - 1); - } - - return array_filter($holidays, fn($holiday) => $holiday->year == $filterYear); - } } diff --git a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays_2024.snap b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2024____2024_.snap similarity index 60% rename from tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays_2024.snap rename to tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2024____2024_.snap index 47f554f65..ba65c6b6c 100644 --- a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays_2024.snap +++ b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2024____2024_.snap @@ -12,31 +12,19 @@ "date": "2024-04-09" }, { - "name": "Eid al-Fitr 1. Day", - "date": "2024-04-10" - }, - { - "name": "Eid al-Fitr 2. Day", - "date": "2024-04-11" + "name": "Eid al-Fitr", + "date": "2024-04-12" }, { "name": "Labour Day", "date": "2024-05-01" }, { - "name": "Eid al-Adha 1. Day", - "date": "2024-06-17" - }, - { - "name": "Eid al-Adha 2. Day", - "date": "2024-06-18" - }, - { - "name": "Eid al-Adha 3. Day", - "date": "2024-06-19" + "name": "Eid al-Adha", + "date": "2024-06-20" }, { - "name": "Islamic new year 1. Day", + "name": "Islamic new year", "date": "2024-07-07" }, { @@ -48,7 +36,7 @@ "date": "2024-08-13" }, { - "name": "Birthday of the Prophet Mohamed 1. Day", + "name": "Birthday of the Prophet Mohamed", "date": "2024-09-15" }, { diff --git a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays_2025.snap b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2025____2025_.snap similarity index 60% rename from tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays_2025.snap rename to tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2025____2025_.snap index 703fab7c1..c507fd12e 100644 --- a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisian_holidays_2025.snap +++ b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2025____2025_.snap @@ -8,12 +8,8 @@ "date": "2025-03-20" }, { - "name": "Eid al-Fitr 1. Day", - "date": "2025-03-31" - }, - { - "name": "Eid al-Fitr 2. Day", - "date": "2025-04-01" + "name": "Eid al-Fitr", + "date": "2025-04-02" }, { "name": "Martyrs' Day", @@ -24,19 +20,11 @@ "date": "2025-05-01" }, { - "name": "Eid al-Adha 1. Day", - "date": "2025-06-07" - }, - { - "name": "Eid al-Adha 2. Day", - "date": "2025-06-08" - }, - { - "name": "Eid al-Adha 3. Day", - "date": "2025-06-09" + "name": "Eid al-Adha", + "date": "2025-06-10" }, { - "name": "Islamic new year 1. Day", + "name": "Islamic new year", "date": "2025-06-26" }, { @@ -48,7 +36,7 @@ "date": "2025-08-13" }, { - "name": "Birthday of the Prophet Mohamed 1. Day", + "name": "Birthday of the Prophet Mohamed", "date": "2025-09-04" }, { diff --git a/tests/Countries/TunisiaTest.php b/tests/Countries/TunisiaTest.php index 07dfe7b11..a241fd2ec 100644 --- a/tests/Countries/TunisiaTest.php +++ b/tests/Countries/TunisiaTest.php @@ -5,8 +5,8 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate tunisian holidays 2024', function () { - CarbonImmutable::setTestNow('2024-01-01'); +it('can calculate tunisia holidays', function ($year) { + CarbonImmutable::setTestNow($year . '-01-01'); $holidays = Holidays::for(country: 'tn')->get(); @@ -15,31 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -}); - -it('can calculate tunisian holidays 2025', function () { - CarbonImmutable::setTestNow('2025-01-01'); - - $holidays = Holidays::for(country: 'tn')->get(); - - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); - - expect(formatDates($holidays))->toMatchSnapshot(); -}); - -//it('can calculate tunisian holidays list', function () { -// -// $result = []; -// for ($i = 1970; $i <= 2037; $i++) { -// CarbonImmutable::setTestNowAndTimezone("$i-01-01"); -// $holidays = Holidays::for(country: 'tn')->get(); -// //dd($holidays); -// $result[$i] = formatDates($holidays)[0]['date']; -// } -// //dd($result); -// file_put_contents('fitr.json', json_encode($result)); -// //file_put_contents('hijri.bin', serialize($result)); -//}); - +})->with([2024, 2025]);