-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
66 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
16 | ||
17 | ||
1G | ||
1M | ||
1ns | ||
APIs | ||
Atomics | ||
Changelog | ||
CHANGELOG | ||
|
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Platform-specific extensions to `web-time` for the Web platform. | ||
|
||
#![allow(clippy::absolute_paths)] | ||
|
||
use std::time::SystemTime as StdSystemTime; | ||
|
||
use crate::SystemTime; | ||
|
||
/// Web-specific extension to [`web_time::SystemTime`](crate::SystemTime). | ||
pub trait SystemTimeExt { | ||
/// Convert [`web_time::SystemTime`](crate::SystemTime) to | ||
/// [`std::time::SystemTime`]. | ||
/// | ||
/// # Note | ||
/// | ||
/// This might give a misleading impression of compatibility! | ||
/// | ||
/// Considering this functionality will probably be used to interact with | ||
/// incompatible APIs of other dependencies, care should be taken that the | ||
/// dependency in question doesn't call [`std::time::SystemTime::now()`] | ||
/// internally, which would panic. | ||
fn to_std(self) -> std::time::SystemTime; | ||
|
||
/// Convert [`std::time::SystemTime`] to | ||
/// [`web_time::SystemTime`](crate::SystemTime). | ||
/// | ||
/// # Note | ||
/// | ||
/// This might give a misleading impression of compatibility! | ||
/// | ||
/// Considering this functionality will probably be used to interact with | ||
/// incompatible APIs of other dependencies, care should be taken that the | ||
/// dependency in question doesn't call [`std::time::SystemTime::now()`] | ||
/// internally, which would panic. | ||
fn from_std(time: std::time::SystemTime) -> SystemTime; | ||
} | ||
|
||
impl SystemTimeExt for SystemTime { | ||
fn to_std(self) -> std::time::SystemTime { | ||
StdSystemTime::UNIX_EPOCH + self.0 | ||
} | ||
|
||
fn from_std(time: std::time::SystemTime) -> SystemTime { | ||
Self::UNIX_EPOCH | ||
+ time | ||
.duration_since(StdSystemTime::UNIX_EPOCH) | ||
.expect("found `SystemTime` earlier then unix epoch") | ||
} | ||
} |