diff --git a/src/packages/arithmetic.rs b/src/packages/arithmetic.rs index 7b011ceb..c848fbe3 100644 --- a/src/packages/arithmetic.rs +++ b/src/packages/arithmetic.rs @@ -16,8 +16,8 @@ use num_traits::float::Float; use crate::stdlib::{format, string::String}; #[inline(always)] -pub fn make_err(msg: String) -> Box { - EvalAltResult::ErrorArithmetic(msg, Position::none()).into() +pub fn make_err(msg: impl Into) -> Box { + EvalAltResult::ErrorArithmetic(msg.into(), Position::none()).into() } macro_rules! gen_arithmetic_functions { diff --git a/src/packages/time_basic.rs b/src/packages/time_basic.rs index f53e703c..ab0cbd5e 100644 --- a/src/packages/time_basic.rs +++ b/src/packages/time_basic.rs @@ -34,7 +34,11 @@ mod time_functions { pub fn elapsed(timestamp: &mut Instant) -> Result> { #[cfg(not(feature = "no_float"))] { - Ok((timestamp.elapsed().as_secs_f64() as FLOAT).into()) + if *timestamp <= Instant::now() { + Ok((timestamp.elapsed().as_secs_f64() as FLOAT).into()) + } else { + Err(make_arithmetic_err("Time-stamp is later than now")) + } } #[cfg(feature = "no_float")] @@ -46,6 +50,8 @@ mod time_functions { "Integer overflow for timestamp.elapsed: {}", seconds ))) + } else if *timestamp <= Instant::now() { + Err(make_arithmetic_err("Time-stamp is later than now")) } else { Ok((seconds as INT).into()) }