From 4b947b0525750993dbd54ac006daff128f96804b Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 21 Oct 2004 21:20:52 +0000 Subject: [PATCH] Allow gettimeofday() return a float if optional argument is specified. --- NEWS | 1 + ext/standard/microtime.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/NEWS b/NEWS index 698a6f548a..aa09a21a39 100644 --- 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) diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c index 3ff8255069..3e4debe433 100644 --- a/ext/standard/microtime.c +++ b/ext/standard/microtime.c @@ -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); -- 2.50.1