summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-10-06 17:22:15 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-06 17:22:15 +0200
commit64bc256d31d64230d40330600432a0ac5708dac8 (patch)
tree28ce7192b8050ac374f03f4e7cb262ade26f6f27
parent7a6a142756a72c8bfc2a7f48253691e8a8d8fb54 (diff)
Add helper trait for generating instances of Dtend/start/stampwriteabletmpcreate-dtstartendstamp
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/icalendar.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/icalendar.rs b/src/icalendar.rs
index c49e193..66933f9 100644
--- a/src/icalendar.rs
+++ b/src/icalendar.rs
@@ -164,6 +164,11 @@ pub trait AsDateTime {
}
#[cfg(feature = "timeconversions")]
+pub trait FromDateTime : Sized {
+ fn from_datetime(NaiveDateTime) -> Self;
+}
+
+#[cfg(feature = "timeconversions")]
impl AsDateTime for Dtend {
fn as_datetime(&self) -> Result<Time> {
@@ -178,6 +183,13 @@ impl AsDateTime for Dtend {
}
#[cfg(feature = "timeconversions")]
+impl FromDateTime for Dtend {
+ fn from_datetime(ndt: NaiveDateTime) -> Self {
+ Dtend(ndt.format(DATE_TIME_FMT).to_string(), BTreeMap::default())
+ }
+}
+
+#[cfg(feature = "timeconversions")]
impl AsDateTime for Dtstart {
fn as_datetime(&self) -> Result<Time> {
@@ -192,6 +204,13 @@ impl AsDateTime for Dtstart {
}
#[cfg(feature = "timeconversions")]
+impl FromDateTime for Dtstart {
+ fn from_datetime(ndt: NaiveDateTime) -> Self {
+ Dtstart(ndt.format(DATE_TIME_FMT).to_string(), BTreeMap::default())
+ }
+}
+
+#[cfg(feature = "timeconversions")]
impl AsDateTime for Dtstamp {
fn as_datetime(&self) -> Result<Time> {
@@ -205,6 +224,13 @@ impl AsDateTime for Dtstamp {
}
+#[cfg(feature = "timeconversions")]
+impl FromDateTime for Dtstamp {
+ fn from_datetime(ndt: NaiveDateTime) -> Self {
+ Dtstamp(ndt.format(DATE_TIME_FMT).to_string(), BTreeMap::default())
+ }
+}
+
#[derive(Clone, Debug)]
pub struct EventBuilder(Component);