[Webkit-unassigned] [Bug 275095] New: [JSC] Fix behavior of `Intl.DurationFormat` for negative values

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Jun 3 23:53:06 PDT 2024


https://bugs.webkit.org/show_bug.cgi?id=275095

            Bug ID: 275095
           Summary: [JSC] Fix behavior of `Intl.DurationFormat` for
                    negative values
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: aosukeke at gmail.com

The current implementation of `Intl.DurationFormat` is incorrect in two ways regarding how it handles negative values:

    1. When the values of multiple units are negative, display `-` only for the largest unit.
    For example, the duration `{ years: -1, months: -2 }` should be formatted as `"-1 years, 2 months"`.
    According to the spec[1], this behavior is controlled by the `signDisplayed` variable (initially
    set to true). This variable is set to false once any unit is formatted.

    2. Implement the DurationSign abstract operation [2] to display negative zero.
    For example, the duration `{ hours: 0, seconds: -1 }` should be formatted as `"-0 hours, 1 second"`.
    This is described in section 4.f.iii.3.b of the spec [1] as follows:

        > b. If value is 0 and DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]) is -1, then
        >     i. Set value to negative-zero.

    The `partitionDurationFormatPattern` function [3] in the `harness/testintl.js` of test262 describes
    a similar process to the changes in this patch.

    [1]: https://tc39.es/proposal-intl-duration-format/#sec-partitiondurationformatpattern
    [2]: https://tc39.es/proposal-intl-duration-format/#sec-durationsign
    [3]: https://github.com/tc39/test262/blob/249657722525cc8e43b1ddb91f8df0b4b011fcf6/harness/testIntl.js#L2649-L2662

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20240604/85781db9/attachment.htm>


More information about the webkit-unassigned mailing list