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

Rename datetime format functions and traits #5847

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/datetime/src/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::raw::neo::*;
use crate::scaffold::*;
use crate::scaffold::{
AllInputMarkers, ConvertCalendar, DateDataMarkers, DateInputMarkers, DateTimeMarkers, GetField,
IsInCalendar, IsInFixedCalendar, TimeMarkers, TypedDateDataMarkers, ZoneMarkers,
InCalendar, InFixedCalendar, TimeMarkers, TypedDateDataMarkers, ZoneMarkers,
};
use crate::size_test_macro::size_test;
use crate::DateTimeWriteError;
Expand Down Expand Up @@ -330,7 +330,7 @@ where
/// ```
pub fn format<I>(&self, input: &I) -> FormattedDateTime
where
I: ?Sized + IsInFixedCalendar<C> + AllInputMarkers<FSet>,
I: ?Sized + InFixedCalendar<C> + AllInputMarkers<FSet>,
{
let input = ExtractedInput::extract_from_neo_input::<FSet::D, FSet::T, FSet::Z, I>(input);
FormattedDateTime {
Expand Down Expand Up @@ -563,7 +563,7 @@ where
datetime: &I,
) -> Result<FormattedDateTime, crate::MismatchedCalendarError>
where
I: ?Sized + IsInCalendar + AllInputMarkers<FSet>,
I: ?Sized + InCalendar + AllInputMarkers<FSet>,
Copy link
Member

Choose a reason for hiding this comment

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

optional: how about InSameCalendar to (a) make it more meaningful and (b) make it more parallel with InFixedCalendar?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Justification: the fully qualified names have good parallelism

  • DateTimeFormatter::format_same_calendar => InSameCalendar
  • FixedCalendarDateTimeFormatter::format => InFixedCalendar

Also, "InCalendar" is too short and could mean something else in the future.

{
datetime.check_any_calendar_kind(self.calendar.kind())?;
let datetime =
Expand Down
4 changes: 2 additions & 2 deletions components/datetime/src/pattern/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::format::datetime::try_write_pattern_items;
use crate::input::ExtractedInput;
use crate::scaffold::*;
use crate::scaffold::{
AllInputMarkers, DateInputMarkers, DateTimeMarkers, IsInFixedCalendar, TimeMarkers,
AllInputMarkers, DateInputMarkers, DateTimeMarkers, InFixedCalendar, TimeMarkers,
TypedDateDataMarkers, ZoneMarkers,
};
use crate::DateTimeWriteError;
Expand Down Expand Up @@ -195,7 +195,7 @@ where
/// ```
pub fn format<I>(&self, datetime: &I) -> FormattedDateTimePattern<'a>
where
I: ?Sized + IsInFixedCalendar<C> + AllInputMarkers<FSet>,
I: ?Sized + InFixedCalendar<C> + AllInputMarkers<FSet>,
{
FormattedDateTimePattern {
pattern: self.inner.pattern,
Expand Down
28 changes: 14 additions & 14 deletions components/datetime/src/scaffold/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl<O: TimeZoneModel> ConvertCalendar for TimeZoneInfo<O> {
}

/// An input that may be associated with a specific runtime calendar.
pub trait IsInCalendar {
pub trait InCalendar {
/// Checks whether this type is compatible with the given calendar.
///
/// Types that are agnostic to calendar systems should return `Ok(())`.
Expand All @@ -449,7 +449,7 @@ pub trait IsInCalendar {
) -> Result<(), MismatchedCalendarError>;
}

impl<C: Calendar, A: AsCalendar<Calendar = C>> IsInCalendar for Date<A> {
impl<C: Calendar, A: AsCalendar<Calendar = C>> InCalendar for Date<A> {
#[inline]
fn check_any_calendar_kind(
&self,
Expand All @@ -466,14 +466,14 @@ impl<C: Calendar, A: AsCalendar<Calendar = C>> IsInCalendar for Date<A> {
}
}

impl IsInCalendar for Time {
impl InCalendar for Time {
#[inline]
fn check_any_calendar_kind(&self, _: AnyCalendarKind) -> Result<(), MismatchedCalendarError> {
Ok(())
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>> IsInCalendar for DateTime<A> {
impl<C: Calendar, A: AsCalendar<Calendar = C>> InCalendar for DateTime<A> {
#[inline]
fn check_any_calendar_kind(
&self,
Expand All @@ -490,41 +490,41 @@ impl<C: Calendar, A: AsCalendar<Calendar = C>> IsInCalendar for DateTime<A> {
}
}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> IsInCalendar for CustomZonedDateTime<A, Z> {
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> InCalendar for CustomZonedDateTime<A, Z> {
#[inline]
fn check_any_calendar_kind(&self, _: AnyCalendarKind) -> Result<(), MismatchedCalendarError> {
Ok(())
}
}

impl IsInCalendar for UtcOffset {
impl InCalendar for UtcOffset {
#[inline]
fn check_any_calendar_kind(&self, _: AnyCalendarKind) -> Result<(), MismatchedCalendarError> {
Ok(())
}
}

impl<O: TimeZoneModel> IsInCalendar for TimeZoneInfo<O> {
impl<O: TimeZoneModel> InCalendar for TimeZoneInfo<O> {
#[inline]
fn check_any_calendar_kind(&self, _: AnyCalendarKind) -> Result<(), MismatchedCalendarError> {
Ok(())
}
}

/// An input associated with a fixed, static calendar.
pub trait IsInFixedCalendar<C> {}
pub trait InFixedCalendar<C> {}

impl<C: Calendar, A: AsCalendar<Calendar = C>> IsInFixedCalendar<C> for Date<A> {}
impl<C: Calendar, A: AsCalendar<Calendar = C>> InFixedCalendar<C> for Date<A> {}

impl<C> IsInFixedCalendar<C> for Time {}
impl<C> InFixedCalendar<C> for Time {}

impl<C: Calendar, A: AsCalendar<Calendar = C>> IsInFixedCalendar<C> for DateTime<A> {}
impl<C: Calendar, A: AsCalendar<Calendar = C>> InFixedCalendar<C> for DateTime<A> {}

impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> IsInFixedCalendar<C>
impl<C: Calendar, A: AsCalendar<Calendar = C>, Z> InFixedCalendar<C>
for CustomZonedDateTime<A, Z>
{
}

impl<C> IsInFixedCalendar<C> for UtcOffset {}
impl<C> InFixedCalendar<C> for UtcOffset {}

impl<C, O: TimeZoneModel> IsInFixedCalendar<C> for TimeZoneInfo<O> {}
impl<C, O: TimeZoneModel> InFixedCalendar<C> for TimeZoneInfo<O> {}
4 changes: 2 additions & 2 deletions components/datetime/src/scaffold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub use calendar::CalMarkers;
pub use calendar::CldrCalendar;
pub use calendar::ConvertCalendar;
pub use calendar::FullDataCalMarkers;
pub use calendar::IsInCalendar;
pub use calendar::IsInFixedCalendar;
pub use calendar::InCalendar;
pub use calendar::InFixedCalendar;
pub use calendar::NoDataCalMarkers;

pub(crate) use fieldset_traits::datetime_marker_helper;
Expand Down
Loading