From 4e2c2b4ad23d6822445718ee536b45d5d649040f Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Fri, 24 Mar 2023 15:48:11 +0100 Subject: [PATCH] Add PartialOrd derivation for Month Also add a few tests to make sure it behaves as expected. --- src/month.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/month.rs b/src/month.rs index 46f09d0fb8..944b276037 100644 --- a/src/month.rs +++ b/src/month.rs @@ -27,7 +27,7 @@ use rkyv::{Archive, Deserialize, Serialize}; /// Allows mapping from and to month, from 1-January to 12-December. /// Can be Serialized/Deserialized with serde // Actual implementation is zero-indexed, API intended as 1-indexed for more intuitive behavior. -#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd)] #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))] #[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] @@ -352,4 +352,13 @@ mod tests { assert_eq!(Month::January.pred(), Month::December); assert_eq!(Month::February.pred(), Month::January); } + + #[test] + fn test_month_partial_ord() { + assert!(Month::January <= Month::January); + assert!(Month::January < Month::February); + assert!(Month::January < Month::December); + assert!(Month::July >= Month::May); + assert!(Month::September > Month::March); + } }