From 7e2e7e0285b82151d4e8980d6230f785caa635d9 Mon Sep 17 00:00:00 2001 From: Nora Date: Fri, 22 Mar 2019 18:26:48 +0100 Subject: make get_start and get_end more logical --- src/khevent.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/khevent.rs b/src/khevent.rs index 1ec9aae..e44db0b 100644 --- a/src/khevent.rs +++ b/src/khevent.rs @@ -17,26 +17,29 @@ pub struct KhEvent { impl KhEvent { pub fn get_start(&self) -> Option { //TODO: should probably depend on is_recur_master, not the instance timestamp - match self.instance_timestamp { - Some(ref timestamp) => Some(timestamp.clone()), - None => self.event.get_dtstart(), + if self.is_recur_instance() { + self.instance_timestamp.clone() + } else { + self.event.get_dtstart() } } pub fn get_end(&self) -> Option { //TODO: should probably depend on is_recur_master, not the instance timestamp - match self.instance_timestamp { + let dtend = match self.instance_timestamp { Some(ref timestamp) => { let dur = self.get_duration().unwrap(); let dtend = timestamp.to_owned() + dur; Some(dtend) } None => self.event.get_dtend(), - } + }; + dtend.or(self.get_start().map(|start| start.succ())) } pub fn with_internal_timestamp(&self, timestamp: &IcalTime) -> Self { Self { + //why shallow copy? event: self.event.shallow_copy(), instance_timestamp: Some(timestamp.clone()), } @@ -107,6 +110,11 @@ impl KhEvent { self.event.has_property_rrule() && self.instance_timestamp.is_none() } + pub fn is_recur_instance(&self) -> bool { + self.event.has_property_rrule() && self.instance_timestamp.is_some() + } + + pub fn is_recur_valid(&self) -> bool { if self.is_recur_master() { true -- cgit v1.2.3