diff options
author | Ben Boeckel <mathstuf@gmail.com> | 2020-04-08 23:18:49 -0400 |
---|---|---|
committer | Ben Boeckel <mathstuf@gmail.com> | 2020-04-09 10:32:32 -0400 |
commit | f08ee3c272ddf01b1025abb0c8a81fdd15a6bf52 (patch) | |
tree | 59fce98d78cdfd87075a44805a7afbc8441a2836 /src/icalendar.rs | |
parent | 4daf9712dda43cd0176400a6fcc89d948e43244d (diff) |
error: mark chrono parsing errors as an error source
Diffstat (limited to 'src/icalendar.rs')
-rw-r--r-- | src/icalendar.rs | 27 |
1 files changed, 12 insertions, 15 deletions
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)?, + }) } } |