Use non-deprecated chrono Duration functions

This commit is contained in:
Michael Davis 2024-03-12 09:58:33 -04:00 committed by Blaž Hrastnik
parent b44b627b14
commit 6c4d986c1b

View file

@ -27,7 +27,7 @@ pub fn increment(selected_text: &str, amount: i64) -> Option<String> {
let date_time = NaiveDateTime::parse_from_str(date_time, format.fmt).ok()?; let date_time = NaiveDateTime::parse_from_str(date_time, format.fmt).ok()?;
Some( Some(
date_time date_time
.checked_add_signed(Duration::minutes(amount))? .checked_add_signed(Duration::try_minutes(amount)?)?
.format(format.fmt) .format(format.fmt)
.to_string(), .to_string(),
) )
@ -35,14 +35,15 @@ pub fn increment(selected_text: &str, amount: i64) -> Option<String> {
(true, false) => { (true, false) => {
let date = NaiveDate::parse_from_str(date_time, format.fmt).ok()?; let date = NaiveDate::parse_from_str(date_time, format.fmt).ok()?;
Some( Some(
date.checked_add_signed(Duration::days(amount))? date.checked_add_signed(Duration::try_days(amount)?)?
.format(format.fmt) .format(format.fmt)
.to_string(), .to_string(),
) )
} }
(false, true) => { (false, true) => {
let time = NaiveTime::parse_from_str(date_time, format.fmt).ok()?; let time = NaiveTime::parse_from_str(date_time, format.fmt).ok()?;
let (adjusted_time, _) = time.overflowing_add_signed(Duration::minutes(amount)); let (adjusted_time, _) =
time.overflowing_add_signed(Duration::try_minutes(amount)?);
Some(adjusted_time.format(format.fmt).to_string()) Some(adjusted_time.format(format.fmt).to_string())
} }
(false, false) => None, (false, false) => None,