diff options
-rw-r--r-- | src/error.rs | 7 | ||||
-rw-r--r-- | src/icalendar.rs | 27 |
2 files changed, 17 insertions, 17 deletions
diff --git a/src/error.rs b/src/error.rs index 13c268d..4c48e50 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,8 +17,11 @@ pub enum VObjectErrorKind { NotAnICalendar(String), #[cfg(feature = "timeconversions")] - #[error("{}", _0)] - ChronoError(::chrono::format::ParseError), + #[error("failed to parse time")] + ChronoError { + #[from] + source: chrono::format::ParseError, + }, } pub(crate) type VObjectResult<T> = Result<T, VObjectErrorKind>; diff --git a/src/icalendar.rs b/src/icalendar.rs index 4863029..6a5fea2 100644 --- a/src/icalendar.rs +++ b/src/icalendar.rs @@ -166,12 +166,11 @@ pub trait AsDateTime { impl AsDateTime for Dtend { fn as_datetime(&self) -> VObjectResult<Time> { - match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { - Ok(dt) => Ok(Time::DateTime(dt)), + Ok(match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { + Ok(dt) => Time::DateTime(dt), Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT) - .map(Time::Date) - .map_err(VObjectErrorKind::ChronoError), - } + .map(Time::Date)?, + }) } } @@ -180,12 +179,11 @@ impl AsDateTime for Dtend { impl AsDateTime for Dtstart { fn as_datetime(&self) -> VObjectResult<Time> { - match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { - Ok(dt) => Ok(Time::DateTime(dt)), + Ok(match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { + Ok(dt) => Time::DateTime(dt), Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT) - .map(Time::Date) - .map_err(VObjectErrorKind::ChronoError), - } + .map(Time::Date)?, + }) } } @@ -194,12 +192,11 @@ impl AsDateTime for Dtstart { impl AsDateTime for Dtstamp { fn as_datetime(&self) -> VObjectResult<Time> { - match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { - Ok(dt) => Ok(Time::DateTime(dt)), + Ok(match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { + Ok(dt) => Time::DateTime(dt), Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT) - .map(Time::Date) - .map_err(VObjectErrorKind::ChronoError), - } + .map(Time::Date)?, + }) } } |