tc39 / proposal-intl-duration-format

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

The resolved plural class is wrong in the current spec of PartitionDurationFormatPattern #118

Closed FrankYFTang closed 2 years ago

FrankYFTang commented 2 years ago

In the current spec PartitionDurationFormatPattern https://tc39.es/proposal-intl-duration-format/#sec-partitiondurationformatpattern step 3-i-iv may set value to be an non integer value and nfOpts with minimumFractionDigits/maximumFractionDigits set to [[FractionalDigits]] which could be in range 0 to 9

But then in step 3-k-v-2 and 3

2. Let pr be ! [Construct](https://tc39.es/ecma262/#sec-construct)(%PluralRules%, « durationFormat.[[Locale]] »).
3. Let prv be ! [ResolvePlural](https://tc39.github.io/ecma402/#sec-resolveplural)(pr, [𝔽](https://tc39.es/ecma262/#%F0%9D%94%BD)(value)).

notice the %PluralRules% is construct without any option bags This will result prv value not exactly as what got generated by

1. Let num be ! PartitionNumberPattern(nf, [𝔽](https://tc39.es/ecma262/#%F0%9D%94%BD)(value)).

for example, if the locale is "en", and we have the following case

let d = {seconds: 1, milliseconds: 19};
let df1 = new Intl.DurationFormat("en", {style: "long", milliseconds: "numeric"});
let df2 = new Intl.DurationFormat("en", {style: "long", milliseconds: "numeric", fractionalDigits:1});
let df3 = new Intl.DurationFormat("en", {style: "long", milliseconds: "numeric", fractionalDigits:2});
let df4 = new Intl.DurationFormat("en", {style: "long", milliseconds: "numeric", fractionalDigits:3});
df1.format(d)
df2.format(d)
df3.format(d)
df4.format(d)

The current spec text does not pass in any option bag to %PluralRules% constructor so step 8 of InitializePluralRules will call with

8. Perform ? SetNumberFormatDigitOptions(pluralRules, options, +0𝔽, 3𝔽, "standard").

and always set to minimumFractionDigits: 0 , maximumFractionDigits: 3

but this will cause prv not matching num.

The right thing for the above code is to produce

 "1 second"
 "1.0 seconds"
 "1.02 seconds"
 "1.019 seconds"

but the current algorithm, assuming minimumFractionDigits: 0 , maximumFractionDigits: 3 will produce

 "1 seconds"
 "1.0 seconds"
 "1.02 seconds"
 "1.019 seconds"
FrankYFTang commented 2 years ago

@sffc @anba @ryzokuken @romulocintra @gibson042 @rkirsling

FrankYFTang commented 2 years ago

Also, I do not understand why we need those steps in sub step 2-7 under 3-k-v of PartitionDurationFormatPattern to deal with all the pattern, plural and string concat together, instead of just construct the nf under step iv and step v separately and make the "Construct (%NumberFormat%" under step v take the nfOpts with also

style: "unit", unit: unit,
unitDisplay: style

instead?

sffc commented 2 years ago

Discussion: https://github.com/tc39/ecma402/blob/master/meetings/notes-2022-09-01.md#the-resolved-plural-class-is-wrong-in-the-current-spec-of-partitiondurationformatpattern-118

Conclusion: This issue seems to be obsolete.

romulocintra commented 2 years ago

cc @ryzokuken should this be closed ?

romulocintra commented 2 years ago

122 Closes this one