From d2c180d00d06fadb403994b35818519b102a03c7 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Thu, 28 Sep 2023 14:58:53 +0200 Subject: [PATCH 1/2] Implement extend_start --- src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index eb85fde..3eb281a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -412,6 +412,29 @@ impl TimeWindow { self.end = end; } + /// Extends time window start to the given value. Is a No-Op when given value + /// isn't earlier than current time window start. + /// Returns by which duration the start was moved. + /// # Examples + /// + /// ``` + /// # use tinytime::Duration; + /// # use tinytime::Time; + /// # use tinytime::TimeWindow; + /// let mut x = TimeWindow::from_seconds(4, 5); + /// assert_eq!(Some(Duration::seconds(1)), x.extend_start(Time::seconds(3))); + /// assert_eq!(Time::seconds(3), x.start()); + /// assert_eq!(None, x.extend_start(Time::seconds(6))); + /// assert_eq!(Time::seconds(3), x.start()); + /// ``` + pub fn extend_start(&mut self, new_start: Time) -> Option { + (new_start < self.start).then(|| { + let diff = self.start - new_start; + self.set_start(new_start); + diff + }) + } + /// Extends time window end to the given value. Is a No-Op when given value /// isn't greater than current time window end. /// Returns by which duration the deadline was extended. From a651ba3bfcf3fc00414f9b97de13084142385a10 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Thu, 28 Sep 2023 15:01:02 +0200 Subject: [PATCH 2/2] Fmt --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3eb281a..85bb424 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -412,8 +412,8 @@ impl TimeWindow { self.end = end; } - /// Extends time window start to the given value. Is a No-Op when given value - /// isn't earlier than current time window start. + /// Extends time window start to the given value. Is a No-Op when given + /// value isn't earlier than current time window start. /// Returns by which duration the start was moved. /// # Examples ///