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;
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.
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
I have checked the types. Both
previous are of type
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?