From:             
Operating system: Linux
PHP version:      5.3.3
Package:          Date/time related
Bug Type:         Bug
Bug description:getTimestamp returns wrong values for DateTimes from DatePeriods

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 bug report at http://bugs.php.net/bug.php?id=53340&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53340&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53340&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53340&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53340&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53340&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53340&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53340&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53340&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53340&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53340&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53340&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53340&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53340&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53340&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53340&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53340&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53340&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53340&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53340&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53340&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53340&r=mysqlcfg

Reply via email to