icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Implement DurationFormat

Open sffc opened this issue 3 years ago • 8 comments

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!

sffc avatar Jun 16 '21 03:06 sffc

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)

kartva avatar Feb 25 '24 20:02 kartva

Yes, you can ask questions here or on GitHub Discussions. We also have [email protected]

Manishearth avatar Feb 26 '24 17:02 Manishearth

Questions specifically about DurationFormat are on-topic for this thread.

sffc avatar Feb 26 '24 18:02 sffc

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)

kartva avatar Mar 15 '24 20:03 kartva

Would [email protected] be the right place to discuss GSoC proposals for this idea?

kartva avatar Mar 20 '24 00:03 kartva

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?

kartva avatar Mar 22 '24 23:03 kartva

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 using FixedDecimalFormatter 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?

kartva avatar Mar 23 '24 20:03 kartva

@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.

sffc avatar Mar 23 '24 20:03 sffc