diff --git a/Cargo.toml b/Cargo.toml index c99eed3..69c987a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bma-ts" -version = "0.1.10" +version = "0.1.11" edition = "2021" authors = ["Serhij S. "] license = "MIT" diff --git a/src/monotonic.rs b/src/monotonic.rs index 1ecaf85..bf990a9 100644 --- a/src/monotonic.rs +++ b/src/monotonic.rs @@ -45,4 +45,8 @@ impl Monotonic { pub fn elapsed(&self) -> Duration { Self::now().0 - self.0 } + #[inline] + pub fn duration_since(&self, earlier: Self) -> Duration { + self.0 - earlier.0 + } } diff --git a/src/timestamp.rs b/src/timestamp.rs index bf1b7a0..e7460db 100644 --- a/src/timestamp.rs +++ b/src/timestamp.rs @@ -31,6 +31,14 @@ impl Timestamp { Err(Error::TimeWentBackward) } } + #[inline] + pub fn duration_since(self, earlier: Self) -> Result { + if self >= earlier { + Ok(self.0 - earlier.0) + } else { + Err(Error::TimeWentBackward) + } + } /// Converts between ANSI (Windows, 1601-01-01) and UNIX (1970-01-01) timestamps /// The source timestamp MUST be in nanoseconds (for Windows timestamp - multiply the source by /// 100)