diff options
author | Ruben Pollan | 2018-08-28 19:17:39 +0200 |
---|---|---|
committer | Ruben Pollan | 2018-08-28 19:17:39 +0200 |
commit | 50e9a4421c7a27bcf01d7adab8d20b7df18f534c (patch) | |
tree | 568b2ace65bb41ec7d3bdebb5460705efa20af2a /src | |
parent | 6263be67208f68a8c8ce1a8a18fc9921df53048e (diff) |
Get events from the list by date
Diffstat (limited to '')
-rw-r--r-- | src/calendar.rs | 4 | ||||
-rw-r--r-- | src/event.rs | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/calendar.rs b/src/calendar.rs index c49e747..ab465ea 100644 --- a/src/calendar.rs +++ b/src/calendar.rs @@ -4,6 +4,7 @@ use ical::IcalParser; use chrono::Duration; use date::Date; +use event; use event::{Event, End}; use periodic::Periodic; use errors::EventError; @@ -62,8 +63,7 @@ impl Calendar { } pub fn get(&self, first: &Date, last: &Date) -> Vec<Event> { - // TODO: not all single, just the one by date - let mut events = self.single.clone(); + let mut events = event::get(&self.single, first, last).to_vec(); for p in &self.periodic { events.append(&mut p.get(first, last)); } diff --git a/src/event.rs b/src/event.rs index b54c422..d086295 100644 --- a/src/event.rs +++ b/src/event.rs @@ -82,3 +82,17 @@ impl FromStr for Status { } } } + + +pub fn get<'a>(events: &'a Vec<Event>, first: &Date, last: &Date) -> &'a [Event] { + match events.iter().position(|ref e| e.start >= *first) { + None => &[], + Some(i) => { + let j = events + .iter() + .position(|ref e| e.end_date() > *last) + .unwrap_or(events.len()); + &events[i..j] + } + } +} |