-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Since PHP 8.1.7 strtotime translates a date-time with DST/non-DST hour differently based on default timezone #9165
Comments
Confirmed: https://3v4l.org/NEBOD. I'm not sure, though, whether the new behavior is intended, since the documentation states:
Since |
As per my test this issue is only with the date-time that has duplicate hour ie. hour in dst and non-dst. If
output
|
I'm pretty sure this change has been introduced through derickr/timelib#121. These calculations are very magic, and changing them again will likely cause other issues. Unless https://wiki.php.net/rfc/datetime_and_daylight_saving_time is implemented, both answers are "not wrong", although a little confusing. I do plan to tackle this issue, but not likely for PHP 8.2. |
Let me give more example. Consider the following code
Before Php 8.1.7 both resulted in the same timestamp
However since PHP 8.1.7 they are different
If two methods are translating one date-time to two different timestamp, I don't think it is merely confusing, it is wrong. |
As someone who works a lot with hourly datasets, I am sympathetic to the complexity of these issues. But, also I was very happy with the change made in 8.1.7, where a strtotime() on a string containing a duplicate hour will now return the timestamp of the first instance. This is in my opinion much better than the previous behaviour of returning the second one, because now a value can go back and forth using strtotime() and date() and not change. It makes many workflows a lot safer because we do not have to write special code for handling the case of our timestamp changing on us during manipulations. Before:
Now, the downside is due to the current issue, we still cannot rely on this behaviour.. Even though I agree that officially it is "not wrong" to give either value, the recently introduced behaviour is in practical use a lot better. So it is really inconvenient that there still is this unexpected variance. And of course, because the whole point of passing timezones is that the default zone should not matter, I think it is a real bug that this difference exists, even if one accepts that the two values are both "not wrong". |
As discussed in dragonmantank#133, the PHP 8.1's date extension daylight saving APIs have been suffering with instabilities. Let's skip the affected tests until php/php-src#9165 is resolved. Signed-off-by: Athos Ribeiro <[email protected]>
As discussed in #133, the PHP 8.1's date extension daylight saving APIs have been suffering with instabilities. Let's skip the affected tests until php/php-src#9165 is resolved. Signed-off-by: Athos Ribeiro <[email protected]> Signed-off-by: Athos Ribeiro <[email protected]>
PR at #9538 — for PHP 8.1.11. |
- Fixed #124: Can't parse INT_MIN - Added a new API, timelib_get_time_zone_offset_info, which reduces allocation speeding up algorithms (Alberto Massari) - Accelerate the do_range_limit_days algorythm by advancing multiple months in a single call (Alberto Massari) Including fixes from 2021.17: - Fixed 'const' and other compiler warnings - Use new 'PACKRAT' format to prevent old timestamps from becoming incorrect - New 2022b data file - Fixed PHP GH-9165: strtotime translates a date-time with DST/non-DST hour differently
`<?php echo "\n- 5hours\n"; `PHP7.4 with strtotime bug??
`PHP 8.2
|
Should we all just stop calling strtotime() ? |
@tomandersen
|
Thanks, I should have thought about that, some new string behaviour. I swear it wasn’t my code! |
Description
For the timezone
Europe/London
on date 2018-10-28 two hour 01:00:00 exist - one DST and another non-DST. Following code shows that it gives two different timestamp based on the set default timezone. Which should not be the case as the string date-time provided tostrtotime
already contains the timezone.Prior to PHP 8.1.7
strtotime
was translating it into1540688400
regardless set timezone.Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.1.7
Operating System
No response
The text was updated successfully, but these errors were encountered: