aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan2018-12-10 15:30:03 +0100
committerRuben Pollan2018-12-10 15:32:51 +0100
commit0afdb0b34eeefff033819f4f0930c960af8e17f8 (patch)
treecfe11590fa58fd8dc897dc4f58546093b5cb282d
parentbaeba8f78097fe13183c71a04355b78b0fdd0920 (diff)
Implement PartialOrd for dates and events
Diffstat (limited to '')
-rw-r--r--src/calendar.rs2
-rw-r--r--src/date.rs8
-rw-r--r--src/event.rs8
3 files changed, 15 insertions, 3 deletions
diff --git a/src/calendar.rs b/src/calendar.rs
index fcec54e..a46795b 100644
--- a/src/calendar.rs
+++ b/src/calendar.rs
@@ -58,7 +58,7 @@ impl Calendar {
}
}
- single.sort_by_key(|k| k.start);
+ single.sort();
Ok(Calendar { single, periodic })
}
diff --git a/src/date.rs b/src/date.rs
index 8d41c67..45a0c28 100644
--- a/src/date.rs
+++ b/src/date.rs
@@ -9,7 +9,7 @@ use chrono::offset::Utc;
use chrono_tz::{Tz, UTC};
-#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Date {
Time(chrono::DateTime<Tz>),
AllDay(chrono::Date<Tz>),
@@ -109,6 +109,12 @@ impl Ord for Date {
}
}
+impl PartialOrd for Date {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
impl Add<Duration> for Date {
type Output = Date;
diff --git a/src/event.rs b/src/event.rs
index e186cfd..2859ff8 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -8,7 +8,7 @@ use date::Date;
use errors::EventError;
-#[derive(Debug, Clone, PartialEq, PartialOrd, Eq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Event {
pub start: Date,
pub end: End,
@@ -82,6 +82,12 @@ impl Ord for Event {
}
}
+impl PartialOrd for Event {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
impl FromStr for Status {
type Err = EventError;