mirror of
https://github.com/nushell/nushell.git
synced 2025-08-11 13:04:39 +02:00
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:
@ -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())),
|
||||
|
Reference in New Issue
Block a user