mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 07:30:13 +01:00
fix: allow subtraction of durations from dates (#8247)
`date` - `duration` is
[implemented](ba5258d716/crates/nu-protocol/src/value/mod.rs (L2145)
)
but the type checker rejects it
this pr fixes that
This commit is contained in:
parent
ba5258d716
commit
0a2e711351
@ -107,6 +107,7 @@ pub fn math_result_type(
|
|||||||
(Type::Int, Type::Float) => (Type::Float, None),
|
(Type::Int, Type::Float) => (Type::Float, None),
|
||||||
(Type::Float, Type::Float) => (Type::Float, None),
|
(Type::Float, Type::Float) => (Type::Float, None),
|
||||||
(Type::Date, Type::Date) => (Type::Duration, None),
|
(Type::Date, Type::Date) => (Type::Duration, None),
|
||||||
|
(Type::Date, Type::Duration) => (Type::Date, None),
|
||||||
(Type::Duration, Type::Duration) => (Type::Duration, None),
|
(Type::Duration, Type::Duration) => (Type::Duration, None),
|
||||||
(Type::Filesize, Type::Filesize) => (Type::Filesize, None),
|
(Type::Filesize, Type::Filesize) => (Type::Filesize, None),
|
||||||
|
|
||||||
|
@ -24,3 +24,17 @@ fn number_int() -> TestResult {
|
|||||||
fn number_float() -> TestResult {
|
fn number_float() -> TestResult {
|
||||||
run_test(r#"def foo [x:number] { $x }; foo 1.4"#, "1.4")
|
run_test(r#"def foo [x:number] { $x }; foo 1.4"#, "1.4")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn date_minus_duration() -> TestResult {
|
||||||
|
let input = "2023-04-22 - 2day | date format %Y-%m-%d";
|
||||||
|
let expected = "2023-04-20";
|
||||||
|
run_test(input, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn date_plus_duration() -> TestResult {
|
||||||
|
let input = "2023-04-18 + 2day | date format %Y-%m-%d";
|
||||||
|
let expected = "2023-04-20";
|
||||||
|
run_test(input, expected)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user