-
-
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.
Merge pull request #279 from karpfediem/hotfix/replace_system_time_we…
…b_time Draft: replace std::time:SystemTime with web_time::SystemTime
- Loading branch information
Showing
3 changed files
with
5 additions
and
18 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