Skip to content

Commit 328f3c0

Browse files
committed
Add Eq and Ord for YearMonth + Eq for MonthDay
1 parent 3a8f8c1 commit 328f3c0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/components/month_day.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515

1616
/// The native Rust implementation of `Temporal.PlainMonthDay`
1717
#[non_exhaustive]
18-
#[derive(Debug, Default, Clone)]
18+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
1919
pub struct PlainMonthDay {
2020
pub iso: IsoDate,
2121
calendar: Calendar,

src/components/year_month.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::{Duration, PartialDate};
1818

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

33+
impl Ord for PlainYearMonth {
34+
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
35+
self.iso.cmp(&other.iso)
36+
}
37+
}
38+
39+
impl PartialOrd for PlainYearMonth {
40+
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
41+
Some(self.cmp(other))
42+
}
43+
}
44+
3345
impl PlainYearMonth {
3446
/// Creates an unvalidated `YearMonth`.
3547
#[inline]

0 commit comments

Comments
 (0)