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 Singapore Public Holiday #94

Closed

Conversation

captainjaypee01
Copy link

@captainjaypee01 captainjaypee01 commented Jan 18, 2024

Singapore Holidays

  • New Year's Day
  • Chinese New Year
  • Good Friday
  • Hari Raya Puasa
  • Labour Day
  • Vesak Day
  • Hari Raya Haji
  • National Day
  • Deepavali
  • Christmas Day

Changes

  • Replacement for Holidays. If falls on Sunday, Monday will be the replacement. For Chinese New Year, if the Day is Sunday and Monday then the Tuesday will be the replacement for Sunday.
  • Used IntlDateFormatter for accurate calendar calculations
  • Added Chinese Calendar to get the Chinese New Year and Vesak Day dates
  • Added Islamic Calendar to get the Hari Raya Puasa and Hari Raya Haji dates
  • Added Indian Calendar to get the Kartik month which is 8th month of the Indian Calendar and 10th month of the Gregorian Calendar.
  • Used the solaris/php-moon-phase for accurate computation of moon phases. Especially for Deepavali holiday, as this holiday is based on moon appearance

Additional Notes

  1. The solaris/php-moon-phase extension is required for this addition. It is referenced in the composer.json file.

References:

Singapore's Ministry of Manpower to reference the Holidays in Singapore
MOM Gov Public Holiday

Deepavali date is based on the appearance of the moon.
Deepavali is subject to change

Chinese Calendar
Islamic Calendar
Indian Calendar

@captainjaypee01 captainjaypee01 force-pushed the add-singapore-holiday branch 3 times, most recently from e0af794 to 182d6d4 Compare January 20, 2024 07:40
@captainjaypee01
Copy link
Author

I added REPLACEMENT feature when holiday is in Sunday

@captainjaypee01
Copy link
Author

Refactor replacement for Sunday holiday. Trying to think if it can implemented in the Holiday class but it seems that not all countries are doing the same process

@captainjaypee01
Copy link
Author

I added the Deepavali Holiday using the moon phases. I used the "solaris/php-moon-phase" package to determine the phases of the moon. I based the date using the Indian Calendar in Kartik month

@captainjaypee01 captainjaypee01 force-pushed the add-singapore-holiday branch 3 times, most recently from e84ea1b to 53d268d Compare January 20, 2024 19:50
@captainjaypee01
Copy link
Author

Rebased to the latest main branch

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.

We have a ChineseCalendar trait you can use: https://github.com/spatie/holidays/blob/main/src/Calendars/ChineseCalendar.php

For the Islamic & Indian calendars, could you use the same reusable approach as the ChineseCalendar trait? Thanks!

}

/** @return array<string, string|CarbonImmutable> */
protected function replacementForSunday(string $name, int $year, string $input, int $addDays = 0): array
Copy link
Member

Choose a reason for hiding this comment

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

Could you make this name & code more readable, so it's immediately obvious what it does?

Copy link
Author

Choose a reason for hiding this comment

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

I will review on this.

return (int) $hijriYear;
}

protected function chineseCalendar(string $input, int $year): string
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 you could use the ChineseCalendar trait

Copy link
Author

Choose a reason for hiding this comment

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

I will review on this.

}


protected function getIslamicFormatter(): IntlDateFormatter
Copy link
Member

@Nielsvanpach Nielsvanpach Jan 27, 2024

Choose a reason for hiding this comment

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

@thecaliskan would you want to help reviewing the Islamic part? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

@Nielsvanpach I will prepare a script and check it when I am available.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @thecaliskan and @Nielsvanpach I have updated my changes in this branch. You may want to check

Thanks

@captainjaypee01
Copy link
Author

Hi @Nielsvanpach, I have added the Islamic Calendar and Indian Calendar and I used the Chinese Calendar Trait.

Regarding Deepavali Date, I didn't include this holiday in the Indian Calendar. I was thinking of adding it but I'm not sure if all countries celebrating the Deepavali Date is the same with Singapore.

For the replacement function I renamed it to "replaceHolidayFallsOnSunday". This function is more on replacing the holidays in Singapore if it falls on Sunday. But if there's a consecutive holidays like in Chinese New Year which falls on Sunday and Monday , the Sunday will move to Tuesday as the replacement. I think not all countries doing this scenario.

@captainjaypee01
Copy link
Author

Hi @Nielsvanpach , I'm planning to add a function to check if the holiday is a regular or a replacement holiday.

@captainjaypee01
Copy link
Author

Updated the composer.json file to fix the conflict

@captainjaypee01
Copy link
Author

Hi @Nielsvanpach , is there anything that I need to add on this PR?

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.

Looks good!
I'm not sure if the IslamicCalendar gives proper results, as it was previously stated this is different from country to country.

"nesbot/carbon": "^2.72.1|^3.0"
"nesbot/carbon": "^2.72.1|^3.0",
"ext-calendar": "*",
"solaris/php-moon-phase": "^2.1"
Copy link
Member

Choose a reason for hiding this comment

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

solaris/php-moon-phase can be removed, I think?

Copy link
Author

Choose a reason for hiding this comment

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

I think I used the moon phase for deepavali event as this holiday is based on the moon phases

*
* @return array<string, string|CarbonImmutable> 
*/
protected function replaceHolidayFallsOnSunday(string $holidayName, int $year, string $input, int $moveDays = 1): array
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 you could use the Observable trait for this

Copy link
Author

Choose a reason for hiding this comment

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

I will convert this to Observable trait

@spatie-bot
Copy link

Dear contributor,

because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it.

@spatie-bot spatie-bot closed this Sep 25, 2024
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