I would expect Date.now() to return the current time in milliseconds but it is effectively calculating the value in seconds and then multiplying it by 1000, which means we're actually losing the millisecond precision. The same is happening with performance.now().
Expected value: 1650844899292
Returned value: 1650844899000
I originally thought the problem was on Duktape falling back to duk_bi_date_get_now_time which only returns time in seconds (and multiplies it by 1000) but using duk_bi_date_get_now_gettimeofday produces the same result because gettimeofday apparently returns 0 on tv_usec.
I would expect
Date.now()
to return the current time in milliseconds but it is effectively calculating the value in seconds and then multiplying it by 1000, which means we're actually losing the millisecond precision. The same is happening withperformance.now()
.I originally thought the problem was on Duktape falling back to
duk_bi_date_get_now_time
which only returns time in seconds (and multiplies it by 1000) but usingduk_bi_date_get_now_gettimeofday
produces the same result becausegettimeofday
apparently returns 0 ontv_usec
.