-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot represent instants before the program start #45
Comments
Is wasn't able to reproduce this and was also not able to find any information on it, could you elaborate how this can happen? |
@daxpedda This line panics with 'overflow when subtracting durations' (if your program has not being running for a 100s):
I added a test to my PR to test this. |
Isn't this as intended? So the behavior seems correct to me. |
The |
Well yes, but that is not behavior that you should rely on. The starting point of the underlying clock is not defined by Rust. The reason this currently works on Linux is because
So the starting time is since the UNIX epoch. So unless your computer boots with a time set to 1970 it will always be much bigger then 0. On Windows for example, That said, looking at your PR, it seems to me that probably the better way to do this is to add In any case, from a general-purpose library standpoint, an additional calculation is additional overhead for a non-conforming use-case, imho. |
Yes, you are right, on Windows I can get my example to panic with a value as little as I could argue that they should be able to handle negative values (because both Windows and POSIX appear to return signed values), but some platforms may not, and that is also beyond this issue. So fell free to close this issue. |
Apologies I gave the wrong impression here, I'm not a maintainer of this repo. However, shameless plug, I was interested in this issue because I recently released |
Previously, I used a Instant keeping the theorical time that the gameboy was turned on to calculate the ammount of clocks in order to emulate the gameboy in real time. Every time I fast-forward the emulate I recomputed the start Instant to `Instant::now() - clock_to_duration(gb.clock_count)`, getting a value of Instant in the past. But it is not guarranteed that Instant is able to represent times in the past and may panic on underflow (See sebcrozet/instant#45). This is fixed by keeping `last_start_time: Instant` as the time that the gameboy started running at the clock count `last_start_clock`.
In one of my projects, I have the necessity of representing an arbitrary instant in time, which include instants before the program start.
The current implementation relies on creating a
Duration
fromperforme.now()
. Becauseperforme.now()
return the time since the creation of the page/web worker, and becauseDuration
cannot represent negative values, the Wasm version ofInstant
can only represent a small range of past instants.The text was updated successfully, but these errors were encountered: