mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 07:28:27 +02:00
Allow duration to be added to date (#14295)
# Description Fixes #14294 - Turned out to be a whole lot easier than I expected, but please double-check me on this, since it's an area I haven't been in before. # User-Facing Changes Allow date to be added to a duration type. # Tests + Formatting Tests added: * Duration + Date is allowed * Duration - Date is not allowed
This commit is contained in:
@ -2444,6 +2444,17 @@ impl Value {
|
||||
Ok(Value::string(lhs.to_string() + rhs, span))
|
||||
}
|
||||
|
||||
(Value::Duration { val: lhs, .. }, Value::Date { val: rhs, .. }) => {
|
||||
if let Some(val) = rhs.checked_add_signed(chrono::Duration::nanoseconds(*lhs)) {
|
||||
Ok(Value::date(val, span))
|
||||
} else {
|
||||
Err(ShellError::OperatorOverflow {
|
||||
msg: "addition operation overflowed".into(),
|
||||
span,
|
||||
help: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
(Value::Date { val: lhs, .. }, Value::Duration { val: rhs, .. }) => {
|
||||
if let Some(val) = lhs.checked_add_signed(chrono::Duration::nanoseconds(*rhs)) {
|
||||
Ok(Value::date(val, span))
|
||||
|
Reference in New Issue
Block a user