fix time convert overflow checks

This commit is contained in:
2026-03-18 09:31:55 -07:00
parent 96e9ebd22d
commit 7904f52f2f

View File

@@ -20,13 +20,14 @@ pub fn from_float<T>(time:f64)->Result<Time<T>,Error>{
core::num::FpCategory::Infinite
|core::num::FpCategory::Subnormal
|core::num::FpCategory::Normal=>{
if time<Time::<T>::MIN.get() as f64{
let time_raw=time*Time::<T>::ONE_SECOND.get() as f64;
if time_raw<Time::<T>::MIN.get() as f64{
return Err(Error::Underflow);
}
if (Time::<T>::MAX.get() as f64)<time{
if (Time::<T>::MAX.get() as f64)<time_raw{
return Err(Error::Overflow);
}
Ok(Time::raw((time*Time::<T>::ONE_SECOND.get() as f64) as i64))
Ok(Time::raw(time_raw as i64))
}
}
}