dart-lang / i18n

A general mono-repo for Dart i18n and l10n packages.
BSD 3-Clause "New" or "Revised" License
64 stars 39 forks source link

intl package: add CLDR-based duration / age formatting #332

Open DartBot opened 9 years ago

DartBot commented 9 years ago

Issue by seaneagan Originally opened as dart-lang/sdk#11075


The intl package currently has unimplemented methods on DateFormat for this called formatDuration and formatDurationFrom. This is the wrong location for these APIs. Arbitrary DateFormat patterns don't match up to the corresponding CLDR data model.

The intlx package (http://pub.dartlang.org/packages/intlx) has DurationFormat which formats Durations, e.g. "5 minutes" or "5 min" and AgeFormat which formats DateTimes offset from now, e.g. "In 5 minutes" or "5 minutes ago" using CLDR data. See the following:

Demo: http://seaneagan.me/intlx/ Docs:   http://seaneagan.me/intlx/docs/intlx/DurationFormat.html   http://seaneagan.me/intlx/docs/intlx/AgeFormat.html

Proposal: move DurationFormat and AgeFormat to intl package and remove DateFormat.formatDuration/formatDurationFrom.

DartBot commented 9 years ago

Comment by iposva-google


Added Area-Pkg, Triaged labels.

DartBot commented 9 years ago

Comment by sethladd


Added Pkg-Intl label.

nikitadol commented 3 years ago

When will this be implemented?

GZaccaroni commented 3 years ago

Still no update on this?

clragon commented 8 months ago

This issue is still relevant today.

These packages provide relative time (e.g. "5 days ago"): https://pub.dev/packages/timeago https://pub.dev/packages/relative_time

Their implementation is pretty good from what I can tell though it would be much nicer to have access to this right inside intl.

However, the only package I can find for directly formatting durations: https://pub.dev/packages/duration seems to be less complete. Durations can be formatted but they cannot possibly be parsed back. The package has no concept of a "DurationFormat" as we have for dates with "DateFormat". The repository also appears to be unmaintained currently.

mosuem commented 8 months ago

This is a long-term goal, pending https://github.com/unicode-org/icu4x/issues/801 and the addition of duration formatting into ECMA402. We can then expose this through package:intl4x. It will not be implemented in package:intl.