TimerangeBound: add functions to extend the tolerances

(This seems much cleaner than baking extra tolerances into the
"true" validity intervals")
This commit is contained in:
Nick Mathewson 2020-09-08 14:01:26 -04:00
parent 8ef0098716
commit d840bbbf64
1 changed files with 13 additions and 0 deletions

View File

@ -54,6 +54,19 @@ impl<T> TimerangeBound<T> {
let end = unwrap_bound(range.end_bound());
Self { obj, start, end }
}
/// Adjust this time-range bound to tolerate an expiration time farther
/// in the future.
pub fn extend_tolerance(self, d: time::Duration) -> Self {
let end = self.end.map(|t| t + d);
Self { end, ..self }
}
/// Adjust this time-range bound to tolerate an initial validity
/// time farther in the past.
pub fn extend_pre_tolerance(self, d: time::Duration) -> Self {
let start = self.start.map(|t| t - d);
Self { start, ..self }
}
}
impl<T> crate::Timebound<T> for TimerangeBound<T> {