summaryrefslogtreecommitdiffstats
path: root/src/icalwrap
diff options
context:
space:
mode:
authorNora <nora.widdecke@tu-bs.de>2019-01-18 22:50:21 +0100
committerNora <nora.widdecke@tu-bs.de>2019-01-18 23:09:20 +0100
commit34483ee1270d84cb42a122965917916094855508 (patch)
tree8998613d6fb98188c416eda494e03129e1b5ffed /src/icalwrap
parentdb3f62f570c874056846b7f349e700dc1280837d (diff)
dateutil: add testable now() function
Diffstat (limited to 'src/icalwrap')
-rw-r--r--src/icalwrap/icalproperty.rs2
-rw-r--r--src/icalwrap/icalvcalendar.rs23
2 files changed, 24 insertions, 1 deletions
diff --git a/src/icalwrap/icalproperty.rs b/src/icalwrap/icalproperty.rs
index 15b07e0..85bad3d 100644
--- a/src/icalwrap/icalproperty.rs
+++ b/src/icalwrap/icalproperty.rs
@@ -6,7 +6,7 @@ use super::icalcomponent::IcalComponent;
use ical;
pub struct IcalProperty<'a> {
- ptr: *mut ical::icalproperty,
+ pub ptr: *mut ical::icalproperty,
_parent: &'a dyn IcalComponent,
}
diff --git a/src/icalwrap/icalvcalendar.rs b/src/icalwrap/icalvcalendar.rs
index 6e2f538..930eb3a 100644
--- a/src/icalwrap/icalvcalendar.rs
+++ b/src/icalwrap/icalvcalendar.rs
@@ -6,6 +6,7 @@ use std::rc::Rc;
use super::IcalVEvent;
use super::IcalComponent;
use ical;
+use utils::dateutil;
pub struct IcalVCalendar {
comp: Rc<IcalComponentOwner>,
@@ -135,6 +136,18 @@ impl IcalVCalendar {
self
}
+ pub fn with_last_modified_now(self) -> Self {
+ let event = self.get_principal_event();
+ unsafe {
+ let now = dateutil::now().timestamp();
+ let is_date = 0;
+ let now_icaltime = ical::icaltime_from_timet_with_zone(now, is_date, ical::icaltimezone_get_utc_timezone());
+ let prop = event.get_property_by_name("LAST-MODIFIED").unwrap();
+ ical::icalproperty_set_lastmodified(prop.ptr, now_icaltime);
+ }
+ self
+ }
+
pub fn with_remove_property(self, property_name: &str) -> (Self, usize) {
let property_kind = unsafe {
let c_str = CString::new(property_name).unwrap();
@@ -408,6 +421,16 @@ mod tests {
}
#[test]
+ fn test_with_last_modified_now() {
+ let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY_LASTMODIFIED, None).unwrap();
+
+ let new_cal = cal.with_last_modified_now();
+
+ let event = new_cal.get_principal_event();
+ assert_eq!("20130101T010203Z", event.get_property_by_name("LAST-MODIFIED").unwrap().get_value());
+ }
+
+ #[test]
fn test_with_internal_timestamp() {
let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();