summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Laitl <matej@laitl.cz>2019-03-07 18:46:53 +0100
committerMatěj Laitl <matej@laitl.cz>2019-03-07 18:46:53 +0100
commit80ab26aadad2997b1cfc48bd9b580f0be1ac02ec (patch)
tree150355c084a185f354bfad1aef9fcaa97e9d8db7
parent95df4e92cccc4c7cc52a03cf0ef81824251b9c05 (diff)
Component serialization: write DTSTAMP only if not already present
Without this, DTSTAMP would be written twice if it was already a property. Also simplify related code to use <map>.contains_key(). Relates to #7.
-rw-r--r--src/components.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/components.rs b/src/components.rs
index 7139e4b..d8f6c8e 100644
--- a/src/components.rs
+++ b/src/components.rs
@@ -127,14 +127,17 @@ pub trait Component {
fn fmt_write<W: fmt::Write>(&self, out: &mut W) -> Result<(), fmt::Error> {
write_crlf!(out, "BEGIN:{}", Self::component_kind())?;
- let now = Local::now().format("%Y%m%dT%H%M%S");
- write_crlf!(out, "DTSTAMP:{}", now)?;
+
+ if !self.properties().contains_key("DTSTAMP") {
+ let now = Local::now().format("%Y%m%dT%H%M%S");
+ write_crlf!(out, "DTSTAMP:{}", now)?;
+ }
for property in self.properties().values() {
property.fmt_write(out)?;
}
- if !self.properties().keys().any(|key| key == "UID") {
+ if !self.properties().contains_key("UID") {
write_crlf!(out, "UID:{}", Uuid::new_v4())?;
}