sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Support richer duration formatting

Open yemount opened this issue 10 years ago • 3 comments

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.

yemount avatar Oct 08 '15 22:10 yemount

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.

lrhn avatar Mar 11 '21 14:03 lrhn

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

clragon avatar Feb 15 '24 04:02 clragon

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.

lrhn avatar Feb 15 '24 10:02 lrhn