Allow math avg to work on durations (#2529)

* Allow `math avg` to work on durations

* formatting

* fix linting issue and implemented `math sum` for duration

* fix linting issue

* applied requested changes

* applied requested change for avg.rs

* formatting
This commit is contained in:
gorogoroumaru
2020-09-13 08:56:05 +09:00
committed by GitHub
parent 7528094e12
commit 45f32c9541
4 changed files with 50 additions and 0 deletions

View File

@ -212,6 +212,29 @@ pub fn compute_values(
Ok(UntaggedValue::Primitive(Primitive::Duration(result)))
}
(Primitive::Int(x), Primitive::Duration(y)) => {
let result = match operator {
Operator::Plus => Ok(x + y),
Operator::Minus => Ok(x - y),
_ => Err((left.type_name(), right.type_name())),
}?;
Ok(UntaggedValue::Primitive(Primitive::Duration(result)))
}
(Primitive::Duration(x), Primitive::Decimal(y)) => {
let result = match operator {
Operator::Divide => {
if y.is_zero() {
return Ok(zero_division_error());
}
let y = y.as_bigint_and_exponent();
Ok(x / y.0)
}
_ => Err((left.type_name(), right.type_name())),
}?;
Ok(UntaggedValue::Primitive(Primitive::Duration(result)))
}
_ => Err((left.type_name(), right.type_name())),
},
_ => Err((left.type_name(), right.type_name())),