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

Should NeoFormatter and TypedNeoFormatter have default generics? #5687

Open
sffc opened this issue Oct 15, 2024 · 5 comments
Open

Should NeoFormatter and TypedNeoFormatter have default generics? #5687

sffc opened this issue Oct 15, 2024 · 5 comments
Labels
C-datetime Component: datetime, calendars, time zones

Comments

@sffc
Copy link
Member

sffc commented Oct 15, 2024

Currently if you want a time formatter you need to explicitly set the calendar type to NeverCalendar / ().

This raises the general question, should they have default generics?

The time formatter specific concern can also be addressed by

  1. Make a type alias such as pub type TimeFormatter
  2. Make format_time imply this bound

@Manishearth @robertbastian

@sffc sffc added the discuss-priority Discuss at the next ICU4X meeting label Oct 15, 2024
@sffc sffc added this to the ICU4X 2.0 ⟨P1⟩ milestone Oct 15, 2024
@Manishearth
Copy link
Member

I don't really think there's a sensible "default" here. I think TimeFormatter is fine. I also think adding the bound may work, though it would be nice if DateTimeFormatter could format_time too.

@sffc
Copy link
Member Author

sffc commented Oct 15, 2024

This currently works:

TypedFormatter::try_new(
  locale,
  fieldset::YMD::with_length(Medium)
)
.format(Date::try_new_gregorian_date(...))

This currently requires an explicit NeverCalendar:

TypedFormatter::<NeverCalendar, _>::try_new(
  locale,
  fieldset::HM::with_length(Medium)
)
.format(Time::try_new(...))

If we had format_time (#5269 (comment)), the type inference should work because the function would be defined on Formatter<NeverCalendar>

TypedFormatter::try_new(
  locale,
  fieldset::HM::with_length(Medium)
)
.format_time(Time::try_new(...))

@sffc
Copy link
Member Author

sffc commented Oct 15, 2024

What would pub type TimeFormatter map to?

pub type TimeFormatter<FSet> = TypedFormatter<NeverCalendar, FSet>
pub type TimeFormatter<FSet> = Formatter<FSet>
pub type TimeFormatter = TypedFormatter<NeverCalendar, TimeSkeleton>

@sffc
Copy link
Member Author

sffc commented Oct 15, 2024

I don't consider this a 2.0-beta blocker.

@sffc sffc added discuss Discuss at a future ICU4X-SC meeting and removed discuss-priority Discuss at the next ICU4X meeting labels Oct 15, 2024
@sffc
Copy link
Member Author

sffc commented Oct 23, 2024

Shane/Rob discussion:

@sffc Note: I have already replaced NeverCalendar with (). We currently have:

DateTimeFormatter<_>  // field set
FixedCalendarDateTimeFormatter<(), _>  // calendar, field set

Discussion:

  • @robertbastian - We could add a type alias for TimeFormatter<FS> = FixedCalendarDateTimeFormatter<(), FS> so that the weirdness is a bit more hidden
  • @sffc It applies to time and time zone.

Bikeshed:

  1. TimeFormatter
  2. NoDateFormatter
  3. NoCalendarFormatter
  4. DatelessFormatter
  5. TimeFormatter + TimeZoneFormatter

Discussion:

  • @robertbastian I think 5 is best, it adds a small amount of API but it's the names people will be looking for. You don't want to think about calendars at all if you try to format a time
  • @sffc It's confusing that TimeZoneFormatter can format other things besides time zones. I'm okay with TimeFormatter to start. It's not that weird to say to use TimeFormatter to format a time zone.
  • @sffc Observation: you would be able to construct a TimeFormatter<fieldset::YMD>, but there is no type that satisfies the bounds for the .format function.

Conclusion:

  • Add a TimeFormatter type alias
  • Do not add default generics

LGTM: @sffc @robertbastian

@sffc sffc added C-datetime Component: datetime, calendars, time zones and removed discuss Discuss at a future ICU4X-SC meeting labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-datetime Component: datetime, calendars, time zones
Projects
None yet
Development

No branches or pull requests

2 participants