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

DTF calendar handling #6350

Closed
wants to merge 3 commits into from
Closed

Conversation

robertbastian
Copy link
Member

No description provided.

@robertbastian robertbastian force-pushed the cals branch 2 times, most recently from 94ab4e8 to e7f9c0f Compare March 25, 2025 18:12
@robertbastian robertbastian force-pushed the cals branch 3 times, most recently from 010a326 to cb96117 Compare March 25, 2025 18:57
_ => prefs.calendar_algorithm = None,
}
let kind = AnyCalendarKind::new((&prefs).into());
// AnyCalendarKind constructor should not select an unsupported fallback
Copy link
Member Author

Choose a reason for hiding this comment

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

this is unfortunate

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, a way to fix this would be for icu_calendar to export an enum LocaleDefaultCalendarKind which we can exhaustively match over here. But this is fine. I do prefer for this to be a debug_assert instead of an assert.

@robertbastian robertbastian marked this pull request as ready for review March 25, 2025 19:15
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Best so far

_ => prefs.calendar_algorithm = None,
}
let kind = AnyCalendarKind::new((&prefs).into());
// AnyCalendarKind constructor should not select an unsupported fallback
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, a way to fix this would be for icu_calendar to export an enum LocaleDefaultCalendarKind which we can exhaustively match over here. But this is fine. I do prefer for this to be a debug_assert instead of an assert.

DataError::custom("Don't know how to load data for specified calendar")
.with_debug_context(&self.kind),
),
_ => unreachable!(),
Copy link
Member

Choose a reason for hiding this comment

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

Issue: I won't approve this with a panic. It is not a panic that the compiler can easily eliminate.

Copy link
Member

Choose a reason for hiding this comment

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

I fixed this in #6352

kind: AnyCalendarKind,
_helper: PhantomData<H>,
}

impl<H, P> AnyCalendarProvider<H, P> {
pub(crate) fn new(provider: P, kind: AnyCalendarKind) -> Self {
pub(crate) fn new_unchecked(provider: P, kind: AnyCalendarKind) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: you could make this try_new -> Option<Self> and do the match in here. Less coding at a distance. I don't really like having a match in the middle of neo.rs which is supposed to be a thin API wrapper file.

Copy link
Member

Choose a reason for hiding this comment

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

I did this in a different way in #6352

AnyCalendarKind::Buddhist
} else if region == Some(region!("AF")) || region == Some(region!("IR")) {
AnyCalendarKind::Persian
} else if region == Some(region!("SA")) && algo == Some(CalendarAlgorithm::Hijri(None)) {
Copy link
Member

Choose a reason for hiding this comment

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

thought: still unhappy with us treating -u-ca-islamic as a "none islamic" calendar; we don't do that for any other category of calendar, and it's mostly a meaningless code

But it's fine for now, we also need ICU4C compatability.

| CalendarAlgorithm::Ethiopic
| CalendarAlgorithm::Gregory
| CalendarAlgorithm::Hebrew
| CalendarAlgorithm::Hijri(_)
Copy link
Member

Choose a reason for hiding this comment

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

thought: oh, huh, because the formatter doesn't distinguish between islamic calendars we don't actually need to selectively support specific ones. clever.

@@ -591,6 +591,8 @@ pub struct FixedCalendarDateTimeNames<C, FSet: DateTimeNamesMarker = CompositeDa
#[derive(Debug, Clone)]
pub struct DateTimeNames<FSet: DateTimeNamesMarker> {
inner: FixedCalendarDateTimeNames<(), FSet>,
// calendar.kind() is one of Buddhist, Chinese, Coptic, Dangi, Ethiopian, EthiopianAmeteAlem, Gregorian, Hebrew, Indian,
Copy link
Member

Choose a reason for hiding this comment

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

suggestion (nb): should we also have a method on CalendarKind called is_core_supported() or something like that?

Copy link
Member

Choose a reason for hiding this comment

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

I fixed this in #6352

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 specifically don't want icu_calendar to define any sets for icu_datetime

@sffc
Copy link
Member

sffc commented Mar 26, 2025

I made a new PR incorporating this one: #6352

@robertbastian robertbastian deleted the cals branch March 26, 2025 10:34
sffc added a commit that referenced this pull request Mar 26, 2025
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