diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-01-20 12:14:59 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-01-20 16:27:40 +0100 |
commit | 16f95ae751e3c96f3f4f335139ab07ab8234f1e6 (patch) | |
tree | d01b2aeded379d579f6da2860b9d090bbe025c4f /src/icalwrap | |
parent | 5ae5ad66abead9a4bd34a8c57a862cb60a913d77 (diff) |
icaltime: add Display trait
Diffstat (limited to 'src/icalwrap')
-rw-r--r-- | src/icalwrap/icaltime.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/icalwrap/icaltime.rs b/src/icalwrap/icaltime.rs index c30d7f9..3f6da8d 100644 --- a/src/icalwrap/icaltime.rs +++ b/src/icalwrap/icaltime.rs @@ -1,8 +1,10 @@ use std::ops::Deref; +use std::ffi::CStr; use chrono::prelude::*; use ical; use utils::dateutil; use super::IcalTimeZone; +use std::fmt::{Error,Display,Formatter}; pub struct IcalTime { time: ical::icaltimetype, @@ -22,6 +24,16 @@ impl Deref for IcalTime { } } +impl Display for IcalTime { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { + let cstr = unsafe { + CStr::from_ptr(ical::icaltime_as_ical_string(self.time)) + }; + let string = cstr.to_string_lossy().into_owned(); + write!(f, "{}", string) + } +} + impl<T: Into<IcalTime> + Clone> From<&T> for IcalTime { fn from(time: &T) -> IcalTime { time.clone().into() |