Skip to content

Commit

Permalink
[JSC] Change Intl.DurationFormat digital's default from narrow to short
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260182
rdar://113879830

Reviewed by Justin Michaud.

Update the implementation to align to the latest spec update[1].
We should use "short" instead of "narrow" by default for Intl.DurationFormat digital formatting.

[1]: tc39/proposal-intl-duration-format@4c24876

* Source/JavaScriptCore/runtime/IntlDurationFormat.cpp:

Canonical link: https://commits.webkit.org/266891@main
  • Loading branch information
Constellation committed Aug 15, 2023
1 parent b8f9d49 commit 5b076c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
21 changes: 7 additions & 14 deletions JSTests/stress/intl-durationformat-digital.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,39 @@ if (Intl.DurationFormat) {
style: 'digital'
});
shouldBeOneOf(fmt.format({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 }), [
`1y, 2mo, 3w, 4d, 10.34.33`,
`1y, 2m, 3w, 4d, 10.34.33`,
`1 yr, 2 mths, 3 wks, 4 days, 10.34.33`,
]);
}
{
var fmt = new Intl.DurationFormat('en-DK-u-ca-buddhist', {
style: 'digital'
});
shouldBeOneOf(fmt.format({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 }), [
`1y, 2mo, 3w, 4d, 10.34.33`,
`1y, 2m, 3w, 4d, 10.34.33`,
`1 yr, 2 mths, 3 wks, 4 days, 10.34.33`,
]);
}
{
var fmt = new Intl.DurationFormat('en-DK-u-nu-hanidec', {
style: 'digital'
});
shouldBeOneOf(fmt.format({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 }), [
`一y, 二mo, 三w, 四d, 一〇:三四:三三`,
`一y, 二m, 三w, 四d, 一〇:三四:三三`,
`一 yr, 二 mths, 三 wks, 四 days, 一〇:三四:三三`,
]);
}
{
var fmt = new Intl.DurationFormat('en', {
style: 'digital'
});
shouldBeOneOf(fmt.format({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 }), [
`1y, 2mo, 3w, 4d, 10:34:33`,
`1y, 2m, 3w, 4d, 10:34:33`,
`1 yr, 2 mths, 3 wks, 4 days, 10:34:33`,
]);
}
{
var fmt = new Intl.DurationFormat('en', {
style: 'digital'
});
shouldBeOneOf(fmt.format({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 }), [
`1y, 2mo, 3w, 4d, 10:34:33`,
`1y, 2m, 3w, 4d, 10:34:33`,
`1 yr, 2 mths, 3 wks, 4 days, 10:34:33`,
]);
}
{
Expand All @@ -65,8 +60,7 @@ if (Intl.DurationFormat) {
});

shouldBeOneOf(fmt.format({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 }), [
`1y, 2mo, 3w, 4d, 10:34:33.032000000`,
`1y, 2m, 3w, 4d, 10:34:33.032000000`,
`1 yr, 2 mths, 3 wks, 4 days, 10:34:33.032000000`,
]);
}
{
Expand All @@ -78,8 +72,7 @@ if (Intl.DurationFormat) {
});

shouldBeOneOf(fmt.format({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 }), [
`1y, 2mo, 3w, 4d, 10:34:33.03`,
`1y, 2m, 3w, 4d, 10:34:33.03`,
`1 yr, 2 mths, 3 wks, 4 days, 10:34:33.03`,
]);
}
{
Expand Down
2 changes: 1 addition & 1 deletion JSTests/stress/intl-durationformat-format-to-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (Intl.DurationFormat) {
});

shouldBeOneOf(JSON.stringify(fmt.formatToParts({ years: 1, months: 2, weeks: 3, days: 4, hours: 10, minutes: 34, seconds: 33, milliseconds: 32 })), [
`[{"type":"integer","value":"1","unit":"year"},{"type":"unit","value":"y","unit":"year"},{"type":"literal","value":", "},{"type":"integer","value":"2","unit":"month"},{"type":"unit","value":"mo","unit":"month"},{"type":"literal","value":", "},{"type":"integer","value":"3","unit":"week"},{"type":"unit","value":"w","unit":"week"},{"type":"literal","value":", "},{"type":"integer","value":"4","unit":"day"},{"type":"unit","value":"d","unit":"day"},{"type":"literal","value":", "},{"type":"integer","value":"10","unit":"hour"},{"type":"literal","value":":"},{"type":"integer","value":"34","unit":"minute"},{"type":"literal","value":":"},{"type":"integer","value":"33","unit":"second"},{"type":"decimal","value":".","unit":"second"},{"type":"fraction","value":"03","unit":"second"}]`,
`[{"type":"integer","value":"1","unit":"year"},{"type":"literal","value":" ","unit":"year"},{"type":"unit","value":"yr","unit":"year"},{"type":"literal","value":", "},{"type":"integer","value":"2","unit":"month"},{"type":"literal","value":" ","unit":"month"},{"type":"unit","value":"mths","unit":"month"},{"type":"literal","value":", "},{"type":"integer","value":"3","unit":"week"},{"type":"literal","value":" ","unit":"week"},{"type":"unit","value":"wks","unit":"week"},{"type":"literal","value":", "},{"type":"integer","value":"4","unit":"day"},{"type":"literal","value":" ","unit":"day"},{"type":"unit","value":"days","unit":"day"},{"type":"literal","value":", "},{"type":"integer","value":"10","unit":"hour"},{"type":"literal","value":":"},{"type":"integer","value":"34","unit":"minute"},{"type":"literal","value":":"},{"type":"integer","value":"33","unit":"second"},{"type":"decimal","value":".","unit":"second"},{"type":"fraction","value":"03","unit":"second"}]`,
]);
}
{
Expand Down
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/runtime/IntlDurationFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ static IntlDurationFormat::UnitData intlDurationUnitOptions(JSGlobalObject* glob
}

static constexpr IntlDurationFormat::UnitStyle digitalDefaults[numberOfTemporalUnits] = {
IntlDurationFormat::UnitStyle::Narrow,
IntlDurationFormat::UnitStyle::Narrow,
IntlDurationFormat::UnitStyle::Narrow,
IntlDurationFormat::UnitStyle::Narrow,
IntlDurationFormat::UnitStyle::Short,
IntlDurationFormat::UnitStyle::Short,
IntlDurationFormat::UnitStyle::Short,
IntlDurationFormat::UnitStyle::Short,
IntlDurationFormat::UnitStyle::Numeric,
IntlDurationFormat::UnitStyle::Numeric,
IntlDurationFormat::UnitStyle::Numeric,
Expand Down

0 comments on commit 5b076c9

Please sign in to comment.