From a0b8f38ab54ac451646aa00cd5e91b6c76f22a84 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:19 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/time/src/weekday.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'vendor/time/src/weekday.rs') diff --git a/vendor/time/src/weekday.rs b/vendor/time/src/weekday.rs index f499c30ee..d530a2e4d 100644 --- a/vendor/time/src/weekday.rs +++ b/vendor/time/src/weekday.rs @@ -66,6 +66,28 @@ impl Weekday { } } + /// Get n-th next day. + /// + /// ```rust + /// # use time::Weekday; + /// assert_eq!(Weekday::Monday.nth_next(1), Weekday::Tuesday); + /// assert_eq!(Weekday::Sunday.nth_next(10), Weekday::Wednesday); + /// ``` + pub const fn nth_next(self, n: u8) -> Self { + match (self.number_days_from_monday() + n % 7) % 7 { + 0 => Monday, + 1 => Tuesday, + 2 => Wednesday, + 3 => Thursday, + 4 => Friday, + 5 => Saturday, + val => { + debug_assert!(val == 6); + Sunday + } + } + } + /// Get the one-indexed number of days from Monday. /// /// ```rust -- cgit v1.2.3