diff --git a/bin/domain/imag-timetrack/Cargo.toml b/bin/domain/imag-timetrack/Cargo.toml index 2d2ce99c..586472f7 100644 --- a/bin/domain/imag-timetrack/Cargo.toml +++ b/bin/domain/imag-timetrack/Cargo.toml @@ -25,6 +25,7 @@ chrono = "0.4" filters = "0.2" itertools = "0.7" prettytable-rs = "0.6" +kairos = "0.1" libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" } libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" } diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs index d58028a4..cb0fd2a4 100644 --- a/bin/domain/imag-timetrack/src/list.rs +++ b/bin/domain/imag-timetrack/src/list.rs @@ -17,13 +17,14 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::str::FromStr; - use chrono::NaiveDateTime; use filters::filter::Filter; use prettytable::Table; use prettytable::row::Row; use prettytable::cell::Cell; +use kairos::parser::Parsed; +use kairos::parser::parse as kairos_parse; +use clap::ArgMatches; use libimagerror::trace::trace_error; use libimagerror::trace::MapErrTrace; @@ -39,23 +40,38 @@ pub fn list(rt: &Runtime) -> i32 { let (_, cmd) = rt.cli().subcommand(); let cmd = cmd.unwrap(); // checked in main() - let start = match cmd.value_of("start-time").map(::chrono::naive::NaiveDateTime::from_str) { - None => None, - Some(Ok(dt)) => Some(dt), - Some(Err(e)) => { - trace_error(&e); - None - } - }; - let end = match cmd.value_of("end-time").map(::chrono::naive::NaiveDateTime::from_str) { - None => None, - Some(Ok(dt)) => Some(dt), - Some(Err(e)) => { - trace_error(&e); - None + let gettime = |cmd: &ArgMatches, name| { + match cmd.value_of(name).map(kairos_parse) { + Some(Ok(Parsed::TimeType(tt))) => match tt.calculate() { + Ok(tt) => { + let dt = tt.get_moment().unwrap_or_else(|| { + error!("Failed to get date from '{}'", cmd.value_of(name).unwrap()); + ::std::process::exit(1) + }); + + Some(dt.clone()) + }, + Err(e) => { + error!("Failed to calculate date from '{}': {:?}", + cmd.value_of(name).unwrap(), e); + ::std::process::exit(1) + }, + }, + Some(Ok(Parsed::Iterator(_))) => { + error!("Expected single point in time, got '{}', which yields a list of dates", cmd.value_of(name).unwrap()); + ::std::process::exit(1) + }, + Some(Err(e)) => { + trace_error(&e); + ::std::process::exit(1) + } + None => None, } }; + let start = gettime(&cmd, "start-time"); + let end = gettime(&cmd, "end-time"); + let list_not_ended = cmd.is_present("list-not-ended"); list_impl(rt, start, end, list_not_ended) diff --git a/bin/domain/imag-timetrack/src/main.rs b/bin/domain/imag-timetrack/src/main.rs index 33f32583..c5054460 100644 --- a/bin/domain/imag-timetrack/src/main.rs +++ b/bin/domain/imag-timetrack/src/main.rs @@ -25,6 +25,7 @@ extern crate chrono; extern crate filters; extern crate itertools; extern crate prettytable; +extern crate kairos; extern crate libimagerror; extern crate libimagstore; diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md index 94fcb584..8f44f2a5 100644 --- a/doc/src/09020-changelog.md +++ b/doc/src/09020-changelog.md @@ -19,6 +19,9 @@ Version 0.y.z and thus we can break the API like we want and need to. This section contains the changelog from the last release to the next release. * Major changes + * `imag-timetrack list --from/--to` now have `kairos` support - that means + that complex `--from/--to` arguments (like `yesterday` or `today-2weeks`) + are now possible * Minor changes * Bugfixes