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:
mike 2023-02-27 23:17:58 +03:00 committed by GitHub
parent ba5258d716
commit 0a2e711351
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -107,6 +107,7 @@ pub fn math_result_type(
(Type::Int, Type::Float) => (Type::Float, None),
(Type::Float, Type::Float) => (Type::Float, None),
(Type::Date, Type::Date) => (Type::Duration, None),
(Type::Date, Type::Duration) => (Type::Date, None),
(Type::Duration, Type::Duration) => (Type::Duration, None),
(Type::Filesize, Type::Filesize) => (Type::Filesize, None),

View File

@ -24,3 +24,17 @@ fn number_int() -> TestResult {
fn number_float() -> TestResult {
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)
}