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

Add different formatting for test/intl402/DurationFormat/prototype/format/style-digital-en.js #3895

Merged
merged 1 commit into from
Aug 21, 2023

Conversation

Constellation
Copy link
Member

@Constellation Constellation commented Aug 12, 2023

ECMA-402 does not require specific CLDR format, and each platform has some customization for their platform consistency.
macOS system ICU is shipping new CLDR, but it has many overrides on the top of it to make the formatted output suitable for the system.
This change modifies the test to accept that alternative output from AppleICU.

@Constellation Constellation requested a review from a team as a code owner August 12, 2023 02:13
@Constellation Constellation force-pushed the update-intl-duration branch 2 times, most recently from 6226dfb to 58f8875 Compare August 12, 2023 02:16
@Constellation
Copy link
Member Author

@rwaldron @sffc @FrankYFTang

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.

Thanks for the submission. Clearly we need to correct this, as the spec does not mandate a particular locale format, and we should not have a test hardcoded to one engine's output.

However, I'd prefer not to perpetuate the problem by having a test hardcoded to two engines' outputs. See #3786.

You probably know the Intl.DurationFormat spec better than I do here, so what are the essential requirements of formatting {style: 'digital'} in English? Could we say that the output must have the number of years, months, weeks, days, hours, minutes, and seconds in order, and that there must be some form of unit (y.*, m.*, w.*, d.*) in between the first five quantities, and two colons in between the hours, minutes, and seconds? Maybe there's a regexp that would express that.

(A minor point, if we aren't using assert.sameValue() anymore, make sure to include the actual value, and expected value if applicable, in the error message, to help debugging.)

@sffc
Copy link
Contributor

sffc commented Aug 14, 2023

Please also note that the default length for digital units is "short" not "narrow" since tc39/proposal-intl-duration-format@4c24876

@@ -9,7 +9,8 @@ features: [Intl.DurationFormat]
---*/

const style = "digital";
const expected = "1 yr 2 mths 3 wks 3 days 4:05:06";
const expected1 = "1 yr 2 mths 3 wks 3 days 4:05:06";
Copy link
Contributor

Choose a reason for hiding this comment

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

expected and expected1 of using " " for separator instead of ", " is incorrect. There is a v8 bug which does not map digital to short style but narrow style and that should be fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

By my reading, either one is permitted by the spec. These separators come from joining the elements together with ListFormat with {type:'unit'}, which is ILD.

(Seems like most implementations currently use ", " in the en locale, while MDN documentation suggests that you will get " ".)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it to accept comma via RegExp.

@sffc
Copy link
Contributor

sffc commented Aug 14, 2023

An appropriate test would be one where year/month/day get formatted in default (short) format and then again in digital format, and the results should be the same per the spec.

@FrankYFTang
Copy link
Contributor

How about we change the testing for the duration format to write testing code which use Intl.ListFormat and Intl.NumberFormat to generate expectation and compare with the result produced by the Intl.DurationFormat.

@Constellation
Copy link
Member Author

An appropriate test would be one where year/month/day get formatted in default (short) format and then again in digital format, and the results should be the same per the spec.

Oops, right. Fixed.

@Constellation
Copy link
Member Author

How about we change the testing for the duration format to write testing code which use Intl.ListFormat and Intl.NumberFormat to generate expectation and compare with the result produced by the Intl.DurationFormat.

Right now, I'll just fix the broken test in the repository.

@Constellation
Copy link
Member Author

Thanks for the submission. Clearly we need to correct this, as the spec does not mandate a particular locale format, and we should not have a test hardcoded to one engine's output.

However, I'd prefer not to perpetuate the problem by having a test hardcoded to two engines' outputs. See #3786.

You probably know the Intl.DurationFormat spec better than I do here, so what are the essential requirements of formatting {style: 'digital'} in English? Could we say that the output must have the number of years, months, weeks, days, hours, minutes, and seconds in order, and that there must be some form of unit (y.*, m.*, w.*, d.*) in between the first five quantities, and two colons in between the hours, minutes, and seconds? Maybe there's a regexp that would express that.

(A minor point, if we aren't using assert.sameValue() anymore, make sure to include the actual value, and expected value if applicable, in the error message, to help debugging.)

Changed it to RegExp approach.

@Constellation Constellation requested a review from ptomato August 14, 2023 23:57
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.

Thanks, works for me, I'll merge it if no-one else suggests any improvements.

@anba
Copy link
Contributor

anba commented Aug 15, 2023

IMO, applying Frank's suggestion seems the best solution, because it results in the output which is required by the spec:

const parts = [
  new Intl.NumberFormat("en", {style: "unit", unit: "year", unitDisplay: "short"}).format(duration.years),
  new Intl.NumberFormat("en", {style: "unit", unit: "month", unitDisplay: "short"}).format(duration.months),
  new Intl.NumberFormat("en", {style: "unit", unit: "week", unitDisplay: "short"}).format(duration.weeks),
  new Intl.NumberFormat("en", {style: "unit", unit: "day", unitDisplay: "short"}).format(duration.days),
  [
    new Intl.NumberFormat("en", {}).format(duration.hours),
    new Intl.NumberFormat("en", {minimumIntegerDigits: 2}).format(duration.minutes),
    new Intl.NumberFormat("en", {minimumIntegerDigits: 2, minimumFractionDigits: 0, maximumFractionDigits: 9, roundingMode: "trunc"}).format(
      duration.seconds + (duration.milliseconds / 10**3) + (duration.microseconds / 10**6) + (duration.nanoseconds / 10 ** 9)
    ),
  ].join(":")
];
const expected = new Intl.ListFormat("en", {type: "unit", style: "short"}).format(parts);

// And then change the assertion to:
assert.sameValue(df.format(duration), expected, `Assert DurationFormat format output using ${style} style option`);

@FrankYFTang
Copy link
Contributor

Thanks for the submission. Clearly we need to correct this, as the spec does not mandate a particular locale format, and we should not have a test hardcoded to one engine's output.
However, I'd prefer not to perpetuate the problem by having a test hardcoded to two engines' outputs. See #3786.
You probably know the Intl.DurationFormat spec better than I do here, so what are the essential requirements of formatting {style: 'digital'} in English? Could we say that the output must have the number of years, months, weeks, days, hours, minutes, and seconds in order, and that there must be some form of unit (y.*, m.*, w.*, d.*) in between the first five quantities, and two colons in between the hours, minutes, and seconds? Maybe there's a regexp that would express that.
(A minor point, if we aren't using assert.sameValue() anymore, make sure to include the actual value, and expected value if applicable, in the error message, to help debugging.)

Changed it to RegExp approach.

Why we need a RegExp to make it ",? " here instead of requiring ", " ?

In what case the one without "," is the correct expectation?

@Constellation
Copy link
Member Author

@FrankYFTang Currently, just keeping the original expectation since the original test was accepting that.
It seems that this test is added in 4fda9c4.
Did you add that based on some ICU configuration?

@FrankYFTang
Copy link
Contributor

Did you add that based on some ICU configuration?

no, that is based on the spec text prior to the merge of
https://github.com/tc39/proposal-intl-duration-format/pull/127/files#diff-7d681727fcf47dc0b9a7512a470fb0da63276c625891a5cc232d725bd12912fd

That PR got merged but the test was not updated to sync to that PR. (nor the v8 implementation till https://chromium-review.googlesource.com/c/v8/v8/+/4781659 (which is under review))

The expected output is not aligned: it is missing comma. This change fixes it.
@Constellation
Copy link
Member Author

@FrankYFTang OK, I've just changed it to comma split one.
@ptomato Can you merge it?

Copy link
Contributor

@FrankYFTang FrankYFTang left a comment

Choose a reason for hiding this comment

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

LGTM

@ptomato
Copy link
Contributor

ptomato commented Aug 21, 2023

I'd prefer that we implement @anba's suggestion in #3895 (comment), to avoid hard-coded expectations, but since (1) that's probably not what you signed up for when you opened the PR and (2) it seems like this particular hard-coded output is acceptable to everyone who commented on this thread and does not make the situation worse than it already was, I'll merge it now. See #3786 for follow up.

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.

5 participants