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

handle invalid timezones Australia/ACT and Europe/Kiev #343

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

kevinpapst
Copy link

@kevinpapst kevinpapst commented Aug 19, 2024

Fixes #342

I hope the code comments explain the reasoning behind the changes.

All my systems seem to support both variants, but I had multiple bugs raised about Australia/ACT and Europe/Kiev.
Can't say when this happens, maybe it depends on the tzdata lib on the system where PHP was compiled. Or some PHP builds remove all timezone name which are only so called "links".

In the official table (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones ) both problematic TZ are only links, so I replaced them with their real TZ identifier.

Edit: I used two approaches, so you can decide which way is the better one.
Use the correct TZ identifier directly (Sydney) or use the try&catch approach (Kiev).
Maybe try&catch in both places is the best approach for maximum BC?

stelgenhof and others added 14 commits January 16, 2024 21:31
…oduces undesired changes

Signed-off-by: Sacha Telgenhof <[email protected]>
* Update methods visibility in multiple Providers

Methods in several providers including Switzerland, South Korea, and Luxembourg among others have been updated from private to protected. These changes allow for better extensibility and customization of the Yasumi library. The methods affected are those calculating specific holidays in the different regions.
Using the latest version of the PHP CS configuration, update all source code to use the most recent code style and formatting rules. For the most part this updates the header comment and the strict type declaration. It should not have any affect on the working of the tests nor the main code.

Signed-off-by: Sacha Telgenhof <[email protected]>
The generator for the years on or after the establishment of the Portuguese
Republic Day did not honor the fact that this holiday was suspended in
2013, resulting in tests to fail for years between 2013 and 2016 (when
it was restored again).

Signed-off-by: Sacha Telgenhof <[email protected]>
One-time holiday was added on 30.11.2018 and removed 1.9. since 2024, because our Slovak government has officially decided that we don't need so many days to rest 🤦🏼
Implement provider for Iran
…in Brandenburg (azuyalabs#337)

* fix(Provider\Germany): pentecost is not an official holiday - except in Brandenburg (see azuyalabs#100)
@stelgenhof
Copy link
Member

Thank you very much @kevinpapst for this PR! Unfortunately there are sometimes backwards incompatible changes introduced in PHP. In the past there were similar BC issues with historical DST changes between PHP versions.

We could also move away from the timezone identifiers (type 3) altogether, and use the UTC offset (type 1) or the timezone abbreviation (type 2), as these seem less prone to changing. The benefit of the timezone identifier is of course it is more human friendlier than the other types.

@kevinpapst
Copy link
Author

Yeah, I fought in the past already with the Kiev removal, but that was in the scope of my time-tracking app, so I could take care of it myself. I use try&catch for it.

I think the timezone identifier is totally fine to use, it doesn't change regularly and the try&catch approach works flawless to handle this situation. Changing it to TZ offset would be a bigger BC break, as many of the $timezone variables are public and therefor you would change the public API.

How to move forward?

  1. Shall I change the the Australia class to try&catch as well?
  2. Never used psalm, what is the equivalent of @phpstan-ignore-line for the "dead catch" warning?

@stelgenhof
Copy link
Member

Yeah, wouldn't think the timezone identifier changes regularly either, but thought the others could be an option instead. However indeed that would break Yasumi's API :(

I think the try&catch approach is a good approach. Please go ahead and use the same for Australia. Let me check on that dead catch issue in regards to Psalm.

@kevinpapst
Copy link
Author

I already did change Australia.
And Psalm doesn't report it, it was only PHPStan.
Checks are green, ready for review/merge from my end.

@stelgenhof stelgenhof self-requested a review August 28, 2024 14:23
Copy link
Member

@stelgenhof stelgenhof left a comment

Choose a reason for hiding this comment

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

Looking good! Could add unit tests for this and update the Changelog as well?
Thanks!

@kevinpapst
Copy link
Author

Ok for the Changelog, but tell me how to test these changes.

The result depends on the environment / PHP runtime.

@thrashzone13
Copy link
Contributor

Hi @stelgenhof @kevinpapst !

I just wanted to suggest using phpversion() . It's self explaining and better than using a try catch

@kevinpapst
Copy link
Author

Does not depend on phpversion afaik, so this approach is not usable.
Afaik this depends on the libicu version PHP was compiled against (or something like that, not sure about the exact internals). But the issue happened with PHP 8.1 and 8.3 and I have enough systems with these version where it doesn't happen.

@stelgenhof
Copy link
Member

I was thinking the same to use the PHP version for testing. If that turns out to be difficult, we can forgo the tests :)

@stelgenhof
Copy link
Member

@kevinpapst Can you only update the changelog? If done, then I'll merge it. Thanks!

@kevinpapst
Copy link
Author

@stelgenhof Changelog adjusted: done.

Any chance you could create a bugfix release? I have production bugs with several users.

@@ -14,12 +14,15 @@ changes.

### Changed

- Holiday calculation methods in providers are now protected instead of private
- Holiday calculation methods in providers are now protected instead of private
Copy link
Author

Choose a reason for hiding this comment

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

sorry, that must have been my IDE 🤷

@stelgenhof
Copy link
Member

Sorry about the late reply. Somehow I missed any of the GitHub notifications.

@stelgenhof stelgenhof added this to the v2.8.0 milestone Oct 21, 2024
@stelgenhof stelgenhof force-pushed the develop branch 8 times, most recently from 4ef0ec7 to 6912aaa Compare October 25, 2024 14:52
@kevinpapst
Copy link
Author

kevinpapst commented Dec 9, 2024

Hello @stelgenhof ,

I keep on having users who run into this bug. I understand if you don't want to merge this: its open source, your product and there is no warranty given. But I am unfortunately getting bug/support requests every other week and I have no proper answer since a few months.

I don't want to cause you any inconvenience here, please don't get that wrong: I appreciate your work and wanna thank you for sharing Yasumi!

But I have to provide a bugfix after such a long time and I can't wait any longer. I don't want to maintain a fork, so I wanted to reach out one more time to ask, if you could share your plans. Is there any chance this gets incorporated anytime soon in a new release?
Is there anything I can do to push this forward?
Shall I recreate the PR from latest develop branch? The PR content doesn't look correct to me.

@kevinpapst
Copy link
Author

Just today:

[2024-12-11 10:11:44] [request] CRITICAL: Uncaught PHP Exception DateInvalidTimeZoneException: "DateTimeZone::__construct(): Unknown or bad timezone (Australia/ACT)" at DateTimeZoneFactory.php line 31 {"exception":"[object] (DateInvalidTimeZoneException(code: 0): DateTimeZone::__construct(): Unknown or bad timezone (Australia/ACT) at /www/htdocs/xxxxx/kimai/vendor/azuyalabs/yasumi/src/Yasumi/Provider/DateTimeZoneFactory.php:31)"} []

@stelgenhof
Copy link
Member

Hi @kevinpapst Let me have a look this weekend to make a release.

@stelgenhof stelgenhof force-pushed the develop branch 3 times, most recently from f3c55da to 054359c Compare December 23, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Unknown or bad timezone Australia/ACT
6 participants