Skip to content

Commit

Permalink
its full auto now
Browse files Browse the repository at this point in the history
  • Loading branch information
bo3bdo committed Jan 26, 2024
1 parent 2b8900f commit 1126115
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 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/pint": "^1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -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": "المولد النبوي الشريف",
Expand Down
50 changes: 36 additions & 14 deletions src/Countries/Bahrain.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;
use GeniusTS\HijriDate\Hijri;

class Bahrain extends Country
{
Expand All @@ -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<string, CarbonImmutable> */
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 1126115

Please sign in to comment.