Bug 441167 – nsIScriptableDateFormat defaults to OS locale but should be application locale. r=smontagu

This commit is contained in:
Jesper Kristensen 2008-07-12 12:26:13 +02:00
parent 557bc969d3
commit caf15f7e6e

View File

@ -46,6 +46,7 @@
#include "nsIScriptableDateFormat.h"
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "nsIPrefService.h"
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
@ -114,14 +115,19 @@ NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime(
nsCOMPtr<nsILocale> locale;
// re-initialise locale pointer only if the locale was given explicitly
if (!localeName.IsEmpty()) {
// get locale service
nsCOMPtr<nsILocaleService> localeService(do_GetService(kLocaleServiceCID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
// get locale
rv = localeService->NewLocale(localeName, getter_AddRefs(locale));
if (localeName.IsEmpty()) {
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCString cLocaleName;
rv = prefs->GetCharPref("general.useragent.locale", getter_Copies(cLocaleName));
CopyUTF8toUTF16(cLocaleName, localeName);
}
// get locale service
nsCOMPtr<nsILocaleService> localeService(do_GetService(kLocaleServiceCID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
// get locale
rv = localeService->NewLocale(localeName, getter_AddRefs(locale));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDateTimeFormat> dateTimeFormat(do_CreateInstance(kDateTimeFormatCID, &rv));
NS_ENSURE_SUCCESS(rv, rv);