summaryrefslogtreecommitdiffstats
path: root/vendor/time/src/weekday.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /vendor/time/src/weekday.rs
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time/src/weekday.rs')
-rw-r--r--vendor/time/src/weekday.rs22
1 files changed, 22 insertions, 0 deletions
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