summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2003-12-17 22:03:33 +0000
committerAndrey Hristov <andrey@php.net>2003-12-17 22:03:33 +0000
commita0e930cff4cf6c1cb05073783d1272a3ab34ad7a (patch)
treef9190d8a9fa40f50bf2d70340f01e6bc2749099c /ext/standard
parent3573c135526ac284afaf78aa0dfeb247a2fe4b84 (diff)
downloadphp-git-a0e930cff4cf6c1cb05073783d1272a3ab34ad7a.tar.gz
Added optional parameter to microtime so now it can return float if it
the user wants. This prevents from getting string representation exploding it and then creating a float.
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/microtime.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c
index fdd8578829..45e1331536 100644
--- a/ext/standard/microtime.c
+++ b/ext/standard/microtime.c
@@ -51,29 +51,40 @@
#define MICRO_IN_SEC 1000000.00
#define SEC_IN_MIN 60
-/* {{{ proto string microtime(void)
- Returns a string containing the current time in seconds and microseconds */
#ifdef HAVE_GETTIMEOFDAY
+/* {{{ proto string microtime([bool get_as_float])
+ Returns either a string or a float containing the current time in seconds and microseconds */
PHP_FUNCTION(microtime)
{
struct timeval tp;
long sec = 0L;
double msec = 0.0;
- char ret[100];
-
+ zend_bool get_as_float = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) {
+ return;
+ }
+
if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) {
msec = (double) (tp.tv_usec / MICRO_IN_SEC);
sec = tp.tv_sec;
if (msec >= 1.0) msec -= (long) msec;
- snprintf(ret, 100, "%.8f %ld", msec, sec);
- RETVAL_STRING(ret,1);
+ if (get_as_float == 0) {
+ char ret[100];
+
+ snprintf(ret, 100, "%.8f %ld", msec, sec);
+ RETURN_STRING(ret,1);
+ } else {
+ RETURN_DOUBLE((double) (sec + msec));
+ }
} else {
RETURN_FALSE;
}
+
}
-#endif
/* }}} */
+#endif
/* {{{ proto array gettimeofday(void)
Returns the current time as array */