-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Added Canada provider #215
Conversation
Very nice! Thank you very much for this PR @lux Much appreciated as there were a few requests for Canada :) Cheers! Sacha |
This is great work! A few comments: Each provider should use a timezone relevant for the specific province. For national provider, I think it would be natural to use the timezone for the capital, Ottawa. Though not implemented throughout Yasumi, it is my personal opinion that translations for holidays implemented in more than one provider are better stored in translation files in |
I've updated all the timezones for Canada and each province/territory. There wasn't a timezone specific to Ottawa, but "America/Toronto" is the same timezone as Ottawa so I went with that. I wasn't sure how best to approach extracting translations since I don't see other countries in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just recently there is a change in the way the DateTimeZone class is used in the code. Using the DateTimeZoneFactory class helps improve the performance of the library. Please change the following (example):
$newyearsday = new DateTime("$this->year-01-01", new DateTimeZone($this->timezone));
to
$newyearsday = new DateTime("$this->year-01-01", DateTimeZoneFactory::getDateTimeZone($this->timezone));
The translations are not grouped by country but by holiday. E.g. Labour Day is already defined in $this->addHoliday(new Holiday(
'labourDay',
- ['en' => 'Labour Day', 'fr' => 'Fête du Travail'],
+ [],
new DateTime("first monday of september $this->year", DateTimeZoneFactory::getDateTimeZone($this->timezone)), For translations not already present, just create a new file with the day's short/internal name. The file will be loaded automatically. If a day has a different name in Canadian French than in “general” French, you can use the key |
@lux Thanks for making the latest changes! Looking a lot better now. One thing I noticed is that you have a lot of duplicate logic. For example VictoriaDay, Thanksgiving have the same code in the various Canadian states. You can simplify this by extracting these into a common function and move these to the Canada class for example (or even a separate class if you prefer). This way you can reuse the holiday logic in the various states (unless the logic is different of course). Cheers! Sacha |
@c960657 that makes sense. I'll look at changing that up. @stelgenhof I ended up duplicating those because of inconsistencies across Canada. Victoria Day, for example, is celebrated in 11 of 13 provinces/territories, called National Patriot's Day in Quebec, and not recognized in Newfoundland. Since provinces inherit from the country provider, I could move the method definition up a level but leave it to the provinces to call addHoliday() if that works better. Similarly, Thanksgiving is only recognized in 9 of 13. |
@lux Makes sense, however I would still recommend to make a common method for those states that share that common logic and make exceptions where needed. That would save time in (future) debugging and testing :) |
The shared holidays are only defined in the Canada provider now, and I've moved the main Canada holidays into translations but didn't have time to do the translations for the province-specific names yet. |
Thanks! It's looking good. Take your time :) |
No description provided.