From 0afdb0b34eeefff033819f4f0930c960af8e17f8 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 10 Dec 2018 15:30:03 +0100 Subject: Implement PartialOrd for dates and events --- src/calendar.rs | 2 +- src/date.rs | 8 +++++++- src/event.rs | 8 +++++++- 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), AllDay(chrono::Date), @@ -109,6 +109,12 @@ impl Ord for Date { } } +impl PartialOrd for Date { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + impl Add 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 { + Some(self.cmp(other)) + } +} + impl FromStr for Status { type Err = EventError; -- cgit v1.2.3