Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Intl.DurationFormat tests #3983

Merged
merged 5 commits into from
Apr 23, 2024
Merged

Update Intl.DurationFormat tests #3983

merged 5 commits into from
Apr 23, 2024

Conversation

anba
Copy link
Contributor

@anba anba commented Jan 9, 2024

Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

For future reference, I'm not at all a fan of the approach of essentially putting a polyfill into the testIntl helper file and comparing the results from the polyfill with the results from the implementation. It makes these tests opaque, difficult to understand what's being tested, and unclear whether the polyfill or the implementation is at fault when the tests fail.

However, the tests were already set up that way, so in the absence of clear recommendations about what to do otherwise (#3786) I would say that changing it is out of scope for this PR.

Nonetheless I would suggest that numeric-hour-with-zero-minutes-and-non-zero-seconds.js was clearer using NumberFormat and ListFormat directly, as it previously did, so maybe we should drop the commit ' Use formatDurationFormatPattern for "/numeric-hour-with-zero-minutes-and-non-zero-seconds"'.

Could @ryzokuken, @romulocintra, or @ben-allen take a look at the polyfill changes please?

@anba
Copy link
Contributor Author

anba commented Jan 19, 2024

Nonetheless I would suggest that numeric-hour-with-zero-minutes-and-non-zero-seconds.js was clearer using NumberFormat and ListFormat directly, as it previously did, so maybe we should drop the commit ' Use formatDurationFormatPattern for "/numeric-hour-with-zero-minutes-and-non-zero-seconds"'.

This isn't actually possible, because of tc39/proposal-intl-duration-format#180. Before that PR, the test expected the string "1, 03", so the hours and seconds duration units were number-formatted and then concatenated through the list formatter. After the PR, the expected string is "1:00:03", so the list formatter is no longer used at all. The only alternative here is to hardcode the string "1:00:03" as the expected result and don't use a number nor a list formatter.

@ben-allen
Copy link
Contributor

ben-allen commented Apr 11, 2024

With regard to the "numeric-hour-with-zero-minutes-and-non-zero-seconds" question: in recent tests involving digital-like styles (see: #4034) I've been handling them by stitching together the unit values with ":" as a hard-coded separator. My theory is that this is slightly better than using a fully hard-coded string, since:

  1. Tests written this way could in the future be used to test in other locales that also use ":" as the hours/minutes and minutes/seconds separators, but that use different numbering systems
  2. It makes it relatively simpler to (in the somewhat more distant future) draw from the new [[HoursMinutesSeparator]], and [[MinutesSecondsSeparator]] slots from Editorial: Refactor handling of numeric-like styles, support differing hours/minutes vs minutes/seconds separators proposal-intl-duration-format#188

@ben-allen ben-allen self-assigned this Apr 17, 2024
Copy link
Contributor

@ben-allen ben-allen left a comment

Choose a reason for hiding this comment

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

oh my goodness, thank you for catching this. I'm actively embarassed...

Copy link
Contributor

@ben-allen ben-allen left a comment

Choose a reason for hiding this comment

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

It's all great -- thank you for all of your work here.

Thoughts in general:

  • I'm wondering if it's worthwhile to have a TG2 discussion on the behaviour when seconds (or the relevant subsecond unit) has its display option set to "auto" and has a non-zero fractional component that's nevertheless not displayed due to use of the fractionalDigits option. I can see arguments for changing this behaviour, but also arguments for leaving it as-is
  • I share @ptomato's skepticism about the use of the partitionDurationFormatPattern quasi-polyfill. That said, given that these tests are great and given that DurationFormat is nearly done, I'm wondering if, in the interest of testing locales other than "en", it would be useful for me to extend partitionDurationFormatPattern to handle hour/minute/second separators other than ":", decimal separators other than ".", and numbering systems other than latn.

Sync `partitionDurationFormatPattern` with the latest spec draft and
change it to use an `Intl.DurationFormat` object as the input, so it's
easier to compare it against the spec text and because it allows to test
more inputs.

Includes the fixes for:
- tc39/proposal-intl-duration-format#183
- tc39/proposal-intl-duration-format#184
…and-non-zero-seconds"

The changes from the first commit allow to use
`formatDurationFormatPattern` for this test.
…fault display of sub-hours units

Numeric "minute" and "seconds" units now default to "always" display, so we have
to add an additional test to cover when "auto" display is used. Additionally add
more inputs to cover all possible test combinations.
@Ms2ger Ms2ger merged commit a640565 into tc39:main Apr 23, 2024
8 checks passed
@anba anba deleted the duration-format branch June 24, 2024 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants