summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
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 /src/cli.rs
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>
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs8
1 files changed, 8 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> {