Skip to content

Commit

Permalink
Merge pull request #43 from moia-oss/tw-contains
Browse files Browse the repository at this point in the history
Implement TimeWindow::contains
  • Loading branch information
fabian-braun authored Oct 17, 2023
2 parents f1264ed + 1525478 commit 2c708cc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,22 @@ 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 2c708cc

Please sign in to comment.