Bug #66118 [Opn->Nab]: date_format prints incorrect GMT offset during time change hour
| From: | heiglandreas@php.net | Date: | Sun, 19 Mar 2017 11:15:06 +0000 |
| Subject: | Bug #66118 [Opn->Nab]: date_format prints incorrect GMT offset during time change hour | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207945@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66118&edit=1
ID: 66118
Updated by: heiglandreas@php.net
Reported by: david dot sheldon at carrierweb dot com
Summary: date_format prints incorrect GMT offset during time
change hour
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Linux, windows7
PHP Version: 5.5.6
Block user comment: N
Private report: N
New Comment:
Due to the way you created the datetime-object the calculations were wrong. As David Sheldon pointed
out when done in the intended way everything works out correctly.
Previous Comments:
------------------------------------------------------------------------
[2013-11-19 16:20:45] david dot sheldon at carrierweb dot com
It appears that this is caused by $dateTime->setTimestamp().
The following code works fine:
$dateTime = new DateTime("@$timeStamp");
$dateTime->setTimezone(new DateTimeZone("America/New_York"));
$dateFormat = $dateTime->format(DateTime::ISO8601);
------------------------------------------------------------------------
[2013-11-19 15:38:44] david dot sheldon at carrierweb dot com
Description:
------------
For the hour where the clock changes, date() reports the correct offset/timezone abbreviation, and
date_format() reports the incorrect offset, appearing to use the offset for an hour later.
Test script:
---------------
// http://3v4l.org/GVjMn
date_default_timezone_set("America/New_York");
$timeStamp = 1352008800;
$date= date(DateTime::ISO8601, $timeStamp);
$dateTime = new DateTime();
$dateTime->setTimestamp($timeStamp);
$dateFormat = date_format($dateTime, DateTime::ISO8601);
echo "Date: $date\nDateFormat: $dateFormat\n";
Expected result:
----------------
Both lines the same:
Date: 2012-11-04T01:00:00-0500
DateFormat: 2012-11-04T01:00:00-0500
Actual result:
--------------
Date: 2012-11-04T01:00:00-0500
DateFormat: 2012-11-04T01:00:00-0400
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66118&edit=1