Skip to content

Commit 4b947b0

Browse files
author
Ilia Alshanetsky
committed
Allow gettimeofday() return a float if optional argument is specified.
1 parent 54aa881 commit 4b947b0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2004, PHP 5.1.0
4+
- Allow gettimeofday() return a float if optional argument is specified. (Ilia)
45
- Added sqlite_fetch_column_types() 3rd argument for arrays. (Ilia)
56
- Added optional offset parameter to stream_get_contents() and
67
file_get_contents(). (Ilia)

ext/standard/microtime.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,22 @@ PHP_FUNCTION(microtime)
8888
#ifdef HAVE_GETTIMEOFDAY
8989
PHP_FUNCTION(gettimeofday)
9090
{
91+
zend_bool get_as_float = 0;
92+
93+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) {
94+
return;
95+
}
96+
9197
struct timeval tp;
9298
struct timezone tz;
9399

94100
memset(&tp, 0, sizeof(tp));
95101
memset(&tz, 0, sizeof(tz));
96102
if(gettimeofday(&tp, &tz) == 0) {
103+
if (get_as_float) {
104+
RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC));
105+
}
106+
97107
array_init(return_value);
98108
add_assoc_long(return_value, "sec", tp.tv_sec);
99109
add_assoc_long(return_value, "usec", tp.tv_usec);

0 commit comments

Comments
 (0)