php.net |  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
Votes:3
Avg. Score:3.0 ± 1.6
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zerkms at zerkms dot ru
New email:
PHP Version: OS:

 

 [2018-04-03 23:58 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-26 22:01 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-07-26 22:01 UTC] cmb@php.net
Yeah, that doesn't look right: <https://3v4l.org/veWsf>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC