Add helper function to parse string with kairos
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
81c6ee8314
commit
9801a3c295
3 changed files with 27 additions and 0 deletions
|
@ -27,6 +27,7 @@ walkdir = "2.2.8"
|
|||
vobject = "0.7"
|
||||
handlebars = "2"
|
||||
chrono = "0.4"
|
||||
kairos = "0.3"
|
||||
|
||||
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||
|
|
|
@ -41,6 +41,7 @@ extern crate toml_query;
|
|||
extern crate walkdir;
|
||||
extern crate handlebars;
|
||||
extern crate chrono;
|
||||
extern crate kairos;
|
||||
|
||||
#[macro_use] extern crate libimagrt;
|
||||
extern crate libimagcalendar;
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue