From:             
Operating system: Linux
PHP version:      5.3.6
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime Object does not always update using DateTime::add 
method

Description:
------------
The DateTime class does not seem to update the object properly,
specifically when 

the 'time' specified in the constructor of the object is relative time
format 

(such as `first day of this month`). The test case is reproducible on PHP
5.3.6 

as well as PHP 5.3.2 using the test script I've included below. A
DateTime::diff 

after using a DateTime::add method on the object results in 0 for all
periods 

(when the period specified with DateInterval is in Days). This clearly is
not the 

expected behavior as using PT24H will increase the object date by one day,
but 

not result in objects date being updated, while P1D (or P1W - which
translates to 

days) will have no effect at all.

Test script:
---------------
        $timezone = new DateTimeZone(date_default_timezone_get());

        $times['relative1'] = new DateTime('first day of this month', 
$timezone);

        $times['relative2'] = new DateTime('-1 week', $timezone);

        $times['fixed'] = new DateTime('4/1/2011 12:00:00 AM', $timezone);

        $intervals['PT24H'] = new DateInterval('PT24H');

        $intervals['P1D'] = new DateInterval('P1D');

        $intervals['P1W'] = new DateInterval('P1W');

        $intervals['P1M'] = new DateInterval('P1M');

        $intervals['P1Y'] = new DateInterval('P1Y');

        echo "<pre>";

        foreach ($times as $type => $time) {

                foreach ($intervals as $period => $interval) {

                        $str = "From " . $time->format('m/d/Y H:i:s') . " To ";

                        $last_time = new DateTime($time->format('m/d/Y H:i:s'));
$time->add($interval);

                        $str .= $time->format('m/d/Y h:i:s') . " - PERIOD: 
$period";

                        echo "<b>Using <i>$type</i> $str</b>\r\n";

                        echo $time->diff($last_time)->format('%y years, %m 
months, %d days, %h
hours, %i minutes, %s seconds.') . '<br />';

                }

        }

        echo "</pre>";

Expected result:
----------------
Specify a DateTime object using relative time format of 'first day of this
month'



DateTime object updates by 1 day when using DateTime::add() with a 

DateInterval('P1D') on that object.

Actual result:
--------------
DateTime object does not update even though the DateInterval is valid and
works 

on other DateTime objects of different, or non-relative, time.

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

Reply via email to