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 Holidays - Pakistan #19

Merged
merged 5 commits into from
Jun 13, 2024
Merged
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
8 changes: 8 additions & 0 deletions lang/pakistan/ur/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Kashmir Solidarity Day": "یوم یکجہتی کشمیر",
"Pakistan Day": "یوم پاکستان",
"Labour Day": "مزدورں کادن",
"Independence Day": "یوم آزادی",
"Iqbal Day": "یوم اقبال",
"Quaid-e-Azam Day": "قائداعظم کا یوم پیدائش"
}
32 changes: 32 additions & 0 deletions src/Countries/Pakistan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Pakistan extends Country
{
public function countryCode(): string
{
return 'pk';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Kashmir Solidarity Day' => '02-05',
Nielsvanpach marked this conversation as resolved.
Show resolved Hide resolved
'Pakistan Day' => '03-23',
'Labour Day' => '05-01',
'Independence Day' => '08-14',
'Iqbal Day' => '11-09',
'Quaid-e-Azam Day' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
// The variable holidays are all follow lunar calendar so their dates are not confirmed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the implementation, the solution provides the dates but there is no surety that the calendar will follow thsoe exact dates. Should I go for it anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't copy-paste the Turkey solution. But a similar approach can be done for Pakistan?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nielsvanpach I tried adapting the solution. The problem is, that we have 4 different sets of holidays that follow the lunar calendar(total of 10 holidays) and it is making the code a lot more complex and even after that, the dates will not be accurate.

return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"name": "Kashmir Solidarity Day",
"date": "2024-02-05"
},
{
"name": "Pakistan Day",
"date": "2024-03-23"
},
{
"name": "Labour Day",
"date": "2024-05-01"
},
{
"name": "Independence Day",
"date": "2024-08-14"
},
{
"name": "Iqbal Day",
"date": "2024-11-09"
},
{
"name": "Quaid-e-Azam Day",
"date": "2024-12-25"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/PakistanTest.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 pakistan holidays', function () {
CarbonImmutable::setTestNow('2024-01-01');

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

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

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