tc39 / test262

Official ECMAScript Conformance Test Suite
Other
2.3k stars 457 forks source link

Add test to check `nfOptions.roundingMode` for seconds / microseconds / nanoseconds is `"trunc"` #4115

Closed sosukesuzuki closed 2 months ago

sosukesuzuki commented 2 months ago

According to the spec^1, nfOptions.roundingMode shoule be "trunc" when formatting seconds, microseconds, and nanoseconds.

  1.1.14 PartitionDurationFormatPattern
    (...)
    4. While numericUnitFound is false, repeat for each row in Table 2 in table order, except the header row:
      e. If style is "numeric" or "2-digit", then
        i. Append FormatNumericUnits(durationFormat, duration, unit, signDisplayed) to result.
        (...)
      f. Else,
        (...)
        ii. If unit is "seconds", "milliseconds", or "microseconds", then
          (...)
          f. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc").

    1.1.12 FormatNumericUnits
      (...)
      18. If secondsFormatted is true, then
        a. Append FormatNumericSeconds(durationFormat, secondsValue, minutesFormatted, signDisplayed) to numericPartsList.
        (...)

    1.1.11 FormatNumericSeconds
      (...)
      15. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc").
      (...)

The test262 harness correctly implements this behavior, but at least WebKit does not^2.

This PR adds a test to check this behavior.