summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-02 13:10:38 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-02 13:17:59 +0200
commit513d7a17a580274c18aaa8161557b616574f07f8 (patch)
tree80f43a35461532d28fca61a35651ba255239dc4b
parent1e77f45fc8649b3fbb9e17bd6a5e262617abcc33 (diff)
Try to parse time with " 00:00:00" appended
This makes it a bit easier to only specify a date. If the parsing fails (e.g. with "2020-01-01"), this patch adds another step of parsing by adding " 00:00:00" to the commandline argument and trying again to parse. This way, the CLI argument can be "2020-01-01" and the time does not have to be specified. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net> Tested-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/cli.rs8
-rw-r--r--src/commands/util.rs7
2 files changed, 15 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index f2ae0ac..018415d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1260,6 +1260,7 @@ fn arg_older_than_date(about: &str) -> Arg<'_> {
.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'
+ If the hour-minute-second part is omitted, " 00:00:00" is appended automatically.
Supported suffixes:
@@ -1290,6 +1291,7 @@ fn arg_newer_than_date(about: &str) -> Arg<'_> {
.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'
+ If the hour-minute-second part is omitted, " 00:00:00" is appended automatically.
Supported suffixes:
@@ -1318,6 +1320,12 @@ fn parse_date_from_string(s: &str) -> std::result::Result<(), String> {
.map_err(|e| e.to_string())
.map(|_| ())
})
+ .or_else(|_| {
+ let s = format!("{} 00:00:00", s);
+ 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 beebfc5..acfbdd2 100644
--- a/src/commands/util.rs
+++ b/src/commands/util.rs
@@ -237,6 +237,13 @@ pub fn get_date_filter(name: &str, matches: &ArgMatches) -> Result<Option<chrono
.map_err(Error::from)
.and_then(|d| d.elapsed().map_err(Error::from))
})
+ .or_else(|_| {
+ let s = format!("{} 00:00:00", s);
+ 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)