diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/periodic.rs | 10 |
2 files changed, 11 insertions, 3 deletions
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); |