Atb.: date->diff error php 8.1
| From: | Jānis Elmeris | Date: | Wed, 08 Jun 2022 09:25:41 +0000 |
| Subject: | Atb.: date->diff error php 8.1 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-328007@lists.php.net to get a copy of this message | ||
Looks like a bug to me.
In 8.1, there were a bunch of bugs related to dates fixed
(https://www.php.net/ChangeLog-8.php#8.1.0), so the related code was changed quite a bit.
In this online example you can see that PHP 8.1 seems to calculate the difference 1 h less than
needed https://3v4l.org/GSA0u
It's like 8.1 is applying DST twice (EST now being -03:00 instead of -04:00). The same was with
another timezone I checked. And the problem was absent for a date outside of DST.
You should probably report the bug on https://github.com/php/php-src/issues
Janis
________________________________
No: John Belli <jbelli@rte-usa.com>
Nosūtīts: trešdiena, 2022. gada 8. jūnijs 01:44
Kam: php-general@lists.php.net <php-general@lists.php.net>
Tēma: date->diff error php 8.1
Trying to figure out why my sessions were expiring immediatly on php 8.1 but not 8.0, I found the
following:
code fragment:
$foo = new DateTime();
$bar = new DateTime($_SESSION['ts']);
var_dump($foo);
var_dump($bar);
$diff = $foo->diff($bar, true);
var_dump ($diff);
php 8.0:
object(DateTime)#2 (3) {
["date"]=>
string(26) "2022-06-07 18:33:01.543434"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Eastern"
}
object(DateTime)#3 (3) {
["date"]=>
string(26) "2022-06-07 18:32:58.651232"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "-04:00"
}
object(DateInterval)#4 (16) {
["y"]=>
int(0)
["m"]=>
int(0)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(2)
["f"]=>
float(0.89220200000000005)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(0)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
php 8.1:
object(DateTime)#2 (3) {
["date"]=>
string(26) "2022-06-07 18:31:30.428703"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Eastern"
}
object(DateTime)#3 (3) {
["date"]=>
string(26) "2022-06-07 18:31:27.274847"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "-04:00"
}
object(DateInterval)#4 (16) {
["y"]=>
int(-1)
["m"]=>
int(11)
["d"]=>
int(29)
["h"]=>
int(23)
["i"]=>
int(0)
["s"]=>
int(3)
["f"]=>
float(0.15385599999999999)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(0)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
What is happening here? Am I doing something wrong that just happened to accidentally work from
5.6-8.0, or did I find a bug?
JAB