mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 19:57:44 +02:00
Implement modulo for duration (#10745)
# Description This PR adds the ability to use modulo with durations: ```nu (2min + 31sec) mod 20sec # 11sec ``` # User-Facing Changes Allows to use `<duration> mod <duration>`
This commit is contained in:
@ -3445,6 +3445,13 @@ impl Value {
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::Duration { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
|
||||
if *rhs != 0 {
|
||||
Ok(Value::duration(lhs % rhs, span))
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero { span: op })
|
||||
}
|
||||
}
|
||||
(Value::CustomValue { val: lhs, .. }, rhs) => {
|
||||
lhs.operation(span, Operator::Math(Math::Modulo), op, rhs)
|
||||
}
|
||||
|
Reference in New Issue
Block a user