Replies: 2 comments 8 replies
-
This one is a bit complicated/subtle. Thanks for bringing it up. Let's try to sort it out.
But.... that does mean that your example does not return garbage on roll-over. When
If we take the |
Beta Was this translation helpful? Give feedback.
-
Here's a quick implementation to try. I named the function It is declared in static difference(start, end) @ "xs_time_difference"; The ESP8266/ESP32 in time/esp/time.c impelemtation is: void xs_time_difference(xsMachine *the)
{
uint32_t start, end;
start = (uint32_t)xsmcToInteger(xsArg(0));
if (xsmcArgc > 1)
end = (uint32_t)xsmcToInteger(xsArg(1));
else
end = modMilliseconds();
xsmcSetInteger(xsResult, end - start);
} On macOS in time/mac/modTime.c: void xs_time_difference(xsMachine *the)
{
xsNumberValue start, end;
start = xsToNumber(xsArg(0));
if (xsToNumber(xsArgc) > 1)
end = xsToNumber(xsArg(1));
else {
c_timeval tv;
c_gettimeofday(&tv, NULL);
end = ((double)(tv.tv_sec) * 1000.0) + ((double)(tv.tv_usec / 1000));
}
xsResult = xsNumber(end - start);
} Linux should be able to use the Mac implementation. Note that If this seems like a good direction, I'll take care of the other platforms (Windows, wasm, Pico, etc). It would be good to get your evaluation and testing on this before that though. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Do I see correctly that Time.ticks is internally an unsigned 32 bit counter and will thus roll over after 49 days? I routinely write stuff like
and that will produce garbage when crossing a roll-over.
Thoughts?
Would there be appetite for a
Time.diff(t_end, t_start)
function that does a 32-bit unsigned subtraction, i.e. deals with the roll-over properly? (Or Math.isub ?)Beta Was this translation helpful? Give feedback.
All reactions