process: fix calculation in process.uptime()

In https://github.com/nodejs/node/pull/26016 the result returned
by process.uptime() was mistakenly set to be based in the wrong
unit. This patch fixes the calculation and makes sure the returned
value is in seconds.

Refs: https://github.com/nodejs/node/pull/26016

PR-URL: https://github.com/nodejs/node/pull/26206
Fixes: https://github.com/nodejs/node/issues/26205
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
Joyee Cheung authored and Rod Vagg committed 2019-02-28 23:35:35 +11:00
1 parent 6b7d8369e3
commit fde40116c4
1 file changed
+2 -4
+2 -4
View File
@@ -57,10 +57,8 @@ Mutex umask_mutex;
// Microseconds in a second, as a float, used in CPUUsage() below
#define MICROS_PER_SEC 1e6
// used in Hrtime() below
// used in Hrtime() and Uptime() below
#define NANOS_PER_SEC 1000000000
// Used in Uptime()
#define NANOS_PER_MICROS 1e3
#ifdef _WIN32
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
@@ -246,7 +244,7 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
uv_update_time(env->event_loop());
double uptime =
static_cast<double>(uv_hrtime() - per_process::node_start_time);
Local<Number> result = Number::New(env->isolate(), uptime / NANOS_PER_MICROS);
Local<Number> result = Number::New(env->isolate(), uptime / NANOS_PER_SEC);
args.GetReturnValue().Set(result);
}