-
Notifications
You must be signed in to change notification settings - Fork 81
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
61 changed files
with
1,189 additions
and
424 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,66 @@ | ||
use cfg_primitives::{Days, Millis, Seconds}; | ||
use frame_support::traits::UnixTime; | ||
|
||
/// Trait to obtain the unix time as seconds | ||
pub trait UnixTimeSecs: UnixTime { | ||
fn now() -> Seconds { | ||
Seconds::from(<Self as UnixTime>::now().as_secs()) | ||
} | ||
|
||
/// Same as now(), shortcut for cases where `now()` conflicts with | ||
/// `UnixTime::now()` | ||
fn now_secs() -> Seconds { | ||
<Self as UnixTimeSecs>::now() | ||
} | ||
} | ||
|
||
impl<T: UnixTime> UnixTimeSecs for T {} | ||
|
||
/// Trait to handle an unknown time unit type | ||
pub trait TimeUnit { | ||
fn as_millis(self) -> Millis; | ||
fn as_seconds(self) -> Seconds; | ||
fn as_days(self) -> Days; | ||
} | ||
|
||
impl TimeUnit for Millis { | ||
fn as_millis(self) -> Millis { | ||
self | ||
} | ||
|
||
fn as_seconds(self) -> Seconds { | ||
self.into_seconds() | ||
} | ||
|
||
fn as_days(self) -> Days { | ||
self.into_days() | ||
} | ||
} | ||
|
||
impl TimeUnit for Seconds { | ||
fn as_millis(self) -> Millis { | ||
self.into_millis() | ||
} | ||
|
||
fn as_seconds(self) -> Seconds { | ||
self | ||
} | ||
|
||
fn as_days(self) -> Days { | ||
self.into_days() | ||
} | ||
} | ||
|
||
impl TimeUnit for Days { | ||
fn as_millis(self) -> Millis { | ||
self.into_millis() | ||
} | ||
|
||
fn as_seconds(self) -> Seconds { | ||
self.into_seconds() | ||
} | ||
|
||
fn as_days(self) -> Days { | ||
self | ||
} | ||
} |
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
Oops, something went wrong.