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/main.rs | 4 +++- src/periodic.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 66e1df1..67eb0fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,5 +25,7 @@ fn main() { let now = Date::now(); let events = calendar.get(&now, &(now + Duration::weeks(10))); - println!("{:?}", events); + for e in events { + println!("{}", e); + } } 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