From 92b1ebe43e90cc9c851ce87e1b4e597b5eb3e3ef Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 28 Aug 2018 19:27:01 +0200 Subject: Add support for count on periodic events --- src/periodic.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/periodic.rs') diff --git a/src/periodic.rs b/src/periodic.rs index f6cd2d7..af9810c 100644 --- a/src/periodic.rs +++ b/src/periodic.rs @@ -12,8 +12,8 @@ pub struct Periodic { pub event: Event, pub freq: Freq, pub interval: i64, + pub count: i64, pub until: Date, - // TODO: count, ... } #[derive(Debug)] @@ -34,6 +34,7 @@ impl Periodic { freq: Freq::Secondly, interval: 1, until: Date::empty(), + count: 0, } } @@ -41,6 +42,7 @@ impl Periodic { match param { "FREQ" => self.freq = value.parse()?, "INTERVAL" => self.interval = value.parse()?, + "COUNT" => self.count = value.parse()?, "UNTIL" => self.until = Date::parse(&value, "")?, _ => (), } @@ -51,8 +53,11 @@ impl Periodic { let mut start = self.event.start; let mut end = self.event.end_date(); let mut events = Vec::new(); + let mut count = 0; while start <= *last { - if !self.until.is_empty() && start <= self.until { + if (!self.until.is_empty() && start <= self.until) || + (count != 0 && count >= self.count) + { break; } @@ -61,6 +66,7 @@ impl Periodic { e.start = start; e.end = End::Date(end); events.push(e); + count += count; } start = start + self.freq.duration(self.interval); end = end + self.freq.duration(self.interval); -- cgit v1.2.3