-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Daylight Savings Time issue with PHP 8.1 #120
Comments
Hmm interesting, I copy/pasted your code to test this and got (tested with the latest master and various PHP versions on a Debian system):
What version of the library and of PHP are you using? Are you on Windows or Linux? It might be related to your setup. |
Wow, that is interesting indeed. I tested on PHP 8.1.9 and 8.1.11 on two environments: Ubuntu 18.04 and my local Mac. I wonder if there's an external library that PHP depends on to calculate timezone offsets and daylight savings time rules? |
Ah ah! I tested on PHP 8.1 with a Docker image and got:
So up to PHP 8.0 it works just fine, and then something changed in PHP 8.1... At least we're narrowing this down. |
I think PHP's date/time logic is powered by timelib. PHP 8.1.11 (current stable) includes timelib 2021.16, but there's a newer version, 2021.17, with several commits since the previous version. It was merged with php-src on 9/14, so I guess it will be available in PHP 8.1.12. I don't know how to test or apply the new timelib version in case it resolves this issue. But I guess the point of this issue is to understand why PHP's native |
Hmm at the moment no, I have no idea, but I'm testing. I changed the recurrence to DAILY to check, and switch back to central standard time do work, but with 1 day difference.
with php 8.1
with php 8.0
|
Interestingly, I do not observe the same behaviour for another timezone like
with php 8.1
with php 8.0
I tried with both 2AM and 3AM as a start time just in case, because the summer time switch is between 2am and 3am, but the behaviour is exactly the same. |
This code reproduces the problem, by essentially reproducing what is happening inside the library when it calculates occurrences. The library doesn't use
with PHP 8.0
with PHP 8.1
|
After testing a bit, my hypothesis is that because the "1am" time on the 6th of November in Chicago timezone literally exists twice (once in CDT, and then once again at 2am CDT / 1am CST), the But it seems with php 8.0, they both become winter time (in America/Chicago they both stayed in summer time)
with php 8.1 the modify +1 week stays in summer time 🤷
|
Thank you so much for such timely responses, @rlanvin. I greatly appreciate the work you put into building this excellent library. I couldn't find the cause of this weird DST issue, but we devised a workaround for our use case. We map events to hours on a weekly schedule, and the Nov 6 at 1 AM hour gave us trouble. Our workaround was to use a local, week-focused date format ( Anyway, thanks again! |
Ah, as you suspected, in PHP 8.1.0, the behavior of setTime changed:
|
I figured it out! It's an issue with createFromFormat. From the docs:
If we omit time from the format, the current time is assumed. $timezone = new \DateTimeZone('America/Chicago');
\DateTime::createFromFormat('Y z', '2022 309', $timezone);
// 2022-11-06T06:17:11-06:00 CST
\DateTime::createFromFormat('Y z H:i:s', '2022 309 00:00:00', $timezone);
// 2022-11-06T00:00:00-05:00 CDT Without the time, depending on the time of day that we calculate the date, it would have a different timezone offset. To fix this, we should set the time to 00:00:00 in the format and adjust with setTime. |
Oh wow, great find! That definitely explains why PHP 8.1 is returning different results. Your solution looks promising, especially since I had a lot of issues in the past with the fact that current time is assumed, but it's not obvious why it would solve the issue (I would need to test a bit to wrap my head around it). Thanks for submitting a PR - I think I'd like to add some unit tests for this bug to make sure the behaviour is now the same for all versions of PHP. Would you like to add them? If not, I'll have a look myself but probably a bit later this month. |
I added a test in 045bbf1, but I'm not sure if that's what you are looking for. I'm happy to write some more tests if it helps. |
On Nov 6, 2022, Daylight Savings Time switches just before the 2 AM hour in the America/Chicago timezone.
I can't get this library to give me the correct time stamp or time zone when iterating to the 1 AM hour just before the time change.
For example:
The output is:
This library produces the wrong time (it's 1 hour late).
Yet, PHP's DateTime::modify and DateTime::add show the correct time.
Why is this?
The text was updated successfully, but these errors were encountered: