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 Jordan holidays #209

Closed
wants to merge 7 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
6 changes: 6 additions & 0 deletions lang/jordan/ar/holidays.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"New Year\n's Day": "يوم رأس السنة",
"Independence Day": "عيد الاستقلال الاردني",
"Labor": "عيد العمال",
"Christmas Day": "عيد الميلاد المجيد"
}
42 changes: 42 additions & 0 deletions src/Calendars/Islamic/arafat-holidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

return [

'jo' => [
Copy link
Member

Choose a reason for hiding this comment

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

Can you use class consts for this? Have a look at Egypt or Bahrain

Copy link
Author

Choose a reason for hiding this comment

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

@Nielsvanpach
Why I used this approach:

  1. It's hard to read around 200 lines of code to read the elements.
  2. in some countries the holidays are shared or in the same region.
  3. at the end the Islamic directory is loadable.

Copy link
Member

Choose a reason for hiding this comment

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

2 and 3 seem valid points.

Although, using jo as a key doesn't feel like the way to go for being shareable across countries?

Also, if you have a look at Turkey, I prefer that format. What the benefit of using the extra date key?

Also, for multiday holidays it's possible to have it twice in a single year:

1999 => '01-19',
2000 => [
    '01-08',
     '12-27',
],

Copy link
Author

Choose a reason for hiding this comment

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

jo it may change,

date is more readable,

The third note is valid.

'dates' => [
2005 => ['date' => '01-21'],
2006 => ['date' => '01-10'],
2007 => ['date' => '01-01'],
2008 => ['date' => '12-09'],
2009 => ['date' => '11-26'],
2010 => ['date' => '11-15'],
2011 => ['date' => '11-05'],
2012 => ['date' => '10-25'],
2013 => ['date' => '10-15'],
2014 => ['date' => '10-04'],
2015 => ['date' => '09-23'],
2016 => ['date' => '09-11'],
2017 => ['date' => '08-31'],
2018 => ['date' => '08-20'],
2019 => ['date' => '08-10'],
2020 => ['date' => '07-30'],
2021 => ['date' => '07-19'],
2022 => ['date' => '07-09'],
2023 => ['date' => '06-27'],
2024 => ['date' => '06-16'],
2025 => ['date' => '06-06'],
2026 => ['date' => '05-26'],
2027 => ['date' => '05-16'],
2028 => ['date' => '05-05'],
2029 => ['date' => '04-24'],
2030 => ['date' => '04-13'],
2031 => ['date' => '04-02'],
2032 => ['date' => '03-21'],
2033 => ['date' => '03-11'],
2034 => ['date' => '03-01'],
2035 => ['date' => '02-18'],
2036 => ['date' => '02-07'],
2037 => ['date' => '01-26']
], 'duration' => 1
]
];
42 changes: 42 additions & 0 deletions src/Calendars/Islamic/ashura-holidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

return [

'jo' => [
'dates' => [
2005 => ['date' => '02-19'],
2006 => ['date' => '02-09'],
2007 => ['date' => '01-29'],
2008 => ['date' => '01-19'],
2009 => ['date' => '12-27'],
2010 => ['date' => '12-16'],
2011 => ['date' => '12-06'],
2012 => ['date' => '11-25'],
2013 => ['date' => '11-15'],
2014 => ['date' => '11-04'],
2015 => ['date' => '10-24'],
2016 => ['date' => '10-13'],
2017 => ['date' => '10-02'],
2018 => ['date' => '09-21'],
2019 => ['date' => '09-10'],
2020 => ['date' => '08-30'],
2021 => ['date' => '08-19'],
2022 => ['date' => '08-08'],
2023 => ['date' => '07-28'],
2024 => ['date' => '07-17'],
2025 => ['date' => '07-07'],
2026 => ['date' => '06-26'],
2027 => ['date' => '06-15'],
2028 => ['date' => '06-04'],
2029 => ['date' => '05-24'],
2030 => ['date' => '05-13'],
2031 => ['date' => '05-02'],
2032 => ['date' => '04-20'],
2033 => ['date' => '04-10'],
2034 => ['date' => '03-30'],
2035 => ['date' => '03-19'],
2036 => ['date' => '03-08'],
2037 => ['date' => '02-25']
], 'duration' => 1
]
];
42 changes: 42 additions & 0 deletions src/Calendars/Islamic/eid-al-adha-holidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

return [

'jo' => [
'dates' => [
2005 => ['date' => '01-22'],
2006 => ['date' => '01-11'],
2007 => ['date' => '01-02'],
2008 => ['date' => '12-10'],
2009 => ['date' => '11-27'],
2010 => ['date' => '11-16'],
2011 => ['date' => '11-06'],
2012 => ['date' => '10-26'],
2013 => ['date' => '10-16'],
2014 => ['date' => '10-05'],
2015 => ['date' => '09-24'],
2016 => ['date' => '09-12'],
2017 => ['date' => '08-31'],
2018 => ['date' => '08-21'],
2019 => ['date' => '08-11'],
2020 => ['date' => '07-31'],
2021 => ['date' => '07-20'],
2022 => ['date' => '07-09'],
2023 => ['date' => '06-28'],
2024 => ['date' => '06-17'],
2025 => ['date' => '06-07'],
2026 => ['date' => '05-27'],
2027 => ['date' => '05-17'],
2028 => ['date' => '05-06'],
2029 => ['date' => '04-25'],
2030 => ['date' => '04-14'],
2031 => ['date' => '04-03'],
2032 => ['date' => '03-22'],
2033 => ['date' => '03-12'],
2034 => ['date' => '03-02'],
2035 => ['date' => '02-19'],
2036 => ['date' => '02-08'],
2037 => ['date' => '01-27']
], 'duration' => 4
]
];
42 changes: 42 additions & 0 deletions src/Calendars/Islamic/eid-al-fitr-holidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

return [

'jo' => [
'dates' => [
2005 => ['date' => '11-04'],
2006 => ['date' => '10-24'],
2007 => ['date' => '10-13'],
2008 => ['date' => '10-02'],
2009 => ['date' => '09-21'],
2010 => ['date' => '09-10'],
2011 => ['date' => '08-30'],
2012 => ['date' => '08-19'],
2013 => ['date' => '08-08'],
2014 => ['date' => '07-28'],
2015 => ['date' => '07-17'],
2016 => ['date' => '07-07'],
2017 => ['date' => '06-26'],
2018 => ['date' => '06-15'],
2019 => ['date' => '06-05'],
2020 => ['date' => '05-24'],
2021 => ['date' => '05-13'],
2022 => ['date' => '05-02'],
2023 => ['date' => '04-20'],
2024 => ['date' => '04-10'],
2025 => ['date' => '03-31'],
2026 => ['date' => '03-21'],
2027 => ['date' => '03-10'],
2028 => ['date' => '02-27'],
2029 => ['date' => '02-15'],
2030 => ['date' => '02-04'],
2031 => ['date' => '01-25'],
2032 => ['date' => '01-15'],
2033 => ['date' => '01-03'],
2034 => ['date' => '12-13'],
2035 => ['date' => '12-02'],
2036 => ['date' => '11-20'],
2037 => ['date' => '11-09']
], 'duration' => 3
]
];
42 changes: 42 additions & 0 deletions src/Calendars/Islamic/islamic-new-year-holidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

return [

'jo' => [
'dates' => [
2005 => ['date' => '02-10'],
2006 => ['date' => '01-31'],
2007 => ['date' => '01-20'],
2008 => ['date' => '01-10'],
2009 => ['date' => '12-18'],
2010 => ['date' => '12-07'],
2011 => ['date' => '11-27'],
2012 => ['date' => '11-15'],
2013 => ['date' => '11-05'],
2014 => ['date' => '10-25'],
2015 => ['date' => '10-14'],
2016 => ['date' => '10-03'],
2017 => ['date' => '09-22'],
2018 => ['date' => '09-11'],
2019 => ['date' => '08-31'],
2020 => ['date' => '08-20'],
2021 => ['date' => '08-09'],
2022 => ['date' => '07-30'],
2023 => ['date' => '07-19'],
2024 => ['date' => '07-08'],
2025 => ['date' => '06-06'],
2026 => ['date' => '06-17'],
2027 => ['date' => '06-07'],
2028 => ['date' => '05-26'],
2029 => ['date' => '05-15'],
2030 => ['date' => '05-05'],
2031 => ['date' => '04-24'],
2032 => ['date' => '04-12'],
2033 => ['date' => '04-01'],
2034 => ['date' => '03-22'],
2035 => ['date' => '03-12'],
2036 => ['date' => '02-29'],
2037 => ['date' => '02-17']
], 'duration' => 1
]
];
42 changes: 42 additions & 0 deletions src/Calendars/Islamic/prophet-mohammed-birthday-holidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

return [

'jo' => [
'dates' => [
2005 => ['date' => '04-21'],
2006 => ['date' => '04-11'],
2007 => ['date' => '03-31'],
2008 => ['date' => '03-20'],
2009 => ['date' => '03-09'],
2010 => ['date' => '02-26'],
2011 => ['date' => '02-16'],
2012 => ['date' => '02-05'],
2013 => ['date' => '01-24'],
2014 => ['date' => '01-13'],
2015 => ['date' => '12-23'],
2016 => ['date' => '12-12'],
2017 => ['date' => '12-01'],
2018 => ['date' => '11-20'],
2019 => ['date' => '11-09'],
2020 => ['date' => '10-29'],
2021 => ['date' => '10-21'],
2022 => ['date' => '10-08'],
2023 => ['date' => '09-28'],
2024 => ['date' => '09-16'],
2025 => ['date' => '09-06'],
2026 => ['date' => '08-26'],
2027 => ['date' => '08-15'],
2028 => ['date' => '08-04'],
2029 => ['date' => '07-25'],
2030 => ['date' => '07-14'],
2031 => ['date' => '07-03'],
2032 => ['date' => '06-21'],
2033 => ['date' => '06-10'],
2034 => ['date' => '05-31'],
2035 => ['date' => '05-21'],
2036 => ['date' => '05-09'],
2037 => ['date' => '04-29']
], 'duration' => 1
]
];
44 changes: 44 additions & 0 deletions src/Concerns/IslamicHolidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Spatie\Holidays\Concerns;

use Carbon\CarbonImmutable;

trait IslamicHolidays
Copy link
Member

Choose a reason for hiding this comment

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

We already have an IslamicCalendar trait which you can use

Copy link
Author

@yousefdev20 yousefdev20 Mar 22, 2024

Choose a reason for hiding this comment

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

This trait depends on the constants variable and I explained the issue in the above replay.

{
protected function getIslamicHolidays(int $year): array
{
$countryCode = $this->countryCode();
$dates = [];

foreach (glob(__DIR__ . '/../../src/Calendars/Islamic/*.php') as $file) {
$basename = basename($file, '.php');
$holidayName = ucwords(str_replace("-", " ", $basename));

$eventData = require $file;

if (isset($eventData[$countryCode])) {
$event = $eventData[$countryCode];

if (isset($event['dates'][$year]['date'])) {
$holidayDate = $event['dates'][$year]['date'];
$duration = $eventData[$countryCode]['duration'];

if ($duration > 1) {
for ($i = 0; $i < $duration; $i++) {
$dates["$holidayName - " . ($i + 1)] = CarbonImmutable::createFromFormat(
'Y-m-d', "$year-$holidayDate"
)->addDays($i)->format('m-d');
}
} else {
$dates[$holidayName] = CarbonImmutable::createFromFormat(
'Y-m-d', "$year-$holidayDate"
)->format('m-d');
}
}
}
}

return $dates;
}
}
45 changes: 45 additions & 0 deletions src/Concerns/WeekendHolidays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Spatie\Holidays\Concerns;

use RuntimeException;
use Carbon\CarbonPeriod;
use Carbon\CarbonImmutable;

trait WeekendHolidays
Copy link
Member

Choose a reason for hiding this comment

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

I think the Observable trait is what you need

{
/**
* @var array<int>
*/
protected array $weekendDays = [];

/**
* @param int|array $days
* @return void
*/
protected function setTheWeekendDays(int|array $days): void
{
$this->weekendDays = array_unique([...$this->weekendDays, ...(array) $days]);
}

/**
* @param int $year
* @return array
*/
protected function getWeekendHolidays(int $year): array
{
$dates = [];

$date = CarbonImmutable::create($year);

foreach ($this->weekendDays as $weekendDay) {
foreach (CarbonPeriod::create($date->startOfMonth(), $date->endOfYear()) as $key => $day) {
if ($day->dayOfWeek === $weekendDay) {
$dates['Weekend - ' . $day->dayName . ' - ' . $key] = $day->format('m-d');
}
}
}

return $dates;
}
}
43 changes: 43 additions & 0 deletions src/Countries/Jordan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonInterface;
use Spatie\Holidays\Concerns\Translatable;
use Spatie\Holidays\Concerns\IslamicHolidays;
use Spatie\Holidays\Concerns\WeekendHolidays;
use Spatie\Holidays\Contracts\HasTranslations;

class Jordan extends Country implements HasTranslations
{
use IslamicHolidays, WeekendHolidays, Translatable;
public function countryCode(): string
{
return 'jo';
}

public function defaultLocale(): string
{
return 'en';
}

protected function allHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
'Labor' => '05-01',
'Independence Day' => '05-25',
'Christmas Day' => '12-25',
], $this->variableHolidays($year));
}

protected function variableHolidays(int $year): array

Check failure on line 34 in src/Countries/Jordan.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Jordan::variableHolidays() return type has no value type specified in iterable type array.
{
$this->setTheWeekendDays([CarbonInterface::FRIDAY, CarbonInterface::SATURDAY]);
$weekendHolidays = $this->getWeekendHolidays($year);

$islamicHolidays = $this->getIslamicHolidays($year);

return [...$islamicHolidays, ...$weekendHolidays];
}
}
Loading
Loading