icu4x
icu4x copied to clipboard
Implement DurationFormat
ECMA-402 will soon include DurationFormat, a formatter that supports durations.
Under the hood, DurationFormat uses a ListFormat (#800) to compose measurement units (#275) in most cases, with a special code path for the "digital" format based on UTS 35.
This is therefore blocked on #275 and #800.
Things to keep in mind:
- If implemented correctly, DurationFormat should require NumberFormat but not DateTimeFormat.
- Look carefully at the ECMA-402 spec for how to handle fallbacks and edge cases. Test thoroughly!
I'm interested in working on this for GSoC, but I'm not sure of the right place to discuss this proposal. Should it be in this issue, on Github Discussions, or somewhere else? (I've looked at CONTRIBUTING.md, but it doesn't seem to have any advice on this)
Yes, you can ask questions here or on GitHub Discussions. We also have [email protected]
Questions specifically about DurationFormat are on-topic for this thread.
Are the attached issues (#275 and #800) considered as part of the scope for the GSoC proposal? (They don't seem to have been completely resolved yet)
Would [email protected] be the right place to discuss GSoC proposals for this idea?
ListFormat functionality seems to exist in ICU4X, but I wasn't able to find any mention of unit formatting in the codebase (only discussion in the linked issue)
I'm starting to draft my proposal; would you say that implementing unit formatting is part of the scope?
I've found this CLDR data for duration units. Here's my understanding after reviewing the DurationFormat proposal:
- We format duration units together with ListFormat.
- The numbers need to be displayed with units, which internally use
FixedDecimalFormatter
for number formatting. Displaying units usingFixedDecimalFormatter
is not built yet. For duration formatting, we may only need #2193.
Implementation steps:
- Create a new crate (like
icu_duration
) - Write a transformer (like #2822) that pulls in the CLDR duration unit formatting data.
- Implement
DurationFormatter
that can use provided locale data and options to format durations. - Create user-facing API.
@ssfc does this look sensible? Are there any blockers or issues I may not be seeing here?
@DesmondWillowbrook Thanks for looking into this!
Yes, you found the CLDR data for the long, short, and narrow styles. In addition, for the numeric style, you'll need this data:
https://github.com/unicode-org/cldr/blob/c7e39f13da2bfbaf58c1447d610627511c7a6549/common/main/root.xml#L5650C4-L5650C16
ListFormatter is implemented already, and the parts of FixedDecimalFormatter that you need for duration formatting are also implemented. You can also use the new icu_pattern
crate in order to help with your data handling.
We may eventually want to implement data sharing between the duration formatter and the single units formatter, but to get started, these can be implemented as separate features. You do not need to wait for single unit formatter to be implemented.
You should start your work in the icu_experimental
crate. Moving it to icu_duration
is the last step after it is ready to ship.