php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74914 DateInterval subtraction across daylight savings change is incorrect
Submitted: 2017-07-12 23:55 UTC Modified: 2017-07-13 05:30 UTC
From: ricjea at sbcglobal dot net Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 5.6.31 OS: Windows Server 2012
Private report: No CVE-ID: None
 [2017-07-12 23:55 UTC] ricjea at sbcglobal dot net
Description:
------------
Found in PHP 5.6.31, still exists in version 7 as per testing with https://3v4l.org/35D4t

If you subtract a DateInterval that ends during the spring daylight savings time transition, the wrong DateTime and DateTime->getTimestamp() are returned. See example. If the DateInterval spans the full transition, then it is ok.




Test script:
---------------
$a = new \DateTime('2016-03-13 3:00:00', new DateTimeZone('America/Los_Angeles'));
echo "Original Timestamp: ".$a->getTimeStamp()."\n";
$b = clone $a;
$b->sub(new \DateInterval('PT1S'));
echo "Subtract 1 second Timestamp: ".$b->getTimeStamp()."\n";
print_r([$a,$b]);


Expected result:
----------------
Original Timestamp: 1457863200
Subtract 1 second Timestamp: 1457863199
Array
(
    [0] => DateTime Object
        (
            [date] => 2016-03-13 03:00:00.000000
            [timezone_type] => 3
            [timezone] => America/Los_Angeles
        )

    [1] => DateTime Object
        (
            [date] => 2016-03-13 01:59:59.000000
            [timezone_type] => 3
            [timezone] => America/Los_Angeles
        )

)

Actual result:
--------------
Original Timestamp: 1457863200
Subtract 1 second Timestamp: 1457866799
Array
(
    [0] => DateTime Object
        (
            [date] => 2016-03-13 03:00:00.000000
            [timezone_type] => 3
            [timezone] => America/Los_Angeles
        )

    [1] => DateTime Object
        (
            [date] => 2016-03-13 03:59:59.000000
            [timezone_type] => 3
            [timezone] => America/Los_Angeles
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-13 05:30 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2017-07-13 05:30 UTC] requinix@php.net
Duplicate of at least two other bugs I remember seeing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 02:01:30 2024 UTC