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 National and Revolutionary Iran Holidays #146

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions src/Countries/Iran.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Iran extends Country
{
public function countryCode(): string
{
return 'ir';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Islamic Revolution Day' => '02-11',
alisalehi1380 marked this conversation as resolved.
Show resolved Hide resolved
'Nationalization of Oil Industry Day' => '03-19',
'Nowruz First Day' => '03-20',
'Nowruz Second Day' => '03-21',
'Nowruz Third Day' => '03-22',
'Nowruz Fourth Day' => '03-23',
'Islamic Republic Day' => '03-31',
'Nature Day' => '04-01',
'Death of Khomeini Day' => '06-03',
'Revolt of Khordad 15 Day' => '06-04',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
alisalehi1380 marked this conversation as resolved.
Show resolved Hide resolved
->setTimezone('Asia/Tehran');

return [
//add more holidays
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.

image
We have 2 types of holidays in Iran.
In the first step (this PR) I added national and revolutionary holidays because these types of holidays are always fixed and do not change every year.

We(Iran) only share the Ramadan and Eid al-Ghadir holidays with Turkey. So, I'm adding "Religious (Islamic) holidays" to another PR because I need to double-check with the solar calendar.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Would it make sense to return Farsi(?) by default instead of English?
You can add translations here: https://github.com/spatie/holidays/tree/main/lang

Copy link
Contributor Author

@alisalehi1380 alisalehi1380 Feb 1, 2024

Choose a reason for hiding this comment

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

Yes, Thank you for this. Return to Farsi language is much more useful for Farsi language users. ❤️
I applied this change.

];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "Islamic Revolution Day",
"date": "2024-02-11"
},
{
"name": "Nationalization of Oil Industry Day",
"date": "2024-03-19"
},
{
"name": "Nowruz First Day",
"date": "2024-03-20"
},
{
"name": "Nowruz Second Day",
"date": "2024-03-21"
},
{
"name": "Nowruz Third Day",
"date": "2024-03-22"
},
{
"name": "Nowruz Fourth Day",
"date": "2024-03-23"
},
{
"name": "Islamic Republic Day",
"date": "2024-03-31"
},
{
"name": "Nature Day",
"date": "2024-04-01"
},
{
"name": "Death of Khomeini Day",
"date": "2024-06-03"
},
{
"name": "Revolt of Khordad 15 Day",
"date": "2024-06-04"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/IranTest.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 iran holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
alisalehi1380 marked this conversation as resolved.
Show resolved Hide resolved

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

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

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