diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-02 13:03:07 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-02 13:17:58 +0200 |
commit | 8cd7b44501d2843cfb2d9307ae2b83db15092028 (patch) | |
tree | 597c2acb9de9475de28e38cd365b8f84459dc17e | |
parent | fb2aa81b6360acb7033488d0b042d3eddf25ad4b (diff) |
Add ability to specify point in time in date filter argument
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/cli.rs | 11 | ||||
-rw-r--r-- | src/commands/util.rs | 12 |
2 files changed, 21 insertions, 2 deletions
@@ -1256,6 +1256,7 @@ fn arg_older_than_date(about: &str) -> Arg<'_> { .about(about) .long_about(r#" DATE can be a freeform date, for example '2h' + It can also be a exact date: '2020-01-01 00:12:45' Supported suffixes: @@ -1285,6 +1286,7 @@ fn arg_newer_than_date(about: &str) -> Arg<'_> { .about(about) .long_about(r#" DATE can be a freeform date, for example '2h' + It can also be a exact date: '2020-01-01 00:12:45' Supported suffixes: @@ -1305,7 +1307,14 @@ fn arg_newer_than_date(about: &str) -> Arg<'_> { } fn parse_date_from_string(s: &str) -> std::result::Result<(), String> { - humantime::parse_duration(s).map_err(|e| e.to_string()).map(|_| ()) + humantime::parse_duration(s) + .map_err(|e| e.to_string()) + .map(|_| ()) + .or_else(|_| { + humantime::parse_rfc3339_weak(s) + .map_err(|e| e.to_string()) + .map(|_| ()) + }) } fn parse_usize(s: &str) -> std::result::Result<(), String> { diff --git a/src/commands/util.rs b/src/commands/util.rs index 58763ac..beebfc5 100644 --- a/src/commands/util.rs +++ b/src/commands/util.rs @@ -227,7 +227,17 @@ pub fn display_data<D: Display>( pub fn get_date_filter(name: &str, matches: &ArgMatches) -> Result<Option<chrono::DateTime::<chrono::Local>>> { matches.value_of(name) - .map(humantime::parse_duration) + .map(|s| { + trace!("Parsing duration: '{}'", s); + humantime::parse_duration(s) + .map_err(Error::from) + .or_else(|_| { + trace!("Parsing time: '{}'", s); + humantime::parse_rfc3339_weak(s) + .map_err(Error::from) + .and_then(|d| d.elapsed().map_err(Error::from)) + }) + }) .transpose()? .map(chrono::Duration::from_std) .transpose()? |