Bug 1225696 - Part 2. Use DateTimeFormat instead of dateFormat.properties. r=mak
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 20 Feb 2017 14:22:21 +0900
changeset 343841 b10f3f8d8d7776b38308825738db5f6a4b10fc54
parent 343840 87908aced1112d2fe469d2042ce8ce22e72a7f34
child 343842 515db19cf5294128cc07208636ec9b582be0f203
push id31388
push usercbook@mozilla.com
push dateMon, 20 Feb 2017 13:05:44 +0000
treeherdermozilla-central@24931c1b6d9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1225696
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 1225696 - Part 2. Use DateTimeFormat instead of dateFormat.properties. r=mak MozReview-Commit-ID: 9ufUVeppwHk
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/nsNavHistory.h
toolkit/locales/en-US/chrome/global/dateFormat.properties
toolkit/locales/en-US/chrome/places/places.properties
toolkit/locales/jar.mn
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -12,16 +12,17 @@
 
 #include "nsNavHistory.h"
 
 #include "mozIPlacesAutoComplete.h"
 #include "nsNavBookmarks.h"
 #include "nsAnnotationService.h"
 #include "nsFaviconService.h"
 #include "nsPlacesMacros.h"
+#include "DateTimeFormat.h"
 #include "History.h"
 #include "Helpers.h"
 
 #include "nsTArray.h"
 #include "nsCollationCID.h"
 #include "nsNetUtil.h"
 #include "nsPrintfCString.h"
 #include "nsPromiseFlatString.h"
@@ -1749,22 +1750,21 @@ PlacesSQLQueryBuilder::SelectAsDay()
         tm.tm_mday = 2;
         tm.tm_month -= MonthIndex;
         // Notice we use GMTParameters because we just want to get the first
         // day of each month.  Using LocalTimeParameters would instead force us
         // to apply a DST correction that we don't really need here.
         PR_NormalizeTime(&tm, PR_GMTParameters);
         // If the container is for a past year, add the year to its title,
         // otherwise just show the month name.
-        // Note that tm_month starts from 0, while we need a 1-based index.
         if (tm.tm_year < currentYear) {
-          history->GetMonthYear(tm.tm_month + 1, tm.tm_year, dateName);
+          nsNavHistory::GetMonthYear(tm, dateName);
         }
         else {
-          history->GetMonthName(tm.tm_month + 1, dateName);
+          nsNavHistory::GetMonthName(tm, dateName);
         }
 
         // From start of MonthIndex + 1 months ago
         sqlFragmentContainerBeginTime = NS_LITERAL_CSTRING(
           "(strftime('%s','now','localtime','start of month','-");
         sqlFragmentContainerBeginTime.AppendInt(MonthIndex);
         sqlFragmentContainerBeginTime.Append(NS_LITERAL_CSTRING(
             " months','utc')*1000000)"));
@@ -4205,56 +4205,46 @@ nsNavHistory::GetStringFromName(const ch
     if (NS_SUCCEEDED(rv)) {
       CopyUTF16toUTF8(value, aResult);
       return;
     }
   }
   CopyUTF16toUTF8(nsDependentString(aName), aResult);
 }
 
+// static
 void
-nsNavHistory::GetMonthName(int32_t aIndex, nsACString& aResult)
-{
-  nsIStringBundle *bundle = GetDateFormatBundle();
-  if (bundle) {
-    nsCString name = nsPrintfCString("month.%d.name", aIndex);
-    nsXPIDLString value;
-    nsresult rv = bundle->GetStringFromName(NS_ConvertUTF8toUTF16(name).get(),
-                                            getter_Copies(value));
-    if (NS_SUCCEEDED(rv)) {
-      CopyUTF16toUTF8(value, aResult);
-      return;
-    }
-  }
-  aResult = nsPrintfCString("[%d]", aIndex);
-}
-
-void
-nsNavHistory::GetMonthYear(int32_t aMonth, int32_t aYear, nsACString& aResult)
+nsNavHistory::GetMonthName(const PRExplodedTime& aTime, nsACString& aResult)
 {
-  nsIStringBundle *bundle = GetBundle();
-  if (bundle) {
-    nsAutoCString monthName;
-    GetMonthName(aMonth, monthName);
-    nsAutoString yearString;
-    yearString.AppendInt(aYear);
-    const char16_t* strings[2] = {
-      NS_ConvertUTF8toUTF16(monthName).get()
-    , yearString.get()
-    };
-    nsXPIDLString value;
-    if (NS_SUCCEEDED(bundle->FormatStringFromName(
-          u"finduri-MonthYear", strings, 2,
-          getter_Copies(value)
-        ))) {
-      CopyUTF16toUTF8(value, aResult);
-      return;
-    }
+  nsAutoString month;
+  nsresult rv = DateTimeFormat::FormatPRExplodedTime(kDateFormatMonthLong,
+                                                     kTimeFormatNone,
+                                                     &aTime,
+                                                     month);
+  if (NS_FAILED(rv)) {
+    aResult = nsPrintfCString("[%d]", aTime.tm_month + 1);
+    return;
   }
-  aResult.AppendLiteral("finduri-MonthYear");
+  CopyUTF16toUTF8(month, aResult);
+}
+
+// static
+void
+nsNavHistory::GetMonthYear(const PRExplodedTime& aTime, nsACString& aResult)
+{
+  nsAutoString monthYear;
+  nsresult rv = DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonthLong,
+                                                     kTimeFormatNone,
+                                                     &aTime,
+                                                     monthYear);
+  if (NS_FAILED(rv)) {
+    aResult = nsPrintfCString("[%d-%d]", aTime.tm_month + 1, aTime.tm_year);
+    return;
+  }
+  CopyUTF16toUTF8(monthYear, aResult);
 }
 
 
 namespace {
 
 // GetSimpleBookmarksQueryFolder
 //
 //    Determines if this set of queries is a simple bookmarks query for a
@@ -4513,23 +4503,8 @@ nsNavHistory::GetBundle()
     NS_ENSURE_TRUE(bundleService, nullptr);
     nsresult rv = bundleService->CreateBundle(
         "chrome://places/locale/places.properties",
         getter_AddRefs(mBundle));
     NS_ENSURE_SUCCESS(rv, nullptr);
   }
   return mBundle;
 }
-
-nsIStringBundle *
-nsNavHistory::GetDateFormatBundle()
-{
-  if (!mDateFormatBundle) {
-    nsCOMPtr<nsIStringBundleService> bundleService =
-      services::GetStringBundleService();
-    NS_ENSURE_TRUE(bundleService, nullptr);
-    nsresult rv = bundleService->CreateBundle(
-        "chrome://global/locale/dateFormat.properties",
-        getter_AddRefs(mDateFormatBundle));
-    NS_ENSURE_SUCCESS(rv, nullptr);
-  }
-  return mDateFormatBundle;
-}
--- a/toolkit/components/places/nsNavHistory.h
+++ b/toolkit/components/places/nsNavHistory.h
@@ -203,23 +203,22 @@ public:
                                bool aWholeEntry, const nsACString& aGUID,
                                uint16_t aReason, uint32_t aTransitionType);
 
   /**
    * These functions return non-owning references to the locale-specific
    * objects for places components.
    */
   nsIStringBundle* GetBundle();
-  nsIStringBundle* GetDateFormatBundle();
   nsICollation* GetCollation();
   void GetStringFromName(const char16_t* aName, nsACString& aResult);
   void GetAgeInDaysString(int32_t aInt, const char16_t *aName,
                           nsACString& aResult);
-  void GetMonthName(int32_t aIndex, nsACString& aResult);
-  void GetMonthYear(int32_t aMonth, int32_t aYear, nsACString& aResult);
+  static void GetMonthName(const PRExplodedTime& aTime, nsACString& aResult);
+  static void GetMonthYear(const PRExplodedTime& aTime, nsACString& aResult);
 
   // Returns whether history is enabled or not.
   bool IsHistoryDisabled() {
     return !mHistoryEnabled;
   }
 
   // Constants for the columns returned by the above statement.
   static const int32_t kGetInfoIndex_PageID;
@@ -560,17 +559,16 @@ protected:
   nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers;
 
   // effective tld service
   nsCOMPtr<nsIEffectiveTLDService> mTLDService;
   nsCOMPtr<nsIIDNService>          mIDNService;
 
   // localization
   nsCOMPtr<nsIStringBundle> mBundle;
-  nsCOMPtr<nsIStringBundle> mDateFormatBundle;
   nsCOMPtr<nsICollation> mCollation;
 
   // recent events
   typedef nsDataHashtable<nsCStringHashKey, int64_t> RecentEventHash;
   RecentEventHash mRecentTyped;
   RecentEventHash mRecentLink;
   RecentEventHash mRecentBookmark;
 
deleted file mode 100644
--- a/toolkit/locales/en-US/chrome/global/dateFormat.properties
+++ /dev/null
@@ -1,58 +0,0 @@
-# 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/.
-
-month.1.Mmm=Jan
-month.2.Mmm=Feb
-month.3.Mmm=Mar
-month.4.Mmm=Apr
-month.5.Mmm=May
-month.6.Mmm=Jun
-month.7.Mmm=Jul
-month.8.Mmm=Aug
-month.9.Mmm=Sep
-month.10.Mmm=Oct
-month.11.Mmm=Nov
-month.12.Mmm=Dec
-
-month.1.name=January
-month.2.name=February
-month.3.name=March
-month.4.name=April
-month.5.name=May
-month.6.name=June
-month.7.name=July
-month.8.name=August
-month.9.name=September
-month.10.name=October
-month.11.name=November
-month.12.name=December
-
-day.1.name=Sunday
-day.2.name=Monday
-day.3.name=Tuesday
-day.4.name=Wednesday
-day.5.name=Thursday
-day.6.name=Friday
-day.7.name=Saturday
-
-day.1.Mmm=Sun
-day.2.Mmm=Mon
-day.3.Mmm=Tue
-day.4.Mmm=Wed
-day.5.Mmm=Thu
-day.6.Mmm=Fri
-day.7.Mmm=Sat
-
-day.1.short=Su
-day.2.short=Mo
-day.3.short=Tu
-day.4.short=We
-day.5.short=Th
-day.6.short=Fr
-day.7.short=Sa
-
-noon=Noon
-midnight=Midnight
-
-AllDay=All Day
--- a/toolkit/locales/en-US/chrome/places/places.properties
+++ b/toolkit/locales/en-US/chrome/places/places.properties
@@ -12,19 +12,16 @@ MobileBookmarksFolderTitle=Mobile Bookma
 # These are used to generate history containers when history is grouped by date
 finduri-AgeInDays-is-0=Today
 finduri-AgeInDays-is-1=Yesterday
 finduri-AgeInDays-is=%S days ago
 finduri-AgeInDays-last-is=Last %S days
 finduri-AgeInDays-isgreater=Older than %S days
 finduri-AgeInMonths-is-0=This month
 finduri-AgeInMonths-isgreater=Older than %S months
-# LOCALIZATION NOTE (finduri-MonthYear):
-# %1$S is the month name, %2$S is the year (4 digits format).
-finduri-MonthYear=%1$S %2$S
 
 # LOCALIZATION NOTE (localFiles):
 # This is used to generate local files container when history is grouped by site
 localhost=(local files)
 
 # LOCALIZATION NOTE
 # The string is used for showing file size of each backup in the "fileRestorePopup" popup
 # %1$S is the file size
--- a/toolkit/locales/jar.mn
+++ b/toolkit/locales/jar.mn
@@ -33,17 +33,16 @@
   locale/@AB_CD@/global/config.dtd                      (%chrome/global/config.dtd)
   locale/@AB_CD@/global/config.properties               (%chrome/global/config.properties)
   locale/@AB_CD@/global/contentAreaCommands.properties  (%chrome/global/contentAreaCommands.properties)
 #ifndef MOZ_FENNEC
   locale/@AB_CD@/global/customizeToolbar.dtd            (%chrome/global/customizeToolbar.dtd)
   locale/@AB_CD@/global/customizeToolbar.properties     (%chrome/global/customizeToolbar.properties)
 #endif
   locale/@AB_CD@/global/datetimepicker.dtd              (%chrome/global/datetimepicker.dtd)
-  locale/@AB_CD@/global/dateFormat.properties           (%chrome/global/dateFormat.properties)
   locale/@AB_CD@/global/dialogOverlay.dtd               (%chrome/global/dialogOverlay.dtd)
 #ifndef MOZ_FENNEC
   locale/@AB_CD@/global/editMenuOverlay.dtd             (%chrome/global/editMenuOverlay.dtd)
 #endif
   locale/@AB_CD@/global/extensions.properties           (%chrome/global/extensions.properties)
   locale/@AB_CD@/global/fallbackMenubar.properties      (%chrome/global/fallbackMenubar.properties)
   locale/@AB_CD@/global/filefield.properties            (%chrome/global/filefield.properties)
 #ifdef MOZ_GTK