summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml1
-rw-r--r--src/icalwrap/icalproperty.rs2
-rw-r--r--src/icalwrap/icalvcalendar.rs23
-rw-r--r--src/lib.rs3
-rw-r--r--src/testdata.rs5
-rw-r--r--src/utils/dateutil.rs11
7 files changed, 45 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3ece256..118f43c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -293,6 +293,7 @@ dependencies = [
"fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"indoc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
"libical-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 050bf28..262e0a9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ serde_derive = "1.0.82"
tempfile = "3.0.5"
uuid = { version = "0.7", features = ["v4"] }
fs2 = "0.4.3"
+lazy_static = "1.2.0"
[dev-dependencies]
assert_fs = "0.10.1"
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();
diff --git a/src/lib.rs b/src/lib.rs
index cca57a9..13d6a5a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -47,3 +47,6 @@ extern crate log;
#[macro_use]
extern crate indoc;
+
+#[macro_use]
+extern crate lazy_static;
diff --git a/src/testdata.rs b/src/testdata.rs
index 70ccf9a..7e5dbfa 100644
--- a/src/testdata.rs
+++ b/src/testdata.rs
@@ -227,6 +227,11 @@ pub static TEST_EVENT_WITH_X_LIC_ERROR: &str = indoc!("
END:VCALENDAR
");
+use chrono::{Utc,DateTime,TimeZone};
+lazy_static! {
+ pub static ref now_test: DateTime<Utc> = Utc.ymd(2013, 01, 01).and_hms(1, 2, 3);
+}
+
#[cfg(test)]
use std::sync::{Once, ONCE_INIT};
#[cfg(test)]
diff --git a/src/utils/dateutil.rs b/src/utils/dateutil.rs
index 1272834..7b7c1dc 100644
--- a/src/utils/dateutil.rs
+++ b/src/utils/dateutil.rs
@@ -22,6 +22,17 @@ pub fn week_from_str_begin(date_str: &str) -> Result<Date<Local>,String> {
Err("Could not parse '{}' as week".to_string())
}
+#[cfg(not(test))]
+pub fn now() -> DateTime<Utc> {
+ Utc::now()
+}
+
+#[cfg(test)]
+pub fn now() -> DateTime<Utc> {
+ use testdata;
+ *testdata::now_test
+}
+
pub fn week_from_str_end(date_str: &str) -> Result<Date<Local>,String> {
let now = Local::now();
if date_str == "toweek" || date_str == "thisweek" {