diff options
author | Ruben Pollan | 2018-04-29 20:10:43 +0200 |
---|---|---|
committer | Ruben Pollan | 2018-04-29 20:10:43 +0200 |
commit | 26ddc4889560ea1e63e7fec674fbd87bb394acfb (patch) | |
tree | bb5c0d00bc4827c8be5c4a1c376f6e7421dadb11 /src/ics.rs | |
parent | 7a90f7f4cdfc53b65d30df806de0a26ca6b86b8c (diff) |
Add Events type
Diffstat (limited to 'src/ics.rs')
-rw-r--r-- | src/ics.rs | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/src/ics.rs b/src/ics.rs deleted file mode 100644 index 0726ba1..0000000 --- a/src/ics.rs +++ /dev/null @@ -1,73 +0,0 @@ -use std::io; -use std::io::BufReader; -use std::fs::File; -use std::path::Path; -use std::num::ParseIntError; - -use ical::parser; -use ical::IcalParser; - -use event::{Event, Date}; - - -pub fn parse<P: AsRef<Path>>(ics: P) -> Result<Vec<Event>, IcsError> { - let buf = BufReader::new(File::open(ics)?); - let reader = IcalParser::new(buf); - let mut events = Vec::new(); - - for line in reader { - for ev in line?.events { - let mut event = Event::new(); - for property in ev.properties { - let value = property.value.unwrap_or("".to_string()); - let mut time_zone = "".to_string(); - - for (param, value) in property.params.unwrap_or(vec![]) { - if param == "TZID" && value.len() > 0 { - time_zone = value[0].clone(); - } - } - - match property.name.as_ref() { - "SUMMARY" => event.summary = value, - "LOCATION" => event.location = value, - "DESCRIPTION" => event.description = value, - "STATUS" => event.status = value.parse()?, - "DTSTART" => event.start = Date::parse(value, time_zone)?, - "DTEND" => event.end = Date::parse(value, time_zone)?, - _ => (), - }; - } - events.push(event); - } - } - - events.sort_by(|a, b| a.start.cmp(&b.start)); - Ok(events) -} - -#[derive(Debug)] -pub enum IcsError { - IoError(io::Error), - IcalError(parser::errors::Error), - IntError(ParseIntError), - StatusError, -} - -impl From<io::Error> for IcsError { - fn from(err: io::Error) -> IcsError { - IcsError::IoError(err) - } -} - -impl From<parser::errors::Error> for IcsError { - fn from(err: parser::errors::Error) -> IcsError { - IcsError::IcalError(err) - } -} - -impl From<ParseIntError> for IcsError { - fn from(err: ParseIntError) -> IcsError { - IcsError::IntError(err) - } -} |