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

 ID:                 53340
 Updated by:         [email protected]
 Reported by:        simon dot kohlmeyer at mayflower dot de
 Summary:            getTimestamp returns wrong values for DateTimes from
                     DatePeriods
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        5.3.3
 Block user comment: N
 Private report:     N

 New Comment:

Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


Previous Comments:
------------------------------------------------------------------------
[2010-11-18 10:47:58] simon dot kohlmeyer at mayflower dot de

Description:
------------
When using a DatePeriod, calling getTimestamp on the objects returns
wrong results, starting with the second Datetime.

This is probably connected with http://bugs.php.net/bug.php?id=52454 and
might have been fixed by it's solution.



I'm on gentoo 64bit testing using php-5.3.3. Also confirmed on debian
32bit using php5.3.2-1.

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



$start = new Datetime('2010-11-10 08:00:00 UTC');

$delta = new DateInterval('P1D');

$snd = new Datetime('2010-11-11 08:00:00 UTC');

$period = new DatePeriod($start, $delta, 3);



echo 'We should get:   ' . $snd->getTimestamp() . "\n";



$manual = clone $start;

$manual->add($delta);

echo 'Manually adding: ' . $manual->getTimestamp() . "\n";



foreach ($period as $p) {

        // work around getTimestamp modifying date
http://bugs.php.net/bug.php?id=52454

        $timestamp = $p->getTimestamp();

        echo 'From DatePeriod: ' . $timestamp . ', ';

        $tmp = new Datetime('@' . $timestamp);

        echo 'which is really: ' . $tmp->format('Y-m-d H:i:s') . ', ' .
$tmp->getTimezone()->getName() . "\n";

}



Expected result:
----------------
We should get:   1289462400

Manually adding: 1289462400

>From DatePeriod: 1289376000, which is really: 2010-11-10 08:00:00,
+00:00

>From DatePeriod: 1289462400, which is really: 2010-11-11 08:00:00,
+00:00

>From DatePeriod: 1289548800, which is really: 2010-11-12 08:00:00,
+00:00

>From DatePeriod: 1289635200, which is really: 2010-11-13 08:00:00,
+00:00



Actual result:
--------------
We should get:   1289462400

Manually adding: 1289462400

>From DatePeriod: 1289376000, which is really: 2010-11-10 08:00:00,
+00:00

>From DatePeriod: 1289548800, which is really: 2010-11-12 08:00:00,
+00:00

>From DatePeriod: 1289635200, which is really: 2010-11-13 08:00:00,
+00:00

>From DatePeriod: 1289721600, which is really: 2010-11-14 08:00:00,
+00:00


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



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

Reply via email to