Skip to content

Commit

Permalink
Bug 1521819: Add numberingSystem support to Intl.RelativeTimeFormat. …
Browse files Browse the repository at this point in the history
…r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D27070

--HG--
extra : moz-landing-system : lando
  • Loading branch information
anba committed Jul 8, 2019
1 parent f1ca2ba commit 8874416
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
26 changes: 16 additions & 10 deletions js/src/builtin/intl/RelativeTimeFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ var relativeTimeFormatInternalProperties = {
addSpecialMissingLanguageTags(locales);
return (this._availableLocales = locales);
},
relevantExtensionKeys: [],
relevantExtensionKeys: ["nu"],
};

function relativeTimeFormatLocaleData() {
// RelativeTimeFormat doesn't support any extension keys.
return {};
return {
nu: getNumberingSystems,
default: {
nu: intl_numberingSystem,
},
};
}

/**
Expand All @@ -49,16 +53,17 @@ function resolveRelativeTimeFormatInternals(lazyRelativeTimeFormatData) {
internalProps.locale = r.locale;

// Step 11.
assert(r.locale === r.dataLocale,
"resolved locale matches the resolved data-locale when no extension-keys are present");
internalProps.numberingSystem = r.nu;

// Step 12 (Not relevant in our implementation).

// Step 13.
// Step 14.
internalProps.style = lazyRelativeTimeFormatData.style;

// Step 15.
// Step 16.
internalProps.numeric = lazyRelativeTimeFormatData.numeric;

// Steps 16-20 (Not relevant in our implementation).
// Steps 17-21 (Not relevant in our implementation).

return internalProps;
}
Expand Down Expand Up @@ -137,11 +142,11 @@ function InitializeRelativeTimeFormat(relativeTimeFormat, locales, options) {

lazyRelativeTimeFormatData.opt = opt;

// Steps 12-13.
// Steps 13-14.
const style = GetOption(options, "style", "string", ["long", "short", "narrow"], "long");
lazyRelativeTimeFormatData.style = style;

// Steps 14-15.
// Steps 15-16.
const numeric = GetOption(options, "numeric", "string", ["always", "auto"], "always");
lazyRelativeTimeFormatData.numeric = numeric;

Expand Down Expand Up @@ -252,6 +257,7 @@ function Intl_RelativeTimeFormat_resolvedOptions() {
locale: internals.locale,
style: internals.style,
numeric: internals.numeric,
numberingSystem: internals.numberingSystem,
};

// Step 6.
Expand Down
4 changes: 0 additions & 4 deletions js/src/tests/jstests.list
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,6 @@ skip script test262/annexB/language/function-code/block-decl-nested-blocks-with-
# https://bugzilla.mozilla.org/show_bug.cgi?id=1473229
skip include test262/intl402/RelativeTimeFormat/prototype/formatToParts/jstests.list

# Need to add "numberingSystem" to resolvedOptions() to address
# https://github.com/tc39/test262/pull/2011 apparently -- bug 1521819.
skip script test262/intl402/RelativeTimeFormat/prototype/resolvedOptions/order.js

# https://bugzilla.mozilla.org/show_bug.cgi?id=1508683
skip script test262/built-ins/RegExp/prototype/multiline/cross-realm.js
skip script test262/built-ins/RegExp/prototype/global/cross-realm.js
Expand Down
22 changes: 22 additions & 0 deletions js/src/tests/non262/Intl/RelativeTimeFormat/numbering-system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

// Ensure passing the default numbering system leads to the same result as when
// no explicit numbering system is present.
//
// This is a regression test for the ICU issue reported at
// <https://unicode-org.atlassian.net/browse/ICU-20280>.

for (var requestedLocale of [undefined, "en", "de", "fr"]) {
var rtf = new Intl.RelativeTimeFormat(requestedLocale);
var {locale, numberingSystem} = rtf.resolvedOptions();
var rtfNu = new Intl.RelativeTimeFormat(`${locale}-u-nu-${numberingSystem}`);

for (var unit of ["year", "quarter", "month", "week", "day", "hour", "minute", "second"]) {
for (var value of [-10, -3, -2, -1, 0, 1, 2, 3, 10]) {
assertEq(rtfNu.format(value, unit), rtf.format(value, unit));
}
}
}

if (typeof reportCompare === "function")
reportCompare(0, 0);

0 comments on commit 8874416

Please sign in to comment.