File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -605,7 +605,9 @@ impl NaiveDate {
605
605
/// ```
606
606
#[ must_use]
607
607
pub fn checked_add_months ( self , months : Months ) -> Option < Self > {
608
- if months. 0 == 0 {
608
+ // To be useable by `DateTime` this method should guarantee the result is valid, even if
609
+ // the input `self` is out of range. So only short-circuit if in range.
610
+ if months. 0 == 0 && self >= Self :: MIN && self <= Self :: MAX {
609
611
return Some ( self ) ;
610
612
}
611
613
@@ -636,7 +638,9 @@ impl NaiveDate {
636
638
/// ```
637
639
#[ must_use]
638
640
pub fn checked_sub_months ( self , months : Months ) -> Option < Self > {
639
- if months. 0 == 0 {
641
+ // To be useable by `DateTime` this method should guarantee the result is valid, even if
642
+ // the input `self` is out of range. So only short-circuit if in range.
643
+ if months. 0 == 0 && self >= Self :: MIN && self <= Self :: MAX {
640
644
return Some ( self ) ;
641
645
}
642
646
You can’t perform that action at this time.
0 commit comments