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 Moroccan Holidays #56

Merged
merged 6 commits into from
Jun 13, 2024
Merged

Conversation

YazidKHALDI
Copy link
Contributor

@YazidKHALDI YazidKHALDI commented Jan 18, 2024

This pull request enhances the support for Moroccan national holidays
Note:

  • Islamic holidays' dates are subject to change based on the Hijri calendar, and efforts will be made to ensure accurate and up-to-date information in subsequent releases.

Do I have the right to use geniusts/hijri-dates to convert Date convert Gregorian date to Hijri date and vice versa?
I will try to test it today to check how much it's accurate

* occur based on the lunar calendar sequence. The order listed reflects the chronological occurrence
* of these holidays throughout the year.
*/
return [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I have the right to use geniusts/hijri-dates to convert Date convert Gregorian date to Hijri date and vice versa ?
i will try to test it today to check how much it's accurate

Choose a reason for hiding this comment

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

It is a necessary feature to not exclude half the holidays from Muslim countries

Copy link
Member

Choose a reason for hiding this comment

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

I am not really familiar with this. Could you shortly explain what this package would do and how we could benefit from it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The geniusts/hijri-dates package is a reliable PHP library designed to facilitate the conversion between Gregorian and Hijri dates. In our case, it can be incredibly useful for handling Islamic holidays that are based on the Hijri calendar.

The Islamic calendar follows a lunar system, which means that its months and years are determined by the moon's phases. This leads to variations in the lengths of months and the occurrence of Islamic holidays. By integrating this package, we gain the ability to accurately convert dates between the Gregorian and Hijri calendars.

I am currently in the process of testing the package to ensure its efficacy. I have a slight doubt about its accuracy, but my friend from the Maldives has used it in his PR#63. I will conduct thorough testing today to evaluate its performance and accuracy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @Nielsvanpach,

I utilized the geniusts/hijri-dates package to compute Islamic holidays for Morocco. I have included tests for the years 2023, 2024, 2025, and 2026. The results match the date converter provided by the Minister of Religious Endowments and Islamic Affairs.

Please note that it's not possible to predict Islamic holidays with 100% certainty. Ministry observers use the naked-eye observation of the New Moon at the end of each lunar month to determine if the current month is 29 or 30 days, impacting the declaration of the new month.

Copy link
Member

@Nielsvanpach Nielsvanpach Jan 20, 2024

Choose a reason for hiding this comment

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

Thanks for that! Just for clarity; do countries with Islamic public holidays all have the same dates for them? So is Eid al-Fitr celebrated everywhere on the same day, or are there exceptions?

If so, is it possible to not limit this to only Morocco, but make the calculations accessible for all countries with Islamic holidays? I would prefer a single implementation for those calculations instead of it being scattered all around the codebase for different countries.

Copy link

@medilies medilies Jan 20, 2024

Choose a reason for hiding this comment

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

@Nielsvanpach It is common for Islamic countries but the phase of the moon is not the same everywhere; For example Eid Al-Fitr may occur on the 10th of April for Algeria and on the 11th of April for Morocco.

Also, the duration of days off may differ between countries, Some may take a week and some may take 2 days.

Btw, this #90 is also making use of the same package.

Copy link
Contributor Author

@YazidKHALDI YazidKHALDI Jan 21, 2024

Choose a reason for hiding this comment

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

@Nielsvanpach

The topic is more intricate than it seems, and there are ongoing debates in Islamic countries. There are two main differences between countries:

  1. Observation Methods: Not all countries share the same date due to differences of approximately ±1 day. This is because each country employs its own method to observe the new moon, whether through naked-eye observation, telescopes, or astronomical calculations. Some countries find it impossible to determine the new moon using the naked eye.

    As an illustration, consider the current Hijri month and the next one. If you check the Hijri date today in all Islamic countries, it will be 09/07/1445. To understand why they all have the same date, check this image, representing the visibility of the moon on the first day of the current Hijri month "Rajab" (source).

    In this image, all countries easily observe the new moon with the naked eye, leading them to declare the 13th of January 2024 as the first day of the month "Rajab."

    Now, observe the visibility of the moon on the first day of the next Hijri month in this image (source).

    You can see that only the countries of West Africa (Morocco, Algeria, etc.) can easily observe the new moon. They declare the 11th of February 2024 as the first day of the month "Shaban." However, Egypt and other Middle Eastern countries may face challenges in seeing the new moon. Consequently, some will declare February 11, 2024, as the first day based on astronomical calculations, while others will wait until February 12, 2024.

    To address these differences, I used an adjustment of -1 day to make the calculations more accurate for Morocco.

    Hijri::setDefaultAdjustment(-1);
  2. Holiday Duration: Another difference is the number of holidays and the number of days taken as holidays. For example, "Eid al-Fitr" is observed for just 2 days in Morocco, but it's 3 days in Algeria and 4 days in Saudi Arabia.

In conclusion, having the same date for all countries is challenging, and achieving 100% accuracy in calculations is difficult because each country has its own protocol for the observation of the new moon.

PS: I fixed the PHPStan failure.

@Nielsvanpach Nielsvanpach mentioned this pull request Jan 20, 2024
28 tasks
@wessama wessama mentioned this pull request Jan 21, 2024
@ahmedmansoor
Copy link
Contributor

I've created a new PR #186, (originally #63), in which I've added a Hijri Calendar trait that we can use geniusts/hijri-dates to calculate Hijri dates.

composer.json Outdated
"nesbot/carbon": "^2.72.1",
"ext-calendar": "*"
"ext-calendar": "*",
"geniusts/hijri-dates": "^1.1",
Copy link
Member

Choose a reason for hiding this comment

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

…unit test coverage for the new holiday addition
@YazidKHALDI
Copy link
Contributor Author

@Nielsvanpach
HI Niels
I hope you're doing well. I've made some updates to the project, , I've removed the dependency on the geniusts/hijri-dates package and integrated the calculation function provided by the Ministry of Endowments and Islamic Affairs in Morocco .

This change simplifies the codebase and reduces external dependencies,

thank you

Copy link
Member

@Nielsvanpach Nielsvanpach left a comment

Choose a reason for hiding this comment

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

Thanks for your efforts on this!


public function defaultLocale(): string
{
return 'en';
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be Arabic by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanx for the review

In fact, I assumed that the Package would be used globally and therefore set English as the default language.

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
// Calculate the current Hijri year based on the Gregorian year
Copy link
Member

Choose a reason for hiding this comment

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

You can have a look at other Islamic countries and how their lunar based holidays are resolved. For example: Turkey, Bahrein and Egypt.

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've reviewed the other contributions, and it seems they've hardcoded the expected dates of Islamic holidays. Personally, I don't find that approach ideal. Instead, I opted to use a date converter for more dynamism. While it may not be 100% accurate, it offers flexibility. If you still prefer the hardcoded holiday expectation dates, I'm willing to make the change tonight.

Copy link
Member

@Nielsvanpach Nielsvanpach left a comment

Choose a reason for hiding this comment

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

Thanks!

@Nielsvanpach Nielsvanpach merged commit dce5e2a into spatie:main Jun 13, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants