diff --git a/src/naive/date.rs b/src/naive/date.rs index a2e3c0f800..61dcd52676 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -605,7 +605,9 @@ impl NaiveDate { /// ``` #[must_use] pub fn checked_add_months(self, months: Months) -> Option { - if months.0 == 0 { + // To be useable by `DateTime` this method should guarantee the result is valid, even if + // the input `self` is out of range. So only short-circuit if in range. + if months.0 == 0 && self >= Self::MIN && self <= Self::MAX { return Some(self); } @@ -636,7 +638,9 @@ impl NaiveDate { /// ``` #[must_use] pub fn checked_sub_months(self, months: Months) -> Option { - if months.0 == 0 { + // To be useable by `DateTime` this method should guarantee the result is valid, even if + // the input `self` is out of range. So only short-circuit if in range. + if months.0 == 0 && self >= Self::MIN && self <= Self::MAX { return Some(self); }