Skip to content

Commit

Permalink
Implement TimeWindow::contains
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-braun committed Oct 17, 2023
1 parent f1264ed commit 11ed30e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,23 @@ impl TimeWindow {
}
}


/// Returns true if this time window contains the given time.
/// # Examples
///
/// ```
/// # use tinytime::{Time, TimeWindow};
/// let mut x = TimeWindow::from_seconds(5, 10);
/// assert!(!x.contains(Time::seconds(4)));
/// assert!(x.contains(Time::seconds(5)));
/// assert!(x.contains(Time::seconds(7)));
/// assert!(x.contains(Time::seconds(10)));
/// assert!(!x.contains(Time::seconds(11)));
/// ```
pub fn contains(&self, that: Time) -> bool {
self.start <= that && that <= self.end
}

/// Returns true if this time window overlaps with another one
/// # Examples
///
Expand Down

0 comments on commit 11ed30e

Please sign in to comment.