tc39 / proposal-intl-duration-format

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

No part.[[Unit]] in 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ) #140

Closed FrankYFTang closed 1 year ago

FrankYFTang commented 1 year ago

In the current spec text 1.4.3 Intl.DurationFormat.prototype.format ( duration ) 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ) https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.format and https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts

both have something like

4. Let parts be PartitionDurationFormatPattern(df, record).
...
7. For each { [[Type]], [[Value]] } part in parts, do

and in formatToParts it also has

d. If part.[[Unit]] is set, Perform ! CreateDataPropertyOrThrow(obj, "unit", part.[[Unit]]).

The problem is some of the Records in parts returned by PartitionDurationFormatPattern has { [[Type]], [[Value]] } while some other has { [[Type]], [[Value]], [[Unit]]}

So the current text imply it will match only those which has { [[Type]], [[Value]]} but not those has { [[Type]], [[Value]], [[Unit]]}

Following what is in https://tc39.es/ecma262/#sec-finalization-registry.prototype.unregister

I think the loop should be changed to

7. For each Record { [[Type]], [[Value]], [[Unit]] } part of parts, do

and also

d. If part.[[Unit]] is not empty , Perform ! CreateDataPropertyOrThrow(obj, "unit", part.[[Unit]]).

@sffc @gibson042 @ryzokuken

ryzokuken commented 1 year ago

@FrankYFTang thanks, good catch