summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHendrik Sollich <hendrik@hoodie.de>2016-11-11 23:29:27 +0100
committerHendrik Sollich <hendrik@hoodie.de>2016-11-11 23:29:27 +0100
commitff7df7f8b735dce2eda541298d2ab9a6eba25f22 (patch)
treea89bf6b1043638aa77f985914c38265c72c85ef4 /src
parent4ed3dffa2fc4fc2a3c1f263e00620f769b35411f (diff)
supporting date only start/end
Diffstat (limited to 'src')
-rw-r--r--src/components.rs30
-rw-r--r--src/lib.rs4
-rw-r--r--src/properties.rs15
3 files changed, 39 insertions, 10 deletions
diff --git a/src/components.rs b/src/components.rs
index 640c4e4..8f6e1a8 100644
--- a/src/components.rs
+++ b/src/components.rs
@@ -73,13 +73,17 @@ pub trait Component {
out_string
}
+ /// Append a given `Property`
fn append_property(&mut self, property: Property) -> &mut Self;
+ /// Construct and append a `Property`
fn add_property(&mut self, key: &str, val: &str) -> &mut Self {
self.append_property( Property::new(key, val));
self
}
+
+ /// Set the DTSTART `Property`
fn starts<TZ:TimeZone>(&mut self, dt: DateTime<TZ>) -> &mut Self
where TZ::Offset: fmt::Display
{
@@ -88,6 +92,7 @@ pub trait Component {
self
}
+ /// Set the DTEND `Property`
fn ends<TZ:TimeZone>(&mut self, dt: DateTime<TZ>) -> &mut Self
where TZ::Offset: fmt::Display
{
@@ -95,6 +100,31 @@ pub trait Component {
self
}
+ /// Set the DTSTART `Property`, date only
+ fn start_date<TZ:TimeZone>(&mut self, date: Date<TZ>) -> &mut Self
+ where TZ::Offset: fmt::Display
+ {
+ // DTSTART
+ self.append_property(
+ Property::new("DTSTART", date.format("%Y%m%d").to_string().as_ref())
+ .parameter("VALUE", "DATE")
+ .done());
+ self
+ }
+
+ /// Set the DTEND `Property`, date only
+ fn end_date<TZ:TimeZone>(&mut self, date: Date<TZ>) -> &mut Self
+ where TZ::Offset: fmt::Display
+ {
+ // DTSTART
+ self.append_property(
+ Property::new("DTEND", date.format("%Y%m%d").to_string().as_ref())
+ .parameter("VALUE", "DATE")
+ .done());
+ self
+ }
+
+
/// Prints to stdout
fn print(&self) -> Result<(), fmt::Error> {
let mut out = String::new();
diff --git a/src/lib.rs b/src/lib.rs
index 86a3d65..5a5977c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,8 +2,6 @@
//! This is still just an early idea, there is nothing implemented,
//! I haven't even read the [spec](http://tools.ietf.org/html/rfc5545) yet.
//!
-//! I'd love to create iCal files with a very [diesel](https://diesel.rs/) or [active support](https://github.com/wycats/rust-activesupport) like syntax.
-//!
//! ## Structure
//! * `Calendar`s consist of `Components`
//! * `Component`s are e.g. `Event` or `Todo`
@@ -22,7 +20,7 @@ mod properties;
mod calendar;
pub mod repeats;
-//pub use components::{Property, Parameter, Component};
+pub use properties::{Property, Parameter};
//pub use components::{event, todo};
pub use components::{Event, Todo, Component};
pub use properties::Class;
diff --git a/src/properties.rs b/src/properties.rs
index ce061f4..c934018 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -1,5 +1,6 @@
use std::fmt;
use std::mem;
+use std::collections::HashMap;
#[derive(Debug)]
/// key-value pairs inside of `Property`s
@@ -17,8 +18,8 @@ impl Parameter {
}
}
-type EntryParameters = Vec<Parameter>;
-// type EntryParameters = HashMap<EPKey,String>;
+//type EntryParameters = Vec<Parameter>;
+type EntryParameters = HashMap<String,Parameter>;
#[derive(Debug)]
/// key-value pairs inside of `Component`s
@@ -34,7 +35,7 @@ impl Property {
Property {
key: key.to_owned(),
value: val.replace('\n', "\\n"),
- parameters: Vec::new(),
+ parameters: HashMap::new(),
}
}
@@ -45,7 +46,7 @@ impl Property {
/// Builder method, adds a new `Parameter`
pub fn parameter(&mut self, key: &str, val: &str) -> &mut Self {
- self.parameters.push(Parameter::new(key, val));
+ self.parameters.insert(key.to_owned(),Parameter::new(key, val));
self
}
@@ -54,14 +55,14 @@ impl Property {
Property {
key: mem::replace(&mut self.key, String::new()),
value: mem::replace(&mut self.value, String::new()),
- parameters: mem::replace(&mut self.parameters, Vec::new()),
+ parameters: mem::replace(&mut self.parameters, HashMap::new()),
}
}
/// Writes this Property to `out`
pub fn fmt_write<W: fmt::Write>(&self, out: &mut W) -> Result<(), fmt::Error> {
try!(write!(out, "{}", self.key));
- for &Parameter { ref key, ref value } in &self.parameters {
+ for (_key, &Parameter { ref key, ref value }) in &self.parameters {
try!(write!(out, ";{}={}", key, value));
}
try!(writeln!(out, ":{}", self.value));
@@ -84,7 +85,7 @@ impl Into<Property> for Class {
Class::Private => "PRIVATE",
Class::Confidential => "CONFIDENTIAL",
}),
- parameters: Vec::new()
+ parameters: HashMap::new()
}
}
}