Bug #81458 [Csd]: Regression in PHP 8.1: Incorrect difference after timezone change
| From: | derick@php.net | Date: | Thu, 18 Nov 2021 14:04:28 +0000 |
| Subject: | Bug #81458 [Csd]: Regression in PHP 8.1: Incorrect difference after timezone change | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237849@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81458&edit=1
ID: 81458
Updated by: derick@php.net
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:
Should be fixed now Kyle, it had nothing to do with a regression, but with a missing "="
-> https://github.com/derickr/timelib/commit/b8885ede02dea903a42b82d1fcb99e708b76e384
Previous Comments:
------------------------------------------------------------------------
[2021-11-17 10:36:08] kylekatarnls at gmail dot com
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.
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
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