Bug 275095
| Summary: | [JSC] Fix behavior of `Intl.DurationFormat` for negative values | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Sosuke Suzuki <aosukeke> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Sosuke Suzuki
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
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Sosuke Suzuki
Pull Request: https://github.com/WebKit/WebKit/pull/29489
Radar WebKit Bug Importer
<rdar://problem/129561747>
EWS
Committed 279902@main (3f74bba5c41c): <https://commits.webkit.org/279902@main>
Reviewed commits have been landed. Closing PR #29489 and removing active labels.