mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Fix broken datetime duration addition
This commit is contained in:
parent
1b5a85c325
commit
a9485f01f8
2 changed files with 11 additions and 2 deletions
|
@ -299,8 +299,9 @@ pub fn to_duration(num: &Number) -> Result<Duration, String> {
|
|||
if num.0.abs() > max {
|
||||
return Err(format!("Implementation error: Number is out of range ({:?})", max))
|
||||
}
|
||||
let (ms, rem) = num.0.div_rem(&Num::from(1000));
|
||||
let ns = &rem / &Num::from(1_000_000_000);
|
||||
let ms = &num.0 * &Num::from(1000);
|
||||
let (ms, rem) = ms.div_rem(&Num::from(1));
|
||||
let ns = &rem * &Num::from(1_000_000_000);
|
||||
Ok(Duration::milliseconds(ms.to_int().unwrap()) +
|
||||
Duration::nanoseconds(ns.to_int().unwrap()))
|
||||
}
|
||||
|
|
|
@ -193,3 +193,11 @@ fn test_substance_add() {
|
|||
"air: Average molecular weight of air. \
|
||||
molar_mass = approx. 28.96790 gram -> 1 mole");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duration_add() {
|
||||
test("#jan 01, 1970# + 1 s",
|
||||
"1970-01-01 00:00:01 +00:00");
|
||||
test("#jan 01, 1970# + 1.123 s",
|
||||
"1970-01-01 00:00:01.123 +00:00");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue