Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ord and PartialOrd to icu_calendar types #3468

Merged
merged 1 commit into from
Jun 1, 2023
Merged

Conversation

sffc
Copy link
Member

@sffc sffc commented May 31, 2023

Needed for #2703

@sffc sffc requested a review from Manishearth as a code owner May 31, 2023 22:31
@sffc sffc requested a review from echeran May 31, 2023 22:43
@@ -92,7 +92,7 @@ pub enum AnyCalendar {
}

/// The inner date type for [`AnyCalendar`]
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this does Self::Gregorian(x) < Self::Buddhist(y)? This will make Date<AnyCalendar> ordered non-chronologically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah I guess it will put all Gregorian before all Buddhist. I can leave this out for now. I'll make a follow-up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fairly straightforward to implement this manually, as all calendars can convert to ISO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll include this in my follow-up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is not as straightforward as it initially seems, because the calendars have different ranges. We can't convert them to fixed_date (number of days since 0000-1-1) because fixed_date is an i32, but the calendar objects support dates outside that range; a calendar with a year field of i32::MAX can't necessarily be converted to another one. (@sotam1069 is working on finding these edge cases and making sure they are at least covered in unit tests)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need Ord?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -7,7 +7,7 @@ use core::convert::TryInto;
use core::marker::PhantomData;
use tinystr::tinystr;

#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would ask you not to make this require C: PartialOrd + Ord, but I guess that ship has sailed with Hash, Eq, PartialEq.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on both counts.

Copy link
Contributor

@echeran echeran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sffc sffc merged commit 85ff0ae into unicode-org:main Jun 1, 2023
@sffc sffc mentioned this pull request Jun 1, 2023
@sffc sffc removed the request for review from Manishearth June 1, 2023 01:45
@sffc sffc deleted the ord branch June 1, 2023 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants