tc39 / proposal-intl-duration-format

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

Normative: Display certain "auto"/0 values in "numeric" style when not displaying them would result in ambiguous/awkward output #180

Closed ben-allen closed 9 months ago

ben-allen commented 9 months ago

As discussed in #170, certain combinations of "display" settings in numeric styles can result in output that's both unclear and awkward. Consider the output from this sequence of formatted durations:

// "1:59:58"
new Intl.DurationFormat('en', {hours: "numeric"}).format({hours: 1, minutes: 59, seconds: 59})
// "1:59:59"
new Intl.DurationFormat('en', {hours: "numeric"}).format({hours: 2, minutes: 0, seconds: 0})
// Old: "2"
// New: "2:00:00"
new Intl.DurationFormat('en', {hours: "numeric"}).format({hours: 2, minutes: 0, seconds: 1})
// Old: "2, 01"
// New: "2:00:01"

This problem arises when there is a unit with style "numeric" or "2-digit", display: "auto", and 0 for its value between two nonzero"numeric"/"2-digit"-styled units. Currently this can only happen when the minutes unit is 0 and "auto", though there would be other contexts where this problem would arise if the "numeric" format were allowed for additional units in a future DFv2.

This PR takes a couple of steps to ensure that "numeric"/"2-digit" formatting produces more regular results:

  1. When units within a duration are "numeric"/"2-digit"-styled without explicitly being set to "numeric"/"2-digit", the default display settings for minutes and seconds are now "always" instead of "auto"
  2. In the interest of never formatting "numeric"/"2-digit" formatted durations as comma-separated lists of one item each, when a "numeric"/"2-digit"-styled unit appears between two other actually displayed "numeric"/"2-digit"-styled units, that middle unit is displayed even if it is 0 and even if the display option for that unit is set to "auto".
sffc commented 9 months ago

TG2 approval: https://github.com/tc39/ecma402/blob/master/meetings/notes-2023-11-16.md#hours-numeric-w-0-in-minutes-and-non-0-in-seconds-cause-strange-output-170

ryzokuken commented 9 months ago

2023-11-28: This PR achieved TC39-TG1 consensus.