tc39 / proposal-intl-duration-format

https://tc39.es/proposal-intl-duration-format
MIT License
165 stars 18 forks source link

Current spec does not output desired result #114

Closed FrankYFTang closed 1 year ago

FrankYFTang commented 2 years ago

This is mentioned by @anba in https://github.com/tc39/proposal-intl-duration-format/pull/107/files#diff-7d681727fcf47dc0b9a7512a470fb0da63276c625891a5cc232d725bd12912fdR329 as "EDITOR'S NOTE Adding the time separator as a separate list element is wrong, because it will be formatted as a single entry through the list formatter resulting in strings like "12, :, 30, :, and 45"." in the end of https://tc39.es/proposal-intl-duration-format/#sec-partitiondurationformatpattern but we need an issue to track this.

Currenlty, if we have

const duration = { years: 1, months: 2, weeks: 3, days: 3,  hours: 4, minutes: 5, seconds: 6, milliseconds: 7, microseconds: 8, nanoseconds: 9 };
const df = new Intl.DurationFormat("en", {style: "digital"});
df.format(duration 

the output is NOT "digital":"1y, 2m, 3w, 3d, and 4:05:06.007" by the algorithm but "1y, 2m, 3w, 3d, 4, :, 05, :, and 06" as the last case in https://github.com/tc39/test262/blob/main/test/intl402/DurationFormat/prototype/format/style-options-en.js

First, the ":" after "4" and the ":" after "05" are appended to result separately as { [[Type]]: "literal", [[Value]]: ":"} so ListFormat will add ", " and " and " for them. Second, the [[FractionalDigits]] is 0 so there will be no ".007" after "06"

Since [[FractionalDigits]] is only used to ouput "seconds", "milliseconds", or "microseconds" should we default it to 3 instead of 0?

@anba @sffc @ryzokuken @romulocintra

sffc commented 2 years ago

Related: #64

sffc commented 2 years ago

Discussion: https://github.com/tc39/ecma402/blob/master/meetings/notes-2022-09-01.md#current-spec-does-not-output-desired-result-114

ryzokuken commented 1 year ago

This was addressed by #55