From:             jennifer dot kimball at nrc dot ca
Operating system: Solaris 10
PHP version:      5.3.0
PHP Bug Type:     Date/time related
Bug description:  indeterminant DateInterval does not subtract correctly

Description:
------------
The logical behaviour of a DateInterval created with the "next" keyword,
when subtracted from a DateTime, should be to use "last" instead of "next"
in the calculation (and vice versa).

Instead, it appears that DateIntervals created with "next" or "last"
keywords cannot be subtracted from DateTimes with any accuracy. A DateTime
results from the operation but has an unexpected value.

Reproduce code:
---------------
//positive DateInterval
$da1=date_create();
$ds1=date_create();
$i=DateInterval::createFromDateString('third Tuesday of next month');
echo $da1->format('Y-m-d');
echo date_add($da1,$i)->format('Y-m-d');//works
echo date_sub($ds1,$i)->format('Y-m-d');//fails with weird date

//negative DateInterval
$da2=date_create();
$ds2=date_create();
$i2=DateInterval::createFromDateString('third Tuesday of last month');
echo $da2->format('Y-m-d');
echo date_add($da2,$i2)->format('Y-m-d');//works
echo date_sub($ds2,$i2)->format('Y-m-d');//fails with weird date

Expected result:
----------------
2009-11-02 //today
2009-12-15 //third Tuesday of December
2009-10-20 //third Tuesday of October

2009-11-02 //today
2009-10-20 //third Tuesday of October
2009-12-15 //third Tuesday of December

Actual result:
--------------
2009-11-02 //today
2009-12-15 //third Tuesday of December
2009-09-18 //third Friday of September

2009-11-02 //today
2009-10-20 //third Tuesday of October
2009-11-18 //third Wednesday of November

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

Reply via email to