File tree 1 file changed +4
-1
lines changed
1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -448,7 +448,7 @@ impl NaiveDate {
448
448
/// ```
449
449
#[ must_use]
450
450
pub fn from_num_days_from_ce_opt ( days : i32 ) -> Option < NaiveDate > {
451
- let days = days + 365 ; // make December 31, 1 BCE equal to day 0
451
+ let days = days. checked_add ( 365 ) ? ; // make December 31, 1 BCE equal to day 0
452
452
let ( year_div_400, cycle) = div_mod_floor ( days, 146_097 ) ;
453
453
let ( year_mod_400, ordinal) = internals:: cycle_to_yo ( cycle as u32 ) ;
454
454
let flags = YearFlags :: from_year_mod_400 ( year_mod_400 as i32 ) ;
@@ -2500,6 +2500,9 @@ mod tests {
2500
2500
assert_eq ! ( from_ndays_from_ce( NaiveDate :: MIN . num_days_from_ce( ) - 1 ) , None ) ;
2501
2501
assert_eq ! ( from_ndays_from_ce( NaiveDate :: MAX . num_days_from_ce( ) ) , Some ( NaiveDate :: MAX ) ) ;
2502
2502
assert_eq ! ( from_ndays_from_ce( NaiveDate :: MAX . num_days_from_ce( ) + 1 ) , None ) ;
2503
+
2504
+ assert_eq ! ( from_ndays_from_ce( i32 :: MIN ) , None ) ;
2505
+ assert_eq ! ( from_ndays_from_ce( i32 :: MAX ) , None ) ;
2503
2506
}
2504
2507
2505
2508
#[ test]
You can’t perform that action at this time.
0 commit comments