diff options
author | dxtr85 | 2022-11-15 19:08:29 +0000 |
---|---|---|
committer | GitHub | 2022-11-15 19:08:29 +0000 |
commit | 888368dae955acd274c2f35790a38f1d3e14028d (patch) | |
tree | 13af60e74371434900c1546522a18726d4a88fbc | |
parent | df6d04425d130f385c4314ed944d5a27963ae9a3 (diff) |
Fix deprecation warnings for chrono 0.4.23 (#4738)
Co-authored-by: dxtr <dxtr@W540.mito>
-rw-r--r-- | helix-core/src/increment/date_time.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/helix-core/src/increment/date_time.rs b/helix-core/src/increment/date_time.rs index 1574bf4d..265242ce 100644 --- a/helix-core/src/increment/date_time.rs +++ b/helix-core/src/increment/date_time.rs @@ -74,12 +74,12 @@ impl DateTimeIncrementor { (true, false) => { let date = NaiveDate::parse_from_str(date_time, format.fmt).ok()?; - date.and_hms(0, 0, 0) + date.and_hms_opt(0, 0, 0).unwrap() } (false, true) => { let time = NaiveTime::parse_from_str(date_time, format.fmt).ok()?; - NaiveDate::from_ymd(0, 1, 1).and_time(time) + NaiveDate::from_ymd_opt(0, 1, 1).unwrap().and_time(time) } (false, false) => return None, }; @@ -312,10 +312,10 @@ fn ndays_in_month(year: i32, month: u32) -> u32 { } else { (year, month + 1) }; - let d = NaiveDate::from_ymd(y, m, 1); + let d = NaiveDate::from_ymd_opt(y, m, 1).unwrap(); // ...is preceded by the last day of the original month. - d.pred().day() + d.pred_opt().unwrap().day() } fn add_months(date_time: NaiveDateTime, amount: i64) -> Option<NaiveDateTime> { @@ -334,7 +334,7 @@ fn add_months(date_time: NaiveDateTime, amount: i64) -> Option<NaiveDateTime> { let day = cmp::min(date_time.day(), ndays_in_month(year, month)); - Some(NaiveDate::from_ymd(year, month, day).and_time(date_time.time())) + NaiveDate::from_ymd_opt(year, month, day).map(|date| date.and_time(date_time.time())) } fn add_years(date_time: NaiveDateTime, amount: i64) -> Option<NaiveDateTime> { @@ -342,8 +342,8 @@ fn add_years(date_time: NaiveDateTime, amount: i64) -> Option<NaiveDateTime> { let ndays = ndays_in_month(year, date_time.month()); if date_time.day() > ndays { - let d = NaiveDate::from_ymd(year, date_time.month(), ndays); - Some(d.succ().and_time(date_time.time())) + NaiveDate::from_ymd_opt(year, date_time.month(), ndays) + .and_then(|date| date.succ_opt().map(|date| date.and_time(date_time.time()))) } else { date_time.with_year(year) } |