Skip to content

Commit

Permalink
Add Maldivian holidays (#229)
Browse files Browse the repository at this point in the history
* Add Maldivian holidays

* Add missing constants for Islamic holidays in Maldives
  • Loading branch information
ahmedmansoor authored Jun 14, 2024
1 parent a94d259 commit dc17581
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 0 deletions.
191 changes: 191 additions & 0 deletions src/Countries/Maldives.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php

namespace Spatie\Holidays\Countries;

use Spatie\Holidays\Calendars\IslamicCalendar;
use Spatie\Holidays\Concerns\Translatable;
use Spatie\Holidays\Contracts\HasTranslations;
use Spatie\Holidays\Contracts\Islamic;

class Maldives extends Country implements HasTranslations, Islamic
{
use IslamicCalendar;
use Translatable;

protected const eidAlFitr = [
2020 => '05-24',
2021 => '05-13',
2022 => '05-02',
2023 => '04-20',
2024 => '04-10',
2025 => '03-31',
2026 => '03-21',
2027 => '03-10',
2028 => '02-27',
2029 => '02-15',
2030 => '02-04',
2031 => '01-25',
2032 => '01-15',
2033 => '01-03',
2034 => '12-13',
2035 => '12-02',
2036 => '11-20',
2037 => '11-09',
];

protected const arafat = [
2020 => '07-30',
2021 => '07-19',
2022 => '07-09',
2023 => '06-27',
2024 => '06-16',
2025 => '06-06',
2026 => '05-26',
2027 => '05-16',
2028 => '05-05',
2029 => '04-24',
2030 => '04-13',
2031 => '04-02',
2032 => '03-21',
2033 => '03-11',
2034 => '03-01',
2035 => '02-18',
2036 => '02-07',
2037 => '01-26',
];

protected const eidAlAdha = [
2020 => '07-31',
2021 => '07-20',
2022 => '07-09',
2023 => '06-28',
2024 => '06-17',
2025 => '06-07',
2026 => '05-27',
2027 => '05-17',
2028 => '05-06',
2029 => '04-25',
2030 => '04-14',
2031 => '04-03',
2032 => '03-22',
2033 => '03-12',
2034 => '03-02',
2035 => '02-19',
2036 => '02-08',
2037 => '01-27',
];

protected const islamicNewYear = [
2020 => '08-20',
2021 => '08-09',
2022 => '07-30',
2023 => '07-19',
2024 => '07-08',
2025 => '06-06',
2026 => '06-17',
2027 => '06-07',
2028 => '05-26',
2029 => '05-15',
2030 => '05-05',
2031 => '04-24',
2032 => '04-12',
2033 => '04-01',
2034 => '03-22',
2035 => '03-12',
2036 => '02-29',
2037 => '02-17',
];

protected const ashura = [
2020 => '08-30',
2021 => '08-19',
2022 => '08-08',
2023 => '07-28',
2024 => '07-17',
2025 => '07-07',
2026 => '06-26',
2027 => '06-15',
2028 => '06-04',
2029 => '05-24',
2030 => '05-13',
2031 => '05-02',
2032 => '04-20',
2033 => '04-10',
2034 => '03-30',
2035 => '03-19',
2036 => '03-08',
2037 => '02-25',
];

protected const prophetMuhammadBirthday = [
2020 => '10-29',
2021 => '10-21',
2022 => '10-08',
2023 => '09-28',
2024 => '09-16',
2025 => '09-06',
2026 => '08-26',
2027 => '08-15',
2028 => '08-04',
2029 => '07-25',
2030 => '07-14',
2031 => '07-03',
2032 => '06-21',
2033 => '06-10',
2034 => '05-31',
2035 => '05-21',
2036 => '05-09',
2037 => '04-29',
];

public function countryCode(): string
{
return 'mv';
}

public function defaultLocale(): string
{
return 'dv'; // Dhivehi, the language spoken in the Maldives
}

protected function allHolidays(int $year): array
{
$newHolidays = [];

if ($year >= 2015) {
$newHolidays['National Day'] = '01-24';
}

return array_merge([
"New Year's Day" => '01-01',
"Independence Day" => '07-26',
"Victory Day" => '11-03',
"Republic Day" => '11-11',
], $newHolidays, $this->islamicHolidays($year));
}

public function islamicHolidays(int $year): array
{
$eidAlFitr = $this->eidAlFitr($year);
$eidAlAdha = $this->eidAlAdha($year);

$holidays = array_merge(
$this->convertPeriods('Eid al-Adha', $year, $eidAlAdha[0], includeEve: true),
$this->convertPeriods('Eid al-Fitr', $year, $eidAlFitr[0], includeEve: true),
);

if (count($eidAlAdha) > 1) {
$holidays = array_merge($holidays,
$this->convertPeriods('2. Eid al-Adha', $year, $eidAlAdha[1], includeEve: true),
);
}

if (count($eidAlFitr) > 1) {
$holidays = array_merge($holidays,
$this->convertPeriods('2. Eid al-Fitr', $year, $eidAlFitr[1], includeEve: true),
);
}

return $holidays;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"name": "New Year's Day",
"date": "2024-01-01"
},
{
"name": "National Day",
"date": "2024-01-24"
},
{
"name": "Eid al-Fitr Eve",
"date": "2024-04-09"
},
{
"name": "Eid al-Fitr",
"date": "2024-04-10"
},
{
"name": "Eid al-Fitr Day 2",
"date": "2024-04-11"
},
{
"name": "Eid al-Fitr Day 3",
"date": "2024-04-12"
},
{
"name": "Eid al-Adha Eve",
"date": "2024-06-16"
},
{
"name": "Eid al-Adha",
"date": "2024-06-17"
},
{
"name": "Eid al-Adha Day 2",
"date": "2024-06-18"
},
{
"name": "Eid al-Adha Day 3",
"date": "2024-06-19"
},
{
"name": "Eid al-Adha Day 4",
"date": "2024-06-20"
},
{
"name": "Independence Day",
"date": "2024-07-26"
},
{
"name": "Victory Day",
"date": "2024-11-03"
},
{
"name": "Republic Day",
"date": "2024-11-11"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/MaldivesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate maldives holidays', function () {
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'mv')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();
});

0 comments on commit dc17581

Please sign in to comment.