Edit report at https://bugs.php.net/bug.php?id=81458&edit=1
ID: 81458
Comment by: kylekatarnls at gmail dot com
Reported by: kylekatarnls at gmail dot com
Summary: Regression in PHP 8.1: Incorrect difference after
timezone change
Status: Closed
Type: Bug
Package: Date/time related
PHP Version: 8.1Git-2021-09-18 (Git)
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
Hello derick,
FYI I now get this returning me days = 0 using master branch, while if I properly understood your
specs it should be 1:
```
date_default_timezone_set('UTC');
$a = new DateTime('2018-12-01 00:00');
$b = new DateTime('2018-12-02 00:01');
var_dump($a->diff($b));
```
So it sounds now there is a regression when both are in UTC.
Previous Comments:
------------------------------------------------------------------------
[2021-11-08 09:40:54] git@php.net
Automatic comment on behalf of derickr
Revision: https://github.com/php/php-src/commit/904933e9185664148ce5459f93726f54f572b6c3
Log: Fixed bug #81458: Regression: Incorrect difference after timezone change
------------------------------------------------------------------------
[2021-11-05 12:46:17] derick@php.net
FWIW, I started working on this, but it's a tad more work than I expected.
------------------------------------------------------------------------
[2021-11-02 21:00:33] kylekatarnls at gmail dot com
Exactly absolute(floor(($one->unixTime - $two->unixTime) / 86400)) is a good fallback to
calendar diff when ambiguous. Thank you.
------------------------------------------------------------------------
[2021-11-02 15:31:59] derick@php.net
Kyle, would you agree to the following definition of what "days" should mean in this
context? It was never really defined
(https://www.php.net/manual/en/class.dateinterval.php#dateinterval.props.days) in the docs:
- If the timezones are the same¹, use the values of year, month, and day to calculate
"days"
- If the timezones are not the same, use absolute(floor(($one->unixTime - $two->unixTime) /
86400))
¹ A timezone is the same if both $one and $two are:
- the same timezone type (1, 2, or 3) AND
- if zonetype 1 (utc offset) or 2 (abbr), the UTC offsets are the same
- if zonetype 3, the TZIDs (such as UTC / America/Toronto) are the same
In your example, the timezone in $first and $second is not the same, as $first is zonetype 3 and has
TZID "UTC", and $second is zonetype 3, but has the TZID "America/Toronto". If
would then calculate absolute(floor((1530504000 - 1530417600) / 86400)) === 1.
------------------------------------------------------------------------
[2021-10-21 16:58:52] kylekatarnls at gmail dot com
cmb@php.net > No, the difference between those 2 moments is 24 hours, not 20 hours.
No hours are added or subtracted when calling setTimezone, only the timezone change not the moment,
it's a meta data that should be used only to format the date, it has no impact on the
difference with an other moment.
Sorry but no, the current behavior is not correct. No way, 1 is correct (it's really 1 FULL DAY
diff), and 0 is wrong.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=81458
--
Edit this bug report at https://bugs.php.net/bug.php?id=81458&edit=1