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

Epoch::now() is returning faulty time (wasm/web-sys) #278

Closed
karpfediem opened this issue Jan 15, 2024 · 0 comments · Fixed by #279
Closed

Epoch::now() is returning faulty time (wasm/web-sys) #278

karpfediem opened this issue Jan 15, 2024 · 0 comments · Fixed by #279

Comments

@karpfediem
Copy link
Contributor

#262 Adds wasm support. But the duration obtained through web-sys is currently wrong.
It uses Performance.now (https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) which returns the milliseconds since the page/worker has loaded.

See the current implementation in https://github.com/nyx-space/hifitime/pull/262/files#diff-2effce6c18e7a6bda6cd5148cecf1af4951be035c6c03b6665e0275539c7f5eeR8-R12

  • we always start at time since Unix Epoch = 0 (time since page navigation/worker load)
  • we multiply milliseconds * Unit::Second which results in 1000 seconds being added every second
  • we lose resolution (reduced to seconds)

Instead we should use something like https://lib.rs/crates/web-time, or adopt it's implementation for this use-case

This implementation uses Performance.now() for Instant and Date.now() for SystemTime to offer a drop-in replacement that works in browsers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant