diff --git a/src/items/mod.rs b/src/items/mod.rs index 28e4aa7..6285ba7 100644 --- a/src/items/mod.rs +++ b/src/items/mod.rs @@ -356,7 +356,7 @@ fn at_date_inner(date: Vec, at: DateTime) -> Option, at: DateTime) -> Option d += chrono::Duration::days(x.into()), relative::Relative::Hours(x) => d += chrono::Duration::hours(x.into()), relative::Relative::Minutes(x) => { - d += chrono::Duration::minutes(x.into()); + d += chrono::Duration::try_minutes(x.into())?; } // Seconds are special because they can be given as a float relative::Relative::Seconds(x) => { - d += chrono::Duration::seconds(x as i64); + d += chrono::Duration::try_seconds(x as i64)?; } } } diff --git a/src/items/relative.rs b/src/items/relative.rs index 6830082..7adaee8 100644 --- a/src/items/relative.rs +++ b/src/items/relative.rs @@ -54,13 +54,15 @@ pub enum Relative { } impl Relative { + // TODO: determine how to handle multiplication overflows, + // using saturating_mul for now. fn mul(self, n: i32) -> Self { match self { - Self::Years(x) => Self::Years(n * x), - Self::Months(x) => Self::Months(n * x), - Self::Days(x) => Self::Days(n * x), - Self::Hours(x) => Self::Hours(n * x), - Self::Minutes(x) => Self::Minutes(n * x), + Self::Years(x) => Self::Years(n.saturating_mul(x)), + Self::Months(x) => Self::Months(n.saturating_mul(x)), + Self::Days(x) => Self::Days(n.saturating_mul(x)), + Self::Hours(x) => Self::Hours(n.saturating_mul(x)), + Self::Minutes(x) => Self::Minutes(n.saturating_mul(x)), Self::Seconds(x) => Self::Seconds(f64::from(n) * x), } }