Skip to content

DurationFormat: Add tests for durations with style: "digital", hoursDisplay: "auto" and zero hours#4367

Merged
Ms2ger merged 2 commits intotc39:mainfrom
sosukesuzuki:eng/intl-durationformat-hours
Jan 13, 2025
Merged

DurationFormat: Add tests for durations with style: "digital", hoursDisplay: "auto" and zero hours#4367
Ms2ger merged 2 commits intotc39:mainfrom
sosukesuzuki:eng/intl-durationformat-hours

Conversation

@sosukesuzuki
Copy link
Contributor

@sosukesuzuki sosukesuzuki commented Dec 28, 2024

The implementation of Intl.DurationFormat in WebKit (JavaScriptCore) has passed all test262 test cases, but we discovered two incompatibilities with the specification. This Pull Request adds tests addressing those issues.

The first one is described in bug 285078. A separator is printed erroneously for an unprinted hours value:

const df = new Intl.DurationFormat('en-US', {
  style: "digital",
  hoursDisplay: "auto",
});
df.format({hours: 0, minutes: 1, seconds: 2});
// expected: "01:02"
// actual  : ":, 01:02"

The second one is described in bug 285212. A negative sign is not printed:

const df = new Intl.DurationFormat('en-US', {
  style: "digital",
  hoursDisplay: "auto",
});
df.format({ hours: 0, minutes: -2, seconds: -3 });
// expected: "-02:03"
// actual  : "02:03"

Both issues occur when style: "digital", hoursDisplay: "auto", and the hours value is 0 or absent. For that reason, they are combined into a single test file.

@sosukesuzuki sosukesuzuki requested a review from a team as a code owner December 28, 2024 10:52
// basic zero hours
[{ hours: 0, minutes: 0, seconds: 2 }, "00:02"],
[{ hours: 0, minutes: 1, seconds: 2 }, "01:02"],
[{ days: 1, hours: 0, minutes: 1, seconds: 2 }, "1 day, 01:02"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome prints "1 day:01:02" for this, which is correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a V8 bug.

In FormatNumericUnits, steps 10-11 will set hoursFormatted to false, because the hour value is zero and the hours display is not "always". Step 17 passes hoursFormatted to FormatNumericMinutes. FormatNumericMinutes, step 2 only appends the separator if hoursDisplayed is false. And the value of hoursDisplayed is hoursFormatted from FormatNumericUnits. That means no separator should be appended for this case.

@sosukesuzuki
Copy link
Contributor Author

esvu on CI fails but probably this PR isn't related

esvu ❯ version 1.2.16
JavaScriptCore ❯ Checking version...
esvu ✖ FetchError: request to https://webkitgtk.org/jsc-built-products/x86_64/release/LAST-IS failed, reason: certificate has expired
    at ClientRequest.<anonymous> (/home/circleci/test262/node_modules/node-fetch/lib/index.js:1501:11)
    at ClientRequest.emit (node:events:518:28)
    at emitErrorEvent (node:_http_client:101:11)
    at TLSSocket.socketErrorListener (node:_http_client:504:5)
    at TLSSocket.emit (node:events:518:28)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'CERT_HAS_EXPIRED',
  code: 'CERT_HAS_EXPIRED'
}
esvu ✖ Some engines were not installed.

// basic zero hours
[{ hours: 0, minutes: 0, seconds: 2 }, "00:02"],
[{ hours: 0, minutes: 1, seconds: 2 }, "01:02"],
[{ days: 1, hours: 0, minutes: 1, seconds: 2 }, "1 day, 01:02"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a V8 bug.

In FormatNumericUnits, steps 10-11 will set hoursFormatted to false, because the hour value is zero and the hours display is not "always". Step 17 passes hoursFormatted to FormatNumericMinutes. FormatNumericMinutes, step 2 only appends the separator if hoursDisplayed is false. And the value of hoursDisplayed is hoursFormatted from FormatNumericUnits. That means no separator should be appended for this case.

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to defer to anba here

@sosukesuzuki
Copy link
Contributor Author

@anba Thank you for review!

@sosukesuzuki
Copy link
Contributor Author

@Ms2ger Anba's suggestions have been applied, probably we can merge this

sosukesuzuki and others added 2 commits January 13, 2025 10:59
…h-hours-display-auto-with-zero-hour.js

Co-authored-by: André Bargull <andre.bargull@gmail.com>
@Ms2ger Ms2ger force-pushed the eng/intl-durationformat-hours branch from 29a1581 to eac60e2 Compare January 13, 2025 09:59
@Ms2ger Ms2ger merged commit c85603f into tc39:main Jan 13, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants