Bug 1681357 - Use regional prefs locale if locale is not specified in GetDateTimePattern; r=zbraniecki

Differential Revision: https://phabricator.services.mozilla.com/D99241
This commit is contained in:
Dan Minor 2020-12-09 16:50:14 +00:00
parent 07faffeb7b
commit 0790cac85a
2 changed files with 29 additions and 5 deletions

View File

@ -499,8 +499,17 @@ OSPreferences::GetDateTimePattern(int32_t aDateFormatStyle,
return NS_OK;
}
// If the locale is not specified, default to first regional prefs locale
const nsACString* locale = &aLocale;
AutoTArray<nsCString, 10> rpLocales;
if (aLocale.IsEmpty()) {
LocaleService::GetInstance()->GetRegionalPrefsLocales(rpLocales);
MOZ_ASSERT(rpLocales.Length() > 0);
locale = &rpLocales[0];
}
// Create a cache key from the locale + style options
nsAutoCString key(aLocale);
nsAutoCString key(*locale);
key.Append(':');
key.AppendInt(aDateFormatStyle);
key.Append(':');
@ -512,9 +521,9 @@ OSPreferences::GetDateTimePattern(int32_t aDateFormatStyle,
return NS_OK;
}
if (!OverrideDateTimePattern(dateStyle, timeStyle, aLocale, pattern)) {
if (!ReadDateTimePattern(dateStyle, timeStyle, aLocale, pattern)) {
if (!GetDateTimePatternForStyle(dateStyle, timeStyle, aLocale, pattern)) {
if (!OverrideDateTimePattern(dateStyle, timeStyle, *locale, pattern)) {
if (!ReadDateTimePattern(dateStyle, timeStyle, *locale, pattern)) {
if (!GetDateTimePatternForStyle(dateStyle, timeStyle, *locale, pattern)) {
return NS_ERROR_FAILURE;
}
}

View File

@ -77,7 +77,22 @@ TEST(Intl_Locale_OSPreferences, GetDateTimePattern)
}
}
ASSERT_TRUE(1);
// If the locale is not specified, we should get the pattern corresponding to
// the first regional prefs locale.
AutoTArray<nsCString, 10> rpLocales;
LocaleService::GetInstance()->GetRegionalPrefsLocales(rpLocales);
ASSERT_TRUE(rpLocales.Length() > 0);
nsAutoCString rpLocalePattern;
ASSERT_TRUE(NS_SUCCEEDED(
osprefs->GetDateTimePattern(mozIOSPreferences::dateTimeFormatStyleLong,
mozIOSPreferences::dateTimeFormatStyleLong,
rpLocales[0], rpLocalePattern)));
ASSERT_TRUE(NS_SUCCEEDED(
osprefs->GetDateTimePattern(mozIOSPreferences::dateTimeFormatStyleLong,
mozIOSPreferences::dateTimeFormatStyleLong,
nsDependentCString(""), pattern)));
ASSERT_EQ(rpLocalePattern, pattern);
}
/**