From 5548acca68e4ec8ea543449db6d5c503062934e4 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 28 Aug 2018 11:29:38 +0200 Subject: Add support for intervals on periodic --- src/events.rs | 6 ++++-- src/periodic.rs | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/events.rs b/src/events.rs index 9cda846..948e86a 100644 --- a/src/events.rs +++ b/src/events.rs @@ -75,8 +75,10 @@ impl fmt::Display for Events { fn rrule(value: &String, params: &Vec<(String, Vec)>) -> Result { let mut periodic = Periodic::new(); - let p: Vec<&str> = value.splitn(2, "=").collect(); - periodic.set_param(p[0], p[1])?; + for entry in value.split(";") { + let p: Vec<&str> = entry.splitn(2, "=").collect(); + periodic.set_param(p[0], p[1])?; + } for (param, values) in params { let mut value = ""; diff --git a/src/periodic.rs b/src/periodic.rs index 0fa06ef..e46a13b 100644 --- a/src/periodic.rs +++ b/src/periodic.rs @@ -8,7 +8,8 @@ use errors::EventError; pub struct Periodic { pub event: Event, pub freq: Freq, - // TODO: until, count, interval, ... + pub interval: i64, + // TODO: until, count, ... } #[derive(Debug)] @@ -27,12 +28,14 @@ impl Periodic { Self { event: Event::new(), freq: Freq::Secondly, + interval: 1, } } pub fn set_param(&mut self, param: &str, value: &str) -> Result<(), EventError> { match param { "FREQ" => self.freq = value.parse()?, + "INTERVAL" => self.interval = value.parse()?, _ => (), } Ok(()) @@ -41,7 +44,11 @@ impl Periodic { impl fmt::Display for Periodic { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}: {}", self.freq, self.event)?; + write!(f, "{:?}", self.freq)?; + if self.interval != 1 { + write!(f, "({})", self.interval)?; + } + write!(f, ": {}", self.event)?; Ok(()) } } -- cgit v1.2.3