Skip to content

Commit

Permalink
date compares
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhibas committed Feb 17, 2024
1 parent b1e4296 commit 0c51dbb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .vimspector.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"filetypes": [ "rust" ],
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/target/debug/deps/parser_test-ce9cb22a64720f6c",
"args": ["test", "scopes_bug_test"]
"program": "${workspaceRoot}/target/debug/deps/bool_expr_parser_nom-78d60f34f694ffc8",
"args": ["test", "testing_date_comparison_evaluation"]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bool_expr_parser_nom"
version = "0.3.3"
version = "0.3.4"
edition = "2021"
authors = ["Nikolajus Krauklis <[email protected]>"]

Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- [+] either lower() or upper() function calls or case insensitive string comparison operators
- [+] support for single quote strings
- [+] evaluation with provided context
- [ ] date comparisons
- [+] date comparisons
- [ ] date > timestamp comparison
5 changes: 5 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ impl PartialOrd for Atom {
Atom::Number(v2) => v.partial_cmp(&f64::from(*v2)),
_ => None,
},
Atom::Date(v) => match other {
Atom::Date(v2) => v.partial_cmp(v2),
/// TODO: if compare to number it might be unixtimestamp
_ => None,
},
_ => None,
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,20 @@ mod tests {
}

#[test]
fn test_logic_expr_eval() {
fn testing_date_comparison_evaluation() {
let (i, expr) = parse("created > 2024-02-02 and created <= 2024-02-13").unwrap();
assert_eq!(
true,
eval(&expr, &HashMap::from([("created", "2024-02-12".into())])).unwrap()
);

// assert_eq!(eval(&parse("a>4 and b<3").unwrap().1, &HashMap::from([])).unwrap(), true);
assert_eq!(
false,
eval(
&parse("created < 2024-02-02").unwrap().1,
&HashMap::from([("created", "2024-02-02".into())])
)
.unwrap()
);
}
}

0 comments on commit 0c51dbb

Please sign in to comment.