add timepoint_from_now to complement timepoint_ago in utils

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-10-11 20:32:32 +00:00 committed by strawberry
parent 2ed0c267eb
commit 89b5c4ee1c
2 changed files with 8 additions and 1 deletions

View file

@ -34,7 +34,7 @@ pub use self::{
stream::{IterStream, ReadyExt, Tools as StreamTools, TryReadyExt},
string::{str_from_bytes, string_from_bytes},
sys::available_parallelism,
time::now_millis as millis_since_unix_epoch,
time::{now_millis as millis_since_unix_epoch, timepoint_ago, timepoint_from_now},
};
#[inline]

View file

@ -22,6 +22,13 @@ pub fn timepoint_ago(duration: Duration) -> Result<SystemTime> {
.ok_or_else(|| err!(Arithmetic("Duration {duration:?} is too large")))
}
#[inline]
pub fn timepoint_from_now(duration: Duration) -> Result<SystemTime> {
SystemTime::now()
.checked_add(duration)
.ok_or_else(|| err!(Arithmetic("Duration {duration:?} is too large")))
}
#[inline]
pub fn parse_duration(duration: &str) -> Result<Duration> {
cyborgtime::parse_duration(duration)