|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76182 DateTime::diff does not respect timezone offset
Submitted: 2018-04-03 23:58 UTC Modified: 2021-07-26 22:01 UTC
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: zerkms at zerkms dot ru Assigned:
Status: Verified Package: Date/time related
PHP Version: 7.2.4 OS: Linux/Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
11 + 26 = ?
Subscribe to this entry?

 [2018-04-03 23:58 UTC] zerkms at zerkms dot ru
If you subtract timezones from the different sides of the standard/dst time boundary - the result is wrong.

Test script:

$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:
string(25) "2018-04-01T03:10:00+12:00"
string(25) "2018-04-01T02:10:00+13:00"
string(1) "2"

Actual result:
string(25) "2018-04-01T03:10:00+12:00"
string(25) "2018-04-01T02:10:00+13:00"
string(1) "1"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-26 22:01 UTC]
-Status: Open +Status: Verified
 [2021-07-26 22:01 UTC]
Yeah, that doesn't look right: <>.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Jun 08 12:03:38 2023 UTC