From 63f32ab461f7264628fd4c58d5db4b1a7a3f9b2a Mon Sep 17 00:00:00 2001 From: puripuri2100 Date: Thu, 9 May 2024 14:40:58 +0900 Subject: [PATCH] add ord trait for date --- jplaw_data_types/src/law.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/jplaw_data_types/src/law.rs b/jplaw_data_types/src/law.rs index e13cf05..526503a 100644 --- a/jplaw_data_types/src/law.rs +++ b/jplaw_data_types/src/law.rs @@ -63,6 +63,20 @@ impl Date { } } +impl PartialOrd for Date { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Date { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + let s = self.get_ad() * 10000 + self.month.unwrap_or(0) * 100 + self.day.unwrap_or(0); + let o = other.get_ad() * 10000 + other.month.unwrap_or(0) * 100 + other.day.unwrap_or(0); + s.cmp(&o) + } +} + /// 法律の立法の種類 #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] pub enum RippouType {