Edit report at https://bugs.php.net/bug.php?id=63953&edit=1

 ID:                 63953
 Comment by:         kaido at tradenet dot ee
 Reported by:        gianluca dot pinna at allbus dot com
 Summary:            DateTime::diff produces a wrong DateInterval on DST
                     change
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux 64
 PHP Version:        5.3.20
 Block user comment: N
 Private report:     N

 New Comment:

test script:

$d1 = new DateTime('2012-05-31');
$d2 = new DateTime('2013-03-02');

$diff1 = $d1->diff ($d2);

$diff2 = $d2->diff ($d1);

echo "case 1: ".$diff1->m." months, case 2: ".$diff2->m." months";


expected result:

both $diff1->m and $diff2->m are 9


Previous Comments:
------------------------------------------------------------------------
[2013-01-09 16:45:28] gianluca dot pinna at allbus dot com

Description:
------------
I have two dates, the second date is after a DST change.

I tried to get a diff between the two dates. Computing the difference between 
the 
timestamps I get the correct result (33 hours).

Using DateTime->diff() I get 34 hours. Is this expected?

Test script:
---------------
<?php

$originDate = new DateTime('2013-03-30 00:00:00', new 
DateTimeZone('Europe/Rome'));
$destinationDate = new DateTime('2013-03-31 10:00:00', new 
DateTimeZone('Europe/Rome'));


$diff = $destinationDate->getTimestamp() - $originDate->getTimestamp();
$dateinterval = $originDate->diff($destinationDate);

var_dump($diff/3600);
var_dump($dateinterval->d*24 + $dateinterval->h);

// int(33)
// int(34)

Expected result:
----------------
I would expect to always get 33 hours.



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63953&edit=1

Reply via email to