aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Pollan2018-04-29 12:33:33 +0200
committerRuben Pollan2018-04-29 12:33:33 +0200
commit0c323ddc25f97bd36d60a78e938337d0ccdfc1db (patch)
treea440a0f4f5cf12a8d3aae0d49f3121a8abf61d2b /src
parent7fb600005e7f233970a613a7babcd7cca32da9e3 (diff)
Add status to event
Diffstat (limited to 'src')
-rw-r--r--src/ics.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ics.rs b/src/ics.rs
index 1ec9417..c357efe 100644
--- a/src/ics.rs
+++ b/src/ics.rs
@@ -21,12 +21,20 @@ pub enum Date {
}
#[derive(Debug)]
+pub enum Status {
+ Confirmed,
+ Tentative,
+ Canceled,
+}
+
+#[derive(Debug)]
pub struct Event {
pub start: Date,
pub end: Date,
pub summary: String,
pub location: String,
pub description: String,
+ pub status: Status,
}
pub fn parse<P: AsRef<Path>>(ics: P) -> Result<Vec<Event>, IcsError> {
@@ -51,6 +59,7 @@ pub fn parse<P: AsRef<Path>>(ics: P) -> Result<Vec<Event>, 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<Self, Self::Err> {
+ match s {
+ "CONFIRMED" => Ok(Status::Confirmed),
+ "TENTATIVE" => Ok(Status::Tentative),
+ "CANCELED" => Ok(Status::Canceled),
+ _ => Err(IcsError::StatusError),
+ }
+ }
+}
+
fn cmp_date_time<T: TimeZone>(date: &chrono::Date<T>, time: &DateTime<T>) -> 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<io::Error> for IcsError {