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

Extend DateTimeFormat to support other calendars #1339

Merged
merged 18 commits into from
Nov 24, 2021

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Nov 23, 2021

Fixes #1316, fixes #1115

This implements the low level API discussed in #1316: There is a public DateTimeFormat<C> API with C as a calendar type, and it is internally backed by a "raw" DateTimeFormat type with the actual implementation (same goes for ZonedDateTimeFormat). Users must specify a calendar on construction and only dates which match the calendar type can be passed in. The raw API does no such checking and is meant to be a building block for the eventual higher level API discussed in #1316.

Todo (I plan to finish these items today, just wanted to have a PR up before lunch)

  • Add some docs about this parameter
  • Enforce inlining
  • Add some tests

Unfortunately it is not yet worth it to properly test this since the Buddhist calendar has identical symbols to the Gregorian one, aside from era formatting which is not yet supported (#1312, I might work on this next).

I did verify that this PR works and loads data from the correct spot by modifying some month names in the CLDR data, regenerating testdata, and running the work_log example:

image

@Manishearth Manishearth changed the title Extend DateTimeFormat Extend DateTimeFormat to support other calendars Nov 23, 2021
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

lgtm!

one n-b question is about using Deref on generalized structs.

s
#[inline]
pub fn format_to_string(&self, value: &impl DateTimeInput<Calendar = C>) -> String {
self.0.format_to_string(value)
}
Copy link
Member

Choose a reason for hiding this comment

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

question: can you Deref to self.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but that would make self.0 a public part of the API.

Plus it's typically not considered good style to use Deref for coercions when pointers aren't involved

@Manishearth Manishearth merged commit 919d6f0 into unicode-org:main Nov 24, 2021
@Manishearth Manishearth deleted the calendar-dtf branch November 24, 2021 15:11
@sffc sffc requested review from sffc and removed request for sffc November 24, 2021 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants