tc39 / proposal-intl-duration-format

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

PartitionDurationFormatPattern: Replace "nextStyle" with comparison against current "style"? #153

Closed anba closed 1 year ago

anba commented 1 year ago

PartitionDurationFormatPattern, steps 4.j.i-iv:

j. If unit is "seconds", "milliseconds", or "microseconds", then   i. If unit is "seconds", then    1. Let nextStyle be durationFormat.[[MillisecondsStyle]].   ii. Else if unit is "milliseconds", then    1. Let nextStyle be durationFormat.[[MicrosecondsStyle]].   iii. Else,    1. Let nextStyle be durationFormat.[[NanosecondsStyle]].   iv. If nextStyle is "numeric", then    ....

Could be replaced with:

j. If unit is "seconds", "milliseconds", or "microseconds", then   i. If style is "2-digit" or "numeric", then    ....

This avoids reading the next style and the extra if-else steps.

anba commented 1 year ago

Whoops, actually not correct → new Intl.DurationFormat("en", {seconds:"short", milliseconds:"numeric"}) has a numeric next style with a current style non-numeric.