Skip to content

Conversation

@robertbastian
Copy link
Member

@robertbastian robertbastian commented Dec 5, 2025

We should stop treating the ISO calendar as special. Conversions are available through to_calendar() like for all other calendars, and there shouldn't be two ways of doing things.

This also cleans up old code in AnyCalendar that converts through ISO, which skips the optimisations in .to_calendar().

@robertbastian robertbastian force-pushed the date-api branch 2 times, most recently from 3e7b3b1 to 0887c4b Compare December 5, 2025 19:02
@robertbastian robertbastian changed the title Date api Deprecate Date::new_from_iso/Date::to_iso Dec 5, 2025
@robertbastian robertbastian force-pushed the date-api branch 2 times, most recently from eecd247 to 940b36f Compare December 8, 2025 17:07
@robertbastian robertbastian marked this pull request as ready for review December 8, 2025 23:03
@robertbastian robertbastian requested a review from sffc December 8, 2025 23:03
let roc_from_case = Date::new_from_iso(iso_from_case, Roc);
assert_eq!(iso_from_rd, iso_from_case,
"ISO from RD not equal to ISO generated from manually-input ymd\nCase: {case:?}\nRD: {iso_from_rd:?}\nManual: {iso_from_case:?}");
let roc_from_case = Date::try_new_roc(
Copy link
Member

Choose a reason for hiding this comment

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

In this test, you removed the new_from_iso and now only create from the ROC dates and the RD.

Are we still satisfactorily covering the has_cheap_iso_conversion code path?

        let inner = if c1.has_cheap_iso_conversion() && c2.has_cheap_iso_conversion() {
            c2.from_iso(c1.to_iso(self.inner()))
        } else {
            // `from_rata_die` precondition is satified by `to_rata_die`
            c2.from_rata_die(c1.to_rata_die(self.inner()))
        };

Copy link
Member Author

Choose a reason for hiding this comment

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

there are a couple of tests that exercise this code, it's shared between all AbstractGregorian calendars, so we don't necessarily need to test it on Roc

it might make sense to add a few test specifically for this code in date.rs.

@robertbastian robertbastian requested a review from sffc December 8, 2025 23:33
fn test_to_calendar() {
let date = Date::try_new_gregorian(2025, 12, 9).unwrap();
// These conversions use the AbstractGregorian fast path
let date2 = date.to_calendar(Buddhist).to_calendar(Gregorian);
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: It seems better to test this for all calendars, not just Buddhist

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

Generally not a fan of churning the APIs here more but I guess it's fine.

@robertbastian robertbastian merged commit b752157 into unicode-org:main Dec 9, 2025
32 checks passed
@robertbastian robertbastian deleted the date-api branch December 9, 2025 09:21
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