]> granicus.if.org Git - php/commitdiff
Allow gettimeofday() return a float if optional argument is specified.
authorIlia Alshanetsky <iliaa@php.net>
Thu, 21 Oct 2004 21:20:52 +0000 (21:20 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 21 Oct 2004 21:20:52 +0000 (21:20 +0000)
NEWS
ext/standard/microtime.c

diff --git a/NEWS b/NEWS
index 698a6f548a7ab75721ed9b717afa316bbac427b8..aa09a21a39b148615d3e17d7736a7b16a64ea332 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2004, PHP 5.1.0
+- Allow gettimeofday() return a float if optional argument is specified. (Ilia)
 - Added sqlite_fetch_column_types() 3rd argument for arrays. (Ilia)
 - Added optional offset parameter to stream_get_contents() and 
   file_get_contents(). (Ilia)
index 3ff82550693a6d0ed1581af1ffa1e3e4b716aab1..3e4debe433142470d3b2855da033ace7c50f8c42 100644 (file)
@@ -88,12 +88,22 @@ PHP_FUNCTION(microtime)
 #ifdef HAVE_GETTIMEOFDAY
 PHP_FUNCTION(gettimeofday)
 {
+       zend_bool get_as_float = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) {
+               return;
+       }
+
        struct timeval tp;
        struct timezone tz;
        
        memset(&tp, 0, sizeof(tp));
        memset(&tz, 0, sizeof(tz));
        if(gettimeofday(&tp, &tz) == 0) {
+               if (get_as_float) {
+                       RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC));
+               }
+
                array_init(return_value);
                add_assoc_long(return_value, "sec", tp.tv_sec);
                add_assoc_long(return_value, "usec", tp.tv_usec);