Skip to content
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

Work around https://github.com/sebcrozet/instant/issues/49 #2094

Merged
merged 2 commits into from
May 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is a comment about the implementation and so should be within the function, not outside it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh; good call. I had started with two separate implementations so this made more sense, but will move into the function.

#[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