diff options
| author | Botahamec <botahamec@outlook.com> | 2022-03-18 14:57:13 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2022-03-18 14:57:13 -0400 |
| commit | db9f20681f90f206d393d2b06a6a8401515ff562 (patch) | |
| tree | 48c16c94a4bf0da27c7cde56a247703b7794600c /src/month.rs | |
| parent | e0e0a18a4bc873583e973d771669e88a92b20d92 (diff) | |
Addition methods for NaiveDateTime
Diffstat (limited to 'src/month.rs')
| -rw-r--r-- | src/month.rs | 7 |
1 files changed, 5 insertions, 2 deletions
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) } |
