From db9f20681f90f206d393d2b06a6a8401515ff562 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Fri, 18 Mar 2022 14:57:13 -0400 Subject: Addition methods for NaiveDateTime --- src/month.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/month.rs') diff --git a/src/month.rs b/src/month.rs index 9582957..1419717 100644 --- a/src/month.rs +++ b/src/month.rs @@ -399,11 +399,14 @@ impl Month { } } - pub const fn add_overflowing(self, months: u8) -> (Self, u8) { + pub const fn add_overflowing(self, months: i8) -> (Self, u8) { let zero_indexed_num = ((self as u16) - 1) + months as u16; let wraps = (zero_indexed_num as u8) / 12; let zero_indexed_month = zero_indexed_num % 12; - let month = Self::from_u8((zero_indexed_month as u8) + 1).unwrap(); + let month = match Self::from_u8((zero_indexed_month as u8) + 1) { + Some(month) => month, + None => unsafe { std::hint::unreachable_unchecked() }, + }; (month, wraps) } -- cgit v1.2.3