Add functor for timepoint expiration to utils.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -39,6 +39,7 @@ pub use self::{
|
|||||||
time::{
|
time::{
|
||||||
exponential_backoff::{continue_exponential_backoff, continue_exponential_backoff_secs},
|
exponential_backoff::{continue_exponential_backoff, continue_exponential_backoff_secs},
|
||||||
now_millis as millis_since_unix_epoch, timepoint_ago, timepoint_from_now,
|
now_millis as millis_since_unix_epoch, timepoint_ago, timepoint_from_now,
|
||||||
|
timepoint_has_passed,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ pub fn parse_duration(duration: &str) -> Result<Duration> {
|
|||||||
.map_err(|error| err!("'{duration:?}' is not a valid duration string: {error:?}"))
|
.map_err(|error| err!("'{duration:?}' is not a valid duration string: {error:?}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
|
pub fn timepoint_has_passed(timepoint: SystemTime) -> bool {
|
||||||
|
SystemTime::now()
|
||||||
|
.duration_since(timepoint)
|
||||||
|
.is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn rfc2822_from_seconds(epoch: i64) -> String {
|
pub fn rfc2822_from_seconds(epoch: i64) -> String {
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|||||||
Reference in New Issue
Block a user