summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora <nora.widdecke@tu-bs.de>2019-03-22 18:26:48 +0100
committerNora <nora.widdecke@tu-bs.de>2019-03-22 18:26:48 +0100
commit7e2e7e0285b82151d4e8980d6230f785caa635d9 (patch)
treee65f2c18d146e1cc709cf934f4d8088a468eaeae
parentb79fdfa2bf3a3718a2a232eefe2021d142f31d64 (diff)
make get_start and get_end more logical
-rw-r--r--src/khevent.rs18
1 files 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<IcalTime> {
//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<IcalTime> {
//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