diff --git a/composer.json b/composer.json index 9f8a2f7fb..a2b375768 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/pint": "^1.0", diff --git a/lang/bahrain/ar/bahrain.json b/lang/bahrain/ar/holidays.json similarity index 70% rename from lang/bahrain/ar/bahrain.json rename to lang/bahrain/ar/holidays.json index 595443359..82e518018 100644 --- a/lang/bahrain/ar/bahrain.json +++ b/lang/bahrain/ar/holidays.json @@ -1,13 +1,13 @@ { "New Year Day": "رأس السنة الميلادية", - "Eid al Fitr Holiday 1": "عيد الفطر", - "Eid al Fitr Holiday 2": "أجازة عيد الفطر", - "Eid al Fitr Holiday 3": "أجازة عيد الفطر", + "Eid al-Fitr Holiday 1": "عيد الفطر", + "Eid al-Fitr Holiday 2": "أجازة عيد الفطر", + "Eid al-Fitr Holiday 3": "أجازة عيد الفطر", "Labour Day": "عيد العمال", "Eid al Adha Holiday 1": "عيد الأضحى", "Eid al Adha Holiday 2": "أجازة عيد الأضحى", "Eid al Adha Holiday 3": "أجازة عيد الأضحى", - "Islamic New Year": "رأس السنة الهجرية", + "Islamic new year": "رأس السنة الهجرية", "Ashura Holiday 1": "عاشوراء", "Ashura Holiday 2": "أجازة عاشوراء", "Prophet Muhammads Birthday": "المولد النبوي الشريف", diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index a9d659c83..ceeab512b 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use GeniusTS\HijriDate\Hijri; class Bahrain extends Country { @@ -14,26 +15,47 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year Day' => '01-01', - 'Eid al Fitr Holiday 1' => '04-10', - 'Eid al Fitr Holiday 2' => '04-11', - 'Eid al Fitr Holiday 3' => '04-12', + 'New Year Day' => CarbonImmutable::createFromDate($year, 1, 1), 'Labour Day' => '05-01', - 'Eid al Adha Holiday 1' => '06-16', - 'Eid al Adha Holiday 2' => '06-17', - 'Eid al Adha Holiday 3' => '06-18', - 'Islamic New Year' => '07-07', - 'Ashura Holiday 1' => '07-16', - 'Ashura Holiday 2' => '07-17', - 'Prophet Muhammads Birthday' => '07-15', - 'National Day' => '12-16', - 'National Day Holiday' => '12-17', + 'Ashura Holiday 1' => CarbonImmutable::createFromDate($year, 7, 16), + 'Ashura Holiday 2' => CarbonImmutable::createFromDate($year, 7, 17), + 'National Day' => CarbonImmutable::createFromDate($year, 12, 16), + 'National Day Holiday' => CarbonImmutable::createFromDate($year, 12, 17), ], $this->variableHolidays($year)); } /** @return array */ protected function variableHolidays(int $year): array { - return []; + return [ + 'Islamic new year' => $this->getHijriDateAsGregorian(1, 1, $year + 1), + 'Prophet Muhammads Birthday' => $this->getHijriDateAsGregorian(12, 3, $year + 1), + 'Eid al-Fitr Holiday 1' => $this->getHijriDateAsGregorian(1, 10, $year, 1), + 'Eid al-Fitr Holiday 2' => $this->getHijriDateAsGregorian(2, 10, $year, 1), + 'Eid al-Fitr Holiday 3' => $this->getHijriDateAsGregorian(3, 10, $year, 1), + 'Eid al Adha Holiday 1' => $this->getHijriDateAsGregorian(10, 12, $year, 1), + 'Eid al Adha Holiday 2' => $this->getHijriDateAsGregorian(11, 12, $year, 1), + 'Eid al Adha Holiday 3' => $this->getHijriDateAsGregorian(12, 12, $year, 1), + ]; + } + + /** + * Convert Hijri dates to Gregorian + * @param int $hijriDay + * @param int $hijriMonth + * @param int $hijriYear + * @param int $adjustmentDays + * @return CarbonImmutable + */ + 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/BahrainTest/it_can_calculate_bahrain_holidays.snap b/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap index 6df6377cb..9cdc0229c 100644 --- a/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap +++ b/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap @@ -4,15 +4,15 @@ "date": "2024-01-01" }, { - "name": "Eid al Fitr Holiday 1", + "name": "Eid al-Fitr Holiday 1", "date": "2024-04-10" }, { - "name": "Eid al Fitr Holiday 2", + "name": "Eid al-Fitr Holiday 2", "date": "2024-04-11" }, { - "name": "Eid al Fitr Holiday 3", + "name": "Eid al-Fitr Holiday 3", "date": "2024-04-12" }, { @@ -21,24 +21,20 @@ }, { "name": "Eid al Adha Holiday 1", - "date": "2024-06-16" + "date": "2024-06-17" }, { "name": "Eid al Adha Holiday 2", - "date": "2024-06-17" + "date": "2024-06-18" }, { "name": "Eid al Adha Holiday 3", - "date": "2024-06-18" + "date": "2024-06-19" }, { - "name": "Islamic New Year", + "name": "Islamic new year", "date": "2024-07-07" }, - { - "name": "Prophet Muhammads Birthday", - "date": "2024-07-15" - }, { "name": "Ashura Holiday 1", "date": "2024-07-16" @@ -47,6 +43,10 @@ "name": "Ashura Holiday 2", "date": "2024-07-17" }, + { + "name": "Prophet Muhammads Birthday", + "date": "2024-09-15" + }, { "name": "National Day", "date": "2024-12-16"