From 0c323ddc25f97bd36d60a78e938337d0ccdfc1db Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Sun, 29 Apr 2018 12:33:33 +0200 Subject: Add status to event --- src/ics.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/ics.rs') diff --git a/src/ics.rs b/src/ics.rs index 1ec9417..c357efe 100644 --- a/src/ics.rs +++ b/src/ics.rs @@ -20,6 +20,13 @@ pub enum Date { AllDay(chrono::Date), } +#[derive(Debug)] +pub enum Status { + Confirmed, + Tentative, + Canceled, +} + #[derive(Debug)] pub struct Event { pub start: Date, @@ -27,6 +34,7 @@ pub struct Event { pub summary: String, pub location: String, pub description: String, + pub status: Status, } pub fn parse>(ics: P) -> Result, IcsError> { @@ -51,6 +59,7 @@ pub fn parse>(ics: P) -> Result, IcsError> { "SUMMARY" => event.summary = value, "LOCATION" => event.location = value, "DESCRIPTION" => event.description = value, + "STATUS" => event.status = Status::from_str(&value)?, "DTSTART" => event.start = parse_date(value, time_zone)?, "DTEND" => event.end = parse_date(value, time_zone)?, _ => (), @@ -93,6 +102,7 @@ impl Event { summary: "".to_string(), location: "".to_string(), description: "".to_string(), + status: Status::Confirmed, start: Date::Time(UTC.timestamp(0, 0)), end: Date::Time(UTC.timestamp(0, 0)), }; @@ -131,6 +141,19 @@ impl Date { } } +impl FromStr for Status { + type Err = IcsError; + + fn from_str(s: &str) -> Result { + match s { + "CONFIRMED" => Ok(Status::Confirmed), + "TENTATIVE" => Ok(Status::Tentative), + "CANCELED" => Ok(Status::Canceled), + _ => Err(IcsError::StatusError), + } + } +} + fn cmp_date_time(date: &chrono::Date, time: &DateTime) -> Ordering { let d2 = time.date(); if date.eq(&d2) { @@ -144,6 +167,7 @@ pub enum IcsError { IoError(io::Error), IcalError(parser::errors::Error), IntError(ParseIntError), + StatusError, } impl From for IcsError { -- cgit v1.2.3