diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-01-18 23:14:25 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-01-18 23:14:25 +0100 |
commit | 390f419cb8043033ad85b9a0ded5617a6f25002a (patch) | |
tree | 2ef285bf09beb29269893b954c131296c729c84a /src/icalwrap | |
parent | 34483ee1270d84cb42a122965917916094855508 (diff) |
icalvcalendar: add property last-modified if it does not exist
Diffstat (limited to 'src/icalwrap')
-rw-r--r-- | src/icalwrap/icalvcalendar.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/icalwrap/icalvcalendar.rs b/src/icalwrap/icalvcalendar.rs index 930eb3a..3c00df4 100644 --- a/src/icalwrap/icalvcalendar.rs +++ b/src/icalwrap/icalvcalendar.rs @@ -142,8 +142,12 @@ impl IcalVCalendar { 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); + if let Some(prop) = event.get_property_by_name("LAST-MODIFIED") { + ical::icalproperty_set_lastmodified(prop.ptr, now_icaltime); + } else { + let prop_lastmod = ical::icalproperty_new_lastmodified(now_icaltime); + ical::icalcomponent_add_property(event.get_ptr(), prop_lastmod); + } } self } @@ -425,7 +429,15 @@ mod tests { 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_last_modified_now_added() { + let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, 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()); } |