-
Notifications
You must be signed in to change notification settings - Fork 7.8k
DateTime::diff doesnt evaluate daylight saving time correctly #9382
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
Comments
Indeed, that looks wrong to me. |
@cmb69 @derickr forgot to add a note in the manual for diff, if they are with timezone type int 3 the result is effective otherwise if different timezones will be converted to UTC and calculate the difference. if you need I will send you when diff has been modified. yes it's a bug for me too Valid period transitions: <?php
date_default_timezone_set('Europe/Berlin');
$origin = new DateTime('2022-03-27 02:00:00', new DateTimeZone('Europe/Berlin'));
$target = new DateTime('2022-03-27 02:00:00 +0200');
$origin->setTimeZone(new DateTimeZone('Europe/Berlin'));
$origin = new DateTime($origin->format('Y-m-d H:i:s'), new DateTimeZone('Europe/Berlin'));
$simil_utc = $target->format('Y-m-d H:i:s');
$target = new DateTime($simil_utc, new DateTimeZone('Europe/Berlin'));
$target->setTimeZone(new DateTimeZone('Europe/Berlin'));
$target = new DateTime($target->format('Y-m-d H:i:s'), new DateTimeZone('Europe/Berlin'));
$interval = $origin->diff($target);
echo $interval->format('%R%a days %h hours') . "\n";
var_dump($origin, $target);
?> DateTime::Diff php 8.10 > if object same type offset timezone $origin and $target is local time object. Means for DST +0200: Europe/Berlin = Europe/Berlin or Europe/Berlin = +0200 or Europe/Berlin = CEST (ex. Localtime object 2022-03-27 02:00:00 - 2022-03-27 02:00:00 = 0 or 2022-03-27 03:00:00 - 2022-03-27 03:00:00 = 0 or Europe/Berlin = +0200 2022-03-27 03:00:00 - 2022-03-27 02:00:00 = 0), for Europe/Berlin: ST (+0100) and DST (+0200) 2022-03-27 01:00:00 - 2022-03-27 03:00:00 = 1 or 2022-03-27 01:00:00 - 2022-03-27 02:00:00 = 1 |
This seems to be already fixed in the 8.1.10RC1. I can successfully recreate this with 8.1.9, but not with 8.1.10RC1. I believe it is a duplicate of #8730. |
🥳 Thanks! |
Description
The following code:
Resulted in this output:
But I expected this output instead:
According to https://3v4l.org/eOUP5 this bug exists since PHP 8.1.0
PHP Version
PHP 8.1.9
Operating System
Fedora 36
The text was updated successfully, but these errors were encountered: