-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace std::time:SystemTime with web_time::SystemTime
Allows consistent usage of SystemTime between targets (including WASM)
- Loading branch information
1 parent
da8e406
commit b7109ff
Showing
3 changed files
with
4 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,8 @@ | ||
use crate::{Duration, Errors}; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
pub(crate) fn duration_since_unix_epoch() -> Result<Duration, Errors> { | ||
{ | ||
use crate::Unit; | ||
use wasm_bindgen_rs::prelude::*; | ||
js_sys::Reflect::get(&js_sys::global(), &JsValue::from_str("performance")) | ||
.map_err(|_| Errors::SystemTimeError) | ||
.map(|performance| { | ||
performance.unchecked_into::<web_sys::Performance>().now() * Unit::Second | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub(crate) fn duration_since_unix_epoch() -> Result<Duration, Errors> { | ||
std::time::SystemTime::now() | ||
.duration_since(std::time::SystemTime::UNIX_EPOCH) | ||
web_time::SystemTime::now() | ||
.duration_since(web_time::SystemTime::UNIX_EPOCH) | ||
.map_err(|_| Errors::SystemTimeError) | ||
.and_then(|d| d.try_into().map_err(|_| Errors::SystemTimeError)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters