Trap elapsed error when timestamp is later than now.
This commit is contained in:
parent
7ede299aae
commit
a4b674d015
@ -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> {
|
||||
EvalAltResult::ErrorArithmetic(msg, Position::none()).into()
|
||||
pub fn make_err(msg: impl Into<String>) -> Box<EvalAltResult> {
|
||||
EvalAltResult::ErrorArithmetic(msg.into(), Position::none()).into()
|
||||
}
|
||||
|
||||
macro_rules! gen_arithmetic_functions {
|
||||
|
@ -34,7 +34,11 @@ mod time_functions {
|
||||
pub fn elapsed(timestamp: &mut Instant) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
#[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())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user