instant icon indicating copy to clipboard operation
instant copied to clipboard

`Instant::elapsed` panics if time goes backwards, when `inaccurate` feature is enabled

Open richvdh opened this issue 2 years ago • 0 comments

STR:

  • Create an Instant: let now = Instant::now();
  • Later: check how long has passed now.elapsed();

If system time goes backwards in the intervening period, elapsed will panic:

panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/instant-0.1.12/src/wasm.rs:24:9:
`earlier` cannot be later than `self`.

This seems to be largely because Instant is based on local system time rather than a proper monotonic clock, violating the specification of std::time::Instant. I think if we're going to do that, we need to let Instant::duration_since saturate rather than panic.

richvdh avatar Dec 13 '23 11:12 richvdh