Skip to content

Commit

Permalink
Add TimeWindow::from_end constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
urmaul committed Sep 27, 2023
1 parent 432cedb commit bb899db
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,22 @@ impl TimeWindow {
/// assert_eq!(Time::seconds(3), x.end());
/// ```
pub fn from_duration(start: Time, duration: Duration) -> Self {
TimeWindow {
start,
end: start.add(duration),
}
TimeWindow::new(start, start.add(duration))
}

/// Creates time window from duration and end time.
/// # Examples
///
/// ```
/// # use tinytime::Duration;
/// # use tinytime::Time;
/// # use tinytime::TimeWindow;
/// let mut x = TimeWindow::from_end(Duration::seconds(2), Time::seconds(3));
/// assert_eq!(Time::seconds(1), x.start());
/// assert_eq!(Time::seconds(3), x.end());
/// ```
pub fn from_end(duration: Duration, end: Time) -> Self {
TimeWindow::new(end.sub(duration), end)
}

pub const fn instant(time: Time) -> Self {
Expand Down

0 comments on commit bb899db

Please sign in to comment.