From:             RQuadling at GMail dot com
Operating system: Irrelevant
PHP version:      5.3.1RC3
PHP Bug Type:     Feature/Change Request
Bug description:  Provide single value difference in DateInterval->diff()

Description:
------------
The output of DateInterval->diff() currently shows the breakdown of 
the 
difference (y, m, d, h, i, s, days, invert).

Which is fine. But I'd like to be able to have the number of seconds 
difference.

The following patch adds a new entry to the output: diff.

It is a straight calculation of the seconds based upon days, h, i and 
s, 
and takes into consideration invert.

The patch below is the same for branch/5_3 and trunk.


I think this patch and the DateInterval object comparison patch 
reported in Bug#49914 by aharvey would be good additions.

Regards,

Richard.

Reproduce code:
---------------
Index: php_date.c
===================================================================
--- php_date.c  (revision 290198)
+++ php_date.c  (working copy)
@@ -2245,6 +2245,16 @@
        PHP_DATE_INTERVAL_ADD_PROPERTY("s", s);
        PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
        PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+       
+       MAKE_STD_ZVAL(zv);
+       ZVAL_LONG(zv, ((((((
+               intervalobj->diff->days * 24) + 
+               intervalobj->diff->h) * 60) + 
+               intervalobj->diff->i) * 60) + 
+               intervalobj->diff->s) * (
+               intervalobj->diff->invert ? -1 : 1)
+       );
+       zend_hash_update(props, "diff", 5, &zv, sizeof(zval), NULL);
 
        return props;
 }



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

Reply via email to