Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add New Country (Malaysia) #237

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/Countries/Malaysia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Malaysia extends Country
{
public function countryCode(): string
{
return 'my';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Tahun Baru' => '01-01',
'Hari Pekerja' => '05-01',
'Hari Kebangsaan' => '08-31',
'Hari Malaysia' => '09-16',
'Hari Keputeraan YDP Agong' => CarbonImmutable::parse("First Monday of June $year")->setTimezone('Asia/Kuala_Lumpur'),
'Hari Krismas' => '12-25',

], $this->variableHolidays($year));
}

protected function variableHolidays(int $year): array

Check failure on line 27 in src/Countries/Malaysia.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Malaysia::variableHolidays() return type has no value type specified in iterable type array.
{
return [
'Hari Keputeraan Yang Di-Pertuan Besar Negeri Sembilan' => '01-14',
'Hari Wilayah Persekutuan' => '02-01',
'Hari Ulang Tahun Pertabalan Sultan Terengganu' => '03-04',
'Hari Keputeraan Sultan Johor' => '03-23',
'Hari Keputeraan Sultan Terengganu' => '04-26',
'Hari Keputeraan Raja Perlis' => '05-17',
'Hari Keputeraan Sultan Kedah' => CarbonImmutable::parse("Third Sunday of June $year")->setTimezone('Asia/Kuala_Lumpur'),
'Harijadi Yang di-Pertua Negeri Pulau Pinang' => CarbonImmutable::parse("Second Saturday of July $year")->setTimezone('Asia/Kuala_Lumpur'),
'Hari Keputeraan Sultan Pahang' => '07-30',
'Harijadi Yang di-Pertua Negeri Melaka' => '08-24',
'Hari Keputeraan Sultan Kelantan' => '09-29',
'Harijadi Yang di-Pertua Negeri Sabah' => CarbonImmutable::parse("First Saturday of October $year")->setTimezone('Asia/Kuala_Lumpur'),
'Harijadi Yang di-Pertua Negeri Sarawak' => CarbonImmutable::parse("Second Saturday of October $year")->setTimezone('Asia/Kuala_Lumpur'),
'Hari Keputeraan Sultan Perak' => CarbonImmutable::parse("First Friday of November $year")->setTimezone('Asia/Kuala_Lumpur'),
'Hari Keputeraan Sultan Selangor' => '12-11'
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[
{
"name": "Tahun Baru",
"date": "2024-01-01"
},
{
"name": "Hari Keputeraan Yang Di-Pertuan Besar Negeri Sembilan",
"date": "2024-01-14"
},
{
"name": "Hari Wilayah Persekutuan",
"date": "2024-02-01"
},
{
"name": "Hari Ulang Tahun Pertabalan Sultan Terengganu",
"date": "2024-03-04"
},
{
"name": "Hari Keputeraan Sultan Johor",
"date": "2024-03-23"
},
{
"name": "Hari Keputeraan Sultan Terengganu",
"date": "2024-04-26"
},
{
"name": "Hari Pekerja",
"date": "2024-05-01"
},
{
"name": "Hari Keputeraan Raja Perlis",
"date": "2024-05-17"
},
{
"name": "Hari Keputeraan YDP Agong",
"date": "2024-06-03"
},
{
"name": "Hari Keputeraan Sultan Kedah",
"date": "2024-06-16"
},
{
"name": "Harijadi Yang di-Pertua Negeri Pulau Pinang",
"date": "2024-07-13"
},
{
"name": "Hari Keputeraan Sultan Pahang",
"date": "2024-07-30"
},
{
"name": "Harijadi Yang di-Pertua Negeri Melaka",
"date": "2024-08-24"
},
{
"name": "Hari Kebangsaan",
"date": "2024-08-31"
},
{
"name": "Hari Malaysia",
"date": "2024-09-16"
},
{
"name": "Hari Keputeraan Sultan Kelantan",
"date": "2024-09-29"
},
{
"name": "Harijadi Yang di-Pertua Negeri Sabah",
"date": "2024-10-05"
},
{
"name": "Harijadi Yang di-Pertua Negeri Sarawak",
"date": "2024-10-12"
},
{
"name": "Hari Keputeraan Sultan Perak",
"date": "2024-11-01"
},
{
"name": "Hari Keputeraan Sultan Selangor",
"date": "2024-12-11"
},
{
"name": "Hari Krismas",
"date": "2024-12-25"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/MalaysiaTest.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 malaysia holidays', function () {
CarbonImmutable::setTestNow('2024-01-01');

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

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

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