Bug 620627 PlacesSQLQueryBuilder::SelectAsDay() is not l12y friendly.
authortimeless@mozdev.org
Thu, 28 Apr 2011 19:55:06 +0200
changeset 68760 cbf8fa67dd5bcc43871f26c4c09f6a0c73565178
parent 68759 a6ef6163855d753c780718a0f049bcc981fd7c61
child 68761 18d8734519e7eba62e8a86bca9535e0ac578bce3
push idunknown
push userunknown
push dateunknown
bugs620627
milestone6.0a1
Bug 620627 PlacesSQLQueryBuilder::SelectAsDay() is not l12y friendly. Further modified by Marco Bonardo (f=gandalf) r=mak
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/nsNavHistory.h
toolkit/locales/en-US/chrome/places/places.properties
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -3265,19 +3265,19 @@ PlacesSQLQueryBuilder::SelectAsDay()
   // insert position in a result.
   mQueryString = nsPrintfCString(1024,
      "SELECT null, "
        "'place:type=%ld&sort=%ld&beginTime='||beginTime||'&endTime='||endTime, "
       "dayTitle, null, null, beginTime, null, null, null, null, null, null "
      "FROM (", // TOUTER BEGIN
      resultType,
      sortingMode);
- 
-   nsNavHistory *history = nsNavHistory::GetHistoryService();
-   NS_ENSURE_STATE(history);
+
+  nsNavHistory *history = nsNavHistory::GetHistoryService();
+  NS_ENSURE_STATE(history);
 
   PRInt32 daysOfHistory = history->GetDaysOfHistory();
   for (PRInt32 i = 0; i <= HISTORY_DATE_CONT_NUM(daysOfHistory); i++) {
     nsCAutoString dateName;
     // Timeframes are calculated as BeginTime <= container < EndTime.
     // Notice times can't be relative to now, since to recognize a query we
     // must ensure it won't change based on the time it is built.
     // So, to select till now, we really select till start of tomorrow, that is
@@ -3375,22 +3375,25 @@ PlacesSQLQueryBuilder::SelectAsDay()
         // Also, we use day 2 instead of day 1, so that the GMT month is always
         // the same as the local month. (Bug 603002)
         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);
-        // tm_month starts from 0 while GetMonthName expects a 1-based index.
-        history->GetMonthName(tm.tm_month+1, dateName);
-
-        // If the container is for a past year, add the year as suffix.
-        if (tm.tm_year < currentYear)
-          dateName.Append(nsPrintfCString(" %d", tm.tm_year));
+        // 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);
+        }
+        else {
+          history->GetMonthName(tm.tm_month + 1, 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)"));
         // To start of MonthIndex months ago
@@ -6684,16 +6687,41 @@ nsNavHistory::GetMonthName(PRInt32 aInde
     if (NS_SUCCEEDED(rv)) {
       CopyUTF16toUTF8(value, aResult);
       return;
     }
   }
   aResult = nsPrintfCString("[%d]", aIndex);
 }
 
+void
+nsNavHistory::GetMonthYear(PRInt32 aMonth, PRInt32 aYear, nsACString& aResult)
+{
+  nsIStringBundle *bundle = GetBundle();
+  if (bundle) {
+    nsCAutoString monthName;
+    GetMonthName(aMonth, monthName);
+    nsAutoString yearString;
+    yearString.AppendInt(aYear);
+    const PRUnichar* strings[2] = {
+      NS_ConvertUTF8toUTF16(monthName).get()
+    , yearString.get()
+    };
+    nsXPIDLString value;
+    if (NS_SUCCEEDED(bundle->FormatStringFromName(
+          NS_LITERAL_STRING("finduri-MonthYear").get(), strings, 2,
+          getter_Copies(value)
+        ))) {
+      CopyUTF16toUTF8(value, aResult);
+      return;
+    }
+  }
+  aResult.AppendLiteral("finduri-MonthYear");
+}
+
 // nsNavHistory::SetPageTitleInternal
 //
 //    Called to set the title for the given URI. Used as a
 //    backend for SetTitle.
 //
 //    Will fail for pages that are not in the DB. To clear the corresponding
 //    title, use aTitle.SetIsVoid(). Sending an empty string will save an
 //    empty string instead of clearing it.
--- a/toolkit/components/places/nsNavHistory.h
+++ b/toolkit/components/places/nsNavHistory.h
@@ -276,16 +276,17 @@ public:
    */
   nsIStringBundle* GetBundle();
   nsIStringBundle* GetDateFormatBundle();
   nsICollation* GetCollation();
   void GetStringFromName(const PRUnichar* aName, nsACString& aResult);
   void GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName,
                           nsACString& aResult);
   void GetMonthName(PRInt32 aIndex, nsACString& aResult);
+  void GetMonthYear(PRInt32 aMonth, PRInt32 aYear, nsACString& aResult);
 
   // Returns whether history is enabled or not.
   PRBool IsHistoryDisabled() {
     return !mHistoryEnabled || InPrivateBrowsingMode();
   }
 
   // Constants for the columns returned by the above statement.
   static const PRInt32 kGetInfoIndex_PageID;
--- a/toolkit/locales/en-US/chrome/places/places.properties
+++ b/toolkit/locales/en-US/chrome/places/places.properties
@@ -7,16 +7,19 @@ TagsFolderTitle=Tags
 # 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 (bookmarksArchiveFilename):
 # Do not change this string! It's used only to
 # detect older localized bookmark archives from