use std::time::Duration;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TimeWindow {
start: Duration,
end: Duration,
}
impl TimeWindow {
pub fn new(start: Duration, end: Duration) -> Option<Self> {
(start < end).then_some(Self { start, end })
}
#[inline]
pub fn start(&self) -> Duration {
self.start
}
#[inline]
pub fn end(&self) -> Duration {
self.end
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn inverted_and_empty_windows_are_rejected() {
let s = Duration::from_secs;
assert!(TimeWindow::new(s(1), s(2)).is_some());
assert!(TimeWindow::new(s(1), s(1)).is_none());
assert!(TimeWindow::new(s(2), s(1)).is_none());
}
}