Bug #76182 [Opn->Ver]: DateTime::diff does not respect timezone offset
| From: | cmb@php.net | Date: | Mon, 26 Jul 2021 22:01:17 +0000 |
| Subject: | Bug #76182 [Opn->Ver]: DateTime::diff does not respect timezone offset | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235381@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76182&edit=1
ID: 76182
Updated by: cmb@php.net
Reported by: zerkms at zerkms dot ru
Summary: DateTime::diff does not respect timezone offset
-Status: Open
+Status: Verified
Type: Bug
Package: Date/time related
Operating System: Linux/Any
PHP Version: 7.2.4
Block user comment: N
Private report: N
New Comment:
Yeah, that doesn't look right: <https://3v4l.org/veWsf>.
Previous Comments:
------------------------------------------------------------------------
[2018-04-03 23:58:17] zerkms at zerkms dot ru
Description:
------------
If you subtract timezones from the different sides of the standard/dst time boundary - the result is
wrong.
Test script:
---------------
<?php
$dt = new \DateTime('2018-04-01 03:10:00', new
\DateTimeZone('Pacific/Auckland'));
$dt2 = clone $dt;
$dt2->sub(new \DateInterval('PT2H'));
var_dump($dt > $dt2, $dt->format(\DateTime::RFC3339), $dt2->format(\DateTime::RFC3339),
$dt->diff($dt2)->format('%h'));
Expected result:
----------------
bool(true)
string(25) "2018-04-01T03:10:00+12:00"
string(25) "2018-04-01T02:10:00+13:00"
string(1) "2"
Actual result:
--------------
bool(true)
string(25) "2018-04-01T03:10:00+12:00"
string(25) "2018-04-01T02:10:00+13:00"
string(1) "1"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76182&edit=1