diff options
-rw-r--r-- | src/icalendar.rs | 26 |
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); |