diff options
Diffstat (limited to 'src')
-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] + } + } +} |