Bug #63442 [Com]: DateTime::getTimestamp returns wrong value
| From: | mj1856 at hotmail dot com | Date: | Thu, 04 Sep 2014 18:47:28 +0000 |
| Subject: | Bug #63442 [Com]: DateTime::getTimestamp returns wrong value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187422@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63442&edit=1
ID: 63442
Comment by: mj1856 at hotmail dot com
Reported by: sea128 at post dot cz
Summary: DateTime::getTimestamp returns wrong value
Status: Open
Type: Bug
Package: Date/time related
Operating System: Windows 7 64 bit
PHP Version: 5.4.8
Block user comment: N
Private report: N
New Comment:
There's some other strangeness here also. Consider:
$tz = new DateTimeZone('Europe/Paris');
$dt = new DateTime('2014-10-26T02:30', $tz);
echo $dt->format(DateTime::ISO8601) . " (" . $dt->getTimeStamp() . ")\n";
$ts = $dt->getTimeStamp() - 3600;
$dt = new DateTime("@$ts", new DateTimeZone('UTC'));
$dt->setTimeZone($tz);
echo $dt->format(DateTime::ISO8601) . " (" . $dt->getTimeStamp() . ")\n";
OUTPUT:
2014-10-26T02:30:00+0100 (1414287000)
2014-10-26T02:30:00+0200 (1414287000)
So even though going through UTC fixed the offset shown in the formatting, it still adjusted the
timestamp. The second value should have the timestamp 141283400.
This is a really dangerous bug that has been sitting for too long. Please raise priority. Thanks.
Previous Comments:
------------------------------------------------------------------------
[2012-11-05 16:35:30] sea128 at post dot cz
Description:
------------
DateTime::getTimestamp() returns different value from DateTime::setTimestamp().
Problem is caused by time zone where is used daylight saving and time when timezone offset is
switched.
Test script:
---------------
$tz = new DateTimeZone('Europe/Prague');
$date = new DateTime('now',$tz);
$date->setTimestamp(1351386000);
echo $date->getTimestamp() . "\n";
$date->setTimestamp(1351386000-3600);
echo $date->getTimestamp() . "\n";
Expected result:
----------------
1351386000
1351382400
Actual result:
--------------
1351386000
1351386000
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63442&edit=1