Skip to content

Commit

Permalink
Add Eq and Ord for YearMonth + Eq for MonthDay
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Jan 21, 2025
1 parent 3a8f8c1 commit 328f3c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/month_day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{

/// The native Rust implementation of `Temporal.PlainMonthDay`
#[non_exhaustive]
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct PlainMonthDay {
pub iso: IsoDate,
calendar: Calendar,
Expand Down
14 changes: 13 additions & 1 deletion src/components/year_month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::{Duration, PartialDate};

/// The native Rust implementation of `Temporal.YearMonth`.
#[non_exhaustive]
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct PlainYearMonth {
pub(crate) iso: IsoDate,
calendar: Calendar,
Expand All @@ -30,6 +30,18 @@ impl core::fmt::Display for PlainYearMonth {
}
}

impl Ord for PlainYearMonth {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.iso.cmp(&other.iso)
}
}

impl PartialOrd for PlainYearMonth {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl PlainYearMonth {
/// Creates an unvalidated `YearMonth`.
#[inline]
Expand Down

0 comments on commit 328f3c0

Please sign in to comment.