Skip to content

Commit

Permalink
fix Tunisia Hijri Holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-wolf-gb committed Jan 18, 2024
1 parent abd492d commit ff904a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 24 additions & 6 deletions src/Countries/Tunisia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -33,12 +37,26 @@ protected function allHolidays(int $year): array
protected function variableHolidays(int $year): array

Check failure on line 37 in src/Countries/Tunisia.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Tunisia::variableHolidays() return type has no value type specified in iterable type 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"date": "2024-04-10"
},
{
"name": "Eid al-Fitr 2",
"name": "Eid al-Fitr - 2nd day",
"date": "2024-04-11"
},
{
Expand All @@ -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"
},
{
Expand All @@ -45,7 +45,7 @@
},
{
"name": "Birthday of the Prophet Muhammad",
"date": "2024-09-16"
"date": "2024-09-15"
},
{
"name": "Evacuation Day",
Expand Down

0 comments on commit ff904a6

Please sign in to comment.