Bug 1342753 - Use app locale in DateTimeFormat.cpp, instead of OS locale. r=m_kato
authorZibi Braniecki <gandalf@mozilla.com>
Mon, 27 Feb 2017 09:36:50 -0800
changeset 394875 439f5e4ed073c9bc4e1dbc8d0f719e57ef6b1136
parent 394874 52fd963991ef5c677f9a5abdc47e8d3aa2eb6003
child 394876 2a8e33a5f238deb6d06871f4f2f4d9b83cd70d13
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1342753
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1342753 - Use app locale in DateTimeFormat.cpp, instead of OS locale. r=m_kato MozReview-Commit-ID: SPsNYxe493
intl/locale/DateTimeFormat.cpp
--- a/intl/locale/DateTimeFormat.cpp
+++ b/intl/locale/DateTimeFormat.cpp
@@ -2,49 +2,36 @@
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DateTimeFormat.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
-#include "nsILocaleService.h"
+#include "mozilla/intl/LocaleService.h"
 #include "unicode/udatpg.h"
 
 namespace mozilla {
 
 nsCString* DateTimeFormat::mLocale = nullptr;
 
 /*static*/ nsresult
 DateTimeFormat::Initialize()
 {
-  nsAutoString localeStr;
-  nsresult rv = NS_OK;
-
-  if (!mLocale) {
-    mLocale = new nsCString();
-  } else if (!mLocale->IsEmpty()) {
+  if (mLocale) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsILocaleService> localeService =
-           do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
-  if (NS_SUCCEEDED(rv)) {
-    nsCOMPtr<nsILocale> appLocale;
-    rv = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
-    if (NS_SUCCEEDED(rv)) {
-      rv = appLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr);
-      if (NS_SUCCEEDED(rv) && !localeStr.IsEmpty()) {
-        *mLocale = NS_LossyConvertUTF16toASCII(localeStr); // cache locale name
-      }
-    }
-  }
+  mLocale = new nsCString();
+  nsAutoCString locale;
+  intl::LocaleService::GetInstance()->GetAppLocale(locale);
+  mLocale->Assign(locale);
 
-  return rv;
+  return NS_OK;
 }
 
 // performs a locale sensitive date formatting operation on the time_t parameter
 /*static*/ nsresult
 DateTimeFormat::FormatTime(const nsDateFormatSelector aDateFormatSelector,
                            const nsTimeFormatSelector aTimeFormatSelector,
                            const time_t aTimetTime,
                            nsAString& aStringOut)