summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-calendar/src/util.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-10-03 15:52:16 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-11 21:36:44 +0200
commit9801a3c29550519caa6633eaefff6707ae34ea46 (patch)
tree52db127a6d7cb812e0ded7634a4a5ba63fff8123 /bin/domain/imag-calendar/src/util.rs
parent81c6ee83140e866bf4b72ecc1769ae8f2d5773f2 (diff)
Add helper function to parse string with kairos
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'bin/domain/imag-calendar/src/util.rs')
-rw-r--r--bin/domain/imag-calendar/src/util.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/bin/domain/imag-calendar/src/util.rs b/bin/domain/imag-calendar/src/util.rs
index ab9f8eba..3908b552 100644
--- a/bin/domain/imag-calendar/src/util.rs
+++ b/bin/domain/imag-calendar/src/util.rs
@@ -27,6 +27,7 @@ use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
use toml_query::read::TomlValueReadTypeExt;
+use chrono::NaiveDateTime;
use libimagrt::runtime::Runtime;
use libimagstore::store::FileLockEntry;
@@ -34,6 +35,7 @@ use libimagentryref::reference::fassade::RefFassade;
use libimagentryref::reference::Ref;
use libimagentryref::reference::Config;
use libimagentryref::hasher::default::DefaultHasher;
+use libimagerror::trace::MapErrTrace;
pub struct ParsedEventFLE<'a> {
inner: FileLockEntry<'a>,
@@ -117,3 +119,26 @@ pub fn build_data_object_for_handlebars<'a>(i: usize, event: &Event<'a>)
data
}
+
+pub fn kairos_parse(spec: &str) -> Result<NaiveDateTime> {
+ match ::kairos::parser::parse(spec).map_err_trace_exit_unwrap() {
+ ::kairos::parser::Parsed::Iterator(_) => {
+ trace!("before-filter spec resulted in iterator");
+ Err(format_err!("Not a moment in time: {}", spec))
+ }
+
+ ::kairos::parser::Parsed::TimeType(tt) => {
+ trace!("before-filter spec resulted in timetype");
+ let tt = tt.calculate()
+ .map_err_trace_exit_unwrap()
+ .get_moment().unwrap_or_else(|| {
+ error!("Not a moment in time: {}", spec);
+ ::std::process::exit(1);
+ })
+ .clone();
+
+ trace!("Before filter spec {} => {}", spec, tt);
+ Ok(tt)
+ }
+ }
+}