Hi,
I'm writing a function where I want to calculate the difference between when current message was received and a previous message. The previous date timestamp is stored in a context variable.
When I do:
var previous = context.get('prev') || 0;
var now = new Date().getTime();
var since = now - previous;
The since
is always equal to now
. It is not performing the substration --> huh??
I have tried with Date's before, which should also just work, but it also did not.
Also tried Math.abs(now - previous)
but it gives the same result.
If, on the same spot, I do a simple var since = 10 - 9
then the result is 1
.
I have checked the types. Both now
and previous
are of type number
.
Is this causing an issue because the timestamp value is too large? But why would that be an issue in NodeJS and not in a browser? I use Chrome Console for trying stuff out and there new Date() - new Date()
just works as expected.
Is this a known problem with NodeJS/NodeRed?
How can I calculate the time difference?
Cheers