summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora <nora.widdecke@tu-bs.de>2019-03-10 16:07:37 +0100
committerNora <nora.widdecke@tu-bs.de>2019-03-10 16:07:37 +0100
commit3207813acca091c05b37fe919aa83aeed0ecada3 (patch)
tree62fe6d0392866a80a90f81e7b4980fc7bd3edaf8
parent5607b7c2718bdc29b1eaced8821d823f31b4c1be (diff)
use khevent, add get_principal_khevent
-rw-r--r--src/icalwrap/icalvcalendar.rs5
-rw-r--r--src/icalwrap/icalvevent.rs67
-rw-r--r--src/khevent.rs86
-rw-r--r--src/khline.rs4
-rw-r--r--src/testdata.rs7
5 files changed, 97 insertions, 72 deletions
diff --git a/src/icalwrap/icalvcalendar.rs b/src/icalwrap/icalvcalendar.rs
index 91a2018..98895ab 100644
--- a/src/icalwrap/icalvcalendar.rs
+++ b/src/icalwrap/icalvcalendar.rs
@@ -6,6 +6,7 @@ use std::io;
use super::IcalVEvent;
use super::IcalComponent;
use super::IcalTime;
+use crate::khevent::KhEvent;
use crate::ical;
pub struct IcalVCalendar {
@@ -261,6 +262,10 @@ impl IcalVCalendar {
event
}
+ pub fn get_principal_khevent(&self) -> KhEvent {
+ KhEvent::from_event_with_timestamp(self.get_first_event(), self.instance_timestamp.clone())
+ }
+
pub fn check_for_errors(&self) -> Option<Vec<String>> {
unsafe {
IcalVCalendar::check_icalcomponent(self.get_ptr())
diff --git a/src/icalwrap/icalvevent.rs b/src/icalwrap/icalvevent.rs
index 9e9ba9f..6aed773 100644
--- a/src/icalwrap/icalvevent.rs
+++ b/src/icalwrap/icalvevent.rs
@@ -290,26 +290,6 @@ mod tests {
}
#[test]
- fn test_is_recur_master() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
- assert!(cal.get_principal_event().is_recur_master());
- }
-
- #[test]
- fn test_is_recur_master_instance() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
- let event = cal.get_principal_event();
- let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2018, 01, 01));
- assert!(!event.is_recur_master());
- }
-
- #[test]
- fn test_is_recur_master_invalid() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_ONE_MEETING, None).unwrap();
- assert!(!cal.get_principal_event().is_recur_master());
- }
-
- #[test]
fn recur_datetimes_test() {
let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
@@ -319,51 +299,4 @@ mod tests {
assert_eq!(IcalTime::floating_ymd(2018, 10, 11).with_timezone(&local), recur_instances.next().unwrap().get_start().unwrap());
assert_eq!(IcalTime::floating_ymd(2018, 10, 18).with_timezone(&local), recur_instances.next().unwrap().get_start().unwrap());
}
-
- #[test]
- fn test_is_recur_valid_master() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
- let event = cal.get_principal_event();
-
- assert!(event.is_recur_valid());
- }
-
- #[test]
- fn test_is_recur_valid_dtstart() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
- let event = cal.get_principal_event();
-
- let event = event.with_internal_timestamp(&event.get_dtstart().unwrap());
-
- assert!(event.is_recur_valid());
- }
-
- #[test]
- fn test_is_recur_valid_incorrect() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
- let event = cal.get_principal_event();
-
- let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2010, 01, 01));
-
- assert!(!event.is_recur_valid());
- }
-
- #[test]
- fn test_is_recur_valid_other() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
- let event = cal.get_principal_event();
-
- let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2018, 10, 25));
-
- assert!(event.is_recur_valid());
- }
-
- #[test]
- fn test_is_recur_valid_nonrecur() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_ONE_MEETING, None).unwrap();
- let event = cal.get_principal_event();
-
- assert!(event.is_recur_valid());
- }
-
}
diff --git a/src/khevent.rs b/src/khevent.rs
index 0ea4889..80bd47a 100644
--- a/src/khevent.rs
+++ b/src/khevent.rs
@@ -1,3 +1,5 @@
+use std::path::PathBuf;
+
use crate::icalwrap::IcalTime;
use crate::icalwrap::IcalDuration;
use crate::icalwrap::IcalVEvent;
@@ -34,10 +36,21 @@ impl KhEvent {
}
}
+ pub fn with_internal_timestamp(self, timestamp: &IcalTime) -> Self {
+ Self {
+ event: self.event,
+ instance_timestamp: Some(timestamp.clone())
+ }
+ }
+
pub fn get_calendar_name(&self) -> Option<String> {
self.event.get_parent().and_then(|cal| cal.get_calendar_name())
}
+ pub fn get_path(&self) -> Option<&PathBuf> {
+ self.event.get_parent()?.get_path()
+ }
+
pub fn is_allday(&self) -> bool {
self.event.is_allday()
}
@@ -112,3 +125,76 @@ impl KhEvent {
}
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::testdata;
+ use crate::icalwrap::IcalVCalendar;
+ use chrono::NaiveDate;
+
+ #[test]
+ fn test_is_recur_valid_master() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
+ let event = cal.get_principal_khevent();
+
+ assert!(event.is_recur_valid());
+ }
+
+ #[test]
+ fn test_is_recur_valid_dtstart() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
+ let event = cal.get_principal_khevent();
+
+ let event = event.with_internal_timestamp(&event.get_start().unwrap());
+
+ assert!(event.is_recur_valid());
+ }
+
+ #[test]
+ fn test_is_recur_valid_incorrect() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
+ let event = cal.get_principal_khevent();
+
+ let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2010, 01, 01));
+
+ assert!(!event.is_recur_valid());
+ }
+
+ #[test]
+ fn test_is_recur_valid_other() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
+ let event = cal.get_principal_khevent();
+
+ let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2018, 10, 25));
+
+ assert!(event.is_recur_valid());
+ }
+
+ #[test]
+ fn test_is_recur_valid_nonrecur() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_ONE_MEETING, None).unwrap();
+ let event = cal.get_principal_khevent();
+
+ assert!(event.is_recur_valid());
+ }
+
+ #[test]
+ fn test_is_recur_master_instance() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
+ let event = cal.get_principal_khevent();
+ let event = event.with_internal_timestamp(&IcalTime::floating_ymd(2018, 01, 01));
+ assert!(!event.is_recur_master());
+ }
+
+ #[test]
+ fn test_is_recur_master() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap();
+ assert!(cal.get_principal_khevent().is_recur_master());
+ }
+
+ #[test]
+ fn test_is_recur_master_invalid() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_ONE_MEETING, None).unwrap();
+ assert!(!cal.get_principal_khevent().is_recur_master());
+ }
+}
diff --git a/src/khline.rs b/src/khline.rs
index 03a6407..e37c367 100644
--- a/src/khline.rs
+++ b/src/khline.rs
@@ -263,7 +263,7 @@ mod tests {
assert_eq!(
testdir.child(".khaleesi/cal/twodaysacrossbuckets.ics").path(),
- event.get_parent().unwrap().get_path().unwrap()
+ event.get_path().unwrap()
);
assert_eq!(12345, event.get_start().unwrap().timestamp());
}
@@ -277,7 +277,7 @@ mod tests {
assert_eq!(
testdir.child(".khaleesi/cal/twodaysacrossbuckets.ics").path(),
- event.get_parent().unwrap().get_path().unwrap()
+ event.get_path().unwrap()
);
assert_eq!(
IcalTime::floating_ymd(2018, 12, 13).and_hms(23, 30, 00),
diff --git a/src/testdata.rs b/src/testdata.rs
index 9828677..c242df3 100644
--- a/src/testdata.rs
+++ b/src/testdata.rs
@@ -248,13 +248,14 @@ pub fn setup() {
}
#[cfg(test)]
-use crate::icalwrap::{IcalVCalendar,IcalVEvent};
+use crate::icalwrap::{IcalVCalendar, IcalVEvent};
+use crate::khevent::KhEvent;
#[cfg(test)]
use std::path::Path;
#[cfg(test)]
-pub fn get_test_event(str: &str, path: Option<&Path>) -> IcalVEvent {
+pub fn get_test_event(str: &str, path: Option<&Path>) -> KhEvent {
IcalVCalendar::from_str(str, path)
- .map(|cal| cal.get_principal_event())
+ .map(|cal| KhEvent::from_event(cal.get_principal_event()))
.unwrap()
}