Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3f74bba5c41c78732611942b04ba1d43a5fa030c
      
https://github.com/WebKit/WebKit/commit/3f74bba5c41c78732611942b04ba1d43a5fa030c
  Author: Sosuke Suzuki <[email protected]>
  Date:   2024-06-11 (Tue, 11 Jun 2024)

  Changed paths:
    A JSTests/stress/intl-duration-format-negative-values.js
    M JSTests/test262/expectations.yaml
    M Source/JavaScriptCore/runtime/IntlDurationFormat.cpp

  Log Message:
  -----------
  [JSC] Fix behavior of `Intl.DurationFormat` for negative values
https://bugs.webkit.org/show_bug.cgi?id=275095

Reviewed by Ross Kirsling.

This patch includes the following two related fixes:

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

* JSTests/stress/intl-duration-format-negative-values.js: Added.
(sameValue):
(throw.new.Error):
* JSTests/test262/expectations.yaml:
* Source/JavaScriptCore/runtime/IntlDurationFormat.cpp:
(JSC::getDurationSign):
(JSC::collectElements):

Canonical link: https://commits.webkit.org/279902@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to