提交 06991b83 authored 作者: Serhij S's avatar Serhij S

diff_abs

上级 1885681b
...@@ -7,6 +7,9 @@ use bma_ts::Monotonic; ...@@ -7,6 +7,9 @@ use bma_ts::Monotonic;
pub trait DurationRT { pub trait DurationRT {
/// Returns true if all provided [`Monotonic`] times fit the duration /// Returns true if all provided [`Monotonic`] times fit the duration
fn fits(&self, t: &[Monotonic]) -> bool; fn fits(&self, t: &[Monotonic]) -> bool;
/// Returns the absolute difference between two durations (provided until abs_diff become
/// stable)
fn diff_abs(&self, other: Self) -> Duration;
} }
impl DurationRT for Duration { impl DurationRT for Duration {
...@@ -19,6 +22,13 @@ impl DurationRT for Duration { ...@@ -19,6 +22,13 @@ impl DurationRT for Duration {
max_ts.as_duration() - min_ts.as_duration() <= *self max_ts.as_duration() - min_ts.as_duration() <= *self
} }
} }
fn diff_abs(&self, other: Self) -> Duration {
if *self > other {
*self - other
} else {
other - *self
}
}
} }
pub fn interval(period: Duration) -> Interval { pub fn interval(period: Duration) -> Interval {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论