Edit report at https://bugs.php.net/bug.php?id=61955&edit=1
ID: 61955
Comment by: zhanglijiu at gmail dot com
Reported by: php at arjanonline dot net
Summary: Adding DateInterval to DateTime adds 1 additional
hour
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux / Mac
PHP Version: 5.3.12
Block user comment: N
Private report: N
New Comment:
My result is object(DateTime)#2 (3) { ["date"]=> string(19) "1970-01-01
00:00:05"
["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" }
My system is MAC 10.6.8 php 5.3.1
Previous Comments:
------------------------------------------------------------------------
[2012-05-05 20:45:27] php at arjanonline dot net
Description:
------------
When I create a DateTime object from a (any) timestamp and then add a
DateInterval object to the DateTime object, the time in the DateInterval object
is added and one additional hour is also added.
I have not noticed this behavior in versions up to and including 5.3.8, only in
newer 5.3 versions. (I did not test in 5.4.)
Also the behavior is related to the default time zone, even though the created
DateTime object is in UTC. I have tested several timezones and it appears that
all Europe/* and North American America/* timezones are affected. The
Australian timezones seem to be unaffected.
Information from phpinfo():
date
- date/time support => enabled
- "Olson" Timezone Database Version => 2012.3
- Timezone Database => internal
Test script:
---------------
date_default_timezone_set('Europe/Amsterdam');
$d1 = new DateTime('@0');
$d2 = clone($d1);
$d2->add(new DateInterval('PT5S'));
var_dump($d2);
Expected result:
----------------
object(DateTime)[2]
public 'date' => string '1970-01-01 00:00:05' (length=19)
public 'timezone_type' => int 1
public 'timezone' => string '+00:00' (length=6)
Actual result:
--------------
object(DateTime)[2]
public 'date' => string '1970-01-01 01:00:05' (length=19)
public 'timezone_type' => int 1
public 'timezone' => string '+00:00' (length=6)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61955&edit=1