Skip to content

Commit

Permalink
Add PartialOrd derivation for Month
Browse files Browse the repository at this point in the history
Also add a few tests to make sure it behaves as expected.
  • Loading branch information
Munksgaard committed Mar 24, 2023
1 parent 2fcdd9e commit 578f265
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::OutOfRange;
/// 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 = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum Month {
Expand Down Expand Up @@ -334,4 +334,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);
}
}

0 comments on commit 578f265

Please sign in to comment.