mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
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:
parent
07faffeb7b
commit
0790cac85a
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user