aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/calendar.rs2
-rw-r--r--src/event.rs18
2 files changed, 16 insertions, 4 deletions
diff --git a/src/calendar.rs b/src/calendar.rs
index a835480..6df2f74 100644
--- a/src/calendar.rs
+++ b/src/calendar.rs
@@ -71,7 +71,7 @@ impl Calendar {
.collect();
events.append(&mut p_events);
}
- events.sort_by_key(|k| k.start);
+ events.sort();
events
}
}
diff --git a/src/event.rs b/src/event.rs
index db32b22..b5e9d27 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -1,3 +1,4 @@
+use std::cmp::{Ordering, Ord};
use std::fmt;
use std::str::FromStr;
@@ -7,7 +8,7 @@ use date::Date;
use errors::EventError;
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq, PartialOrd, Eq)]
pub struct Event {
pub start: Date,
pub end: End,
@@ -17,14 +18,14 @@ pub struct Event {
pub status: Status,
}
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq)]
pub enum Status {
Confirmed,
Tentative,
Canceled,
}
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq)]
pub enum End {
Date(Date),
Duration(Duration),
@@ -70,6 +71,17 @@ impl fmt::Display for Event {
}
}
+impl Ord for Event {
+ fn cmp(&self, other: &Self) -> Ordering {
+ let ord = self.start.cmp(&other.start);
+ if ord == Ordering::Equal {
+ self.end_date().cmp(&other.end_date())
+ } else {
+ ord
+ }
+ }
+}
+
impl FromStr for Status {
type Err = EventError;