Bug #74914 [NEW]: DateInterval subtraction across daylight savings change is incorrect
| From: | ricjea at sbcglobal dot net | Date: | Wed, 12 Jul 2017 23:55:39 +0000 |
| Subject: | Bug #74914 [NEW]: DateInterval subtraction across daylight savings change is incorrect | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-210034@lists.php.net to get a copy of this message | ||
From: ricjea at sbcglobal dot net
Operating system: Windows Server 2012
PHP version: 5.6.31
Package: Date/time related
Bug Type: Bug
Bug description:DateInterval subtraction across daylight savings change is incorrect
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
)
)
--
Edit bug report at https://bugs.php.net/bug.php?id=74914&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74914&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74914&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74914&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74914&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74914&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74914&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74914&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74914&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74914&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74914&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74914&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74914&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74914&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74914&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74914&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74914&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74914&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74914&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74914&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74914&r=mysqlcfg