dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.24k stars 1.57k forks source link

Support richer duration formatting #24529

Open yemount opened 9 years ago

yemount commented 9 years ago

Currently Dart only supports limited duration formatting. The only way to get a formatted duration is through Duration.toString(): https://github.com/dart-lang/sdk/blob/bb7f3a7501e4e64fa149d9a42fae6625a88900a8/sdk/lib/core/duration.dart#L241

It'd be helpful to provide richer formatting options. For instance one that drops the hour string if hour is zero, or drops the unnecessary trailing 0s after the decimal point.

lrhn commented 3 years ago

We generally recommend using package:intl for complicated formatting of time and dates. It sadly doesn't support durations yet. I think that's where we should put the functionality when we implement it.

clragon commented 9 months ago

I assume that would be https://github.com/dart-lang/i18n/issues/332 then.

lrhn commented 9 months ago

That would be it, yes. If something has to be written, that would be a better place for it than the SDK, since the intl package can choose to support many different formats, where the SDK prefers to have just one canonical toString with an accompagnying parse, to allow storing as a string. It's not generally intended for displaying, because how to do that that is very much domain and use-case specific.