Skip to content

Commit

Permalink
Work around sebcrozet/instant#49
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed May 11, 2023
1 parent 3abd1c1 commit e140cc6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/re_log_types/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ use time::OffsetDateTime;
pub struct Time(i64);

impl Time {
// NOTE: Even though `instant` should work on wasm, `elapsed` is broken.
// See: https://github.com/sebcrozet/instant/issues/49
// We would like to switch to `web-time`, but that's broken in a different way
// See issues in: https://github.com/rerun-io/rerun/pull/2093
//
// So we implement what elapsed is supposed to do ourselves.
#[inline]
pub fn now() -> Self {
/*
let nanos_since_epoch = instant::SystemTime::UNIX_EPOCH
.elapsed()
.expect("Expected system clock to be set to after 1970")
.as_nanos() as _;
*/
let nanos_since_epoch = instant::SystemTime::now()
.duration_since(instant::SystemTime::UNIX_EPOCH)
.expect("Expected system clock to be set to after 1970")
.as_nanos() as _;
Self(nanos_since_epoch)
}

Expand Down

0 comments on commit e140cc6

Please sign in to comment.