Bug 1426907 - Call OSPreferences::GetDateTimePattern once in FormatUDateTime; r=zbraniecki
authorDan Minor <dminor@mozilla.com>
Tue, 27 Oct 2020 20:43:25 +0000
changeset 554794 4602056737ce4a30f9ffb8572f43259307e04d61
parent 554793 7774282861fedcc4b82f40eb221dafede074cb91
child 554795 e1137eef3ae34db7527e4c9c2213167b148224f3
push id37898
push userabutkovits@mozilla.com
push dateWed, 28 Oct 2020 09:24:21 +0000
treeherdermozilla-central@83bf4fd3b1fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszbraniecki
bugs1426907
milestone84.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 1426907 - Call OSPreferences::GetDateTimePattern once in FormatUDateTime; r=zbraniecki Now that we've removed a lot of the special cases we were supporting in the date and time format selectors, we can call GetDateTimePattern once with the two selectors instead of calling it twice and combining the results. This will simplifies the code and will make it easier to handle overriding patterns using prefs. A side effect of this change is that on OS X, you get a slightly different result if you ask for the long format date and time all at once than if you ask for the two separately and then combine them. The test expectations have been updated accordingly. Differential Revision: https://phabricator.services.mozilla.com/D94431
intl/locale/DateTimeFormat.cpp
--- a/intl/locale/DateTimeFormat.cpp
+++ b/intl/locale/DateTimeFormat.cpp
@@ -268,77 +268,53 @@ nsresult DateTimeFormat::FormatUDateTime
         new nsDataHashtable<nsCStringHashKey, UDateFormat*>(kMaxCachedFormats);
   }
 
   UDateFormat*& dateTimeFormat = mFormatCache->GetOrInsert(key);
 
   if (!dateTimeFormat) {
     // We didn't have a cached formatter for this key, so create one.
 
-    // Get the date style for the formatter.
-    nsAutoString patternDate;
+    nsAutoString pattern;
+    int32_t dateFormatStyle;
     switch (aDateFormatSelector) {
       case kDateFormatLong:
-        rv = OSPreferences::GetInstance()->GetDateTimePattern(
-            mozIOSPreferences::dateTimeFormatStyleLong,
-            mozIOSPreferences::dateTimeFormatStyleNone,
-            nsDependentCString(mLocale->get()), patternDate);
-        NS_ENSURE_SUCCESS(rv, rv);
+        dateFormatStyle = mozIOSPreferences::dateTimeFormatStyleLong;
         break;
       case kDateFormatShort:
-        rv = OSPreferences::GetInstance()->GetDateTimePattern(
-            mozIOSPreferences::dateTimeFormatStyleShort,
-            mozIOSPreferences::dateTimeFormatStyleNone,
-            nsDependentCString(mLocale->get()), patternDate);
-        NS_ENSURE_SUCCESS(rv, rv);
+        dateFormatStyle = mozIOSPreferences::dateTimeFormatStyleShort;
         break;
       case kDateFormatNone:
+        dateFormatStyle = mozIOSPreferences::dateTimeFormatStyleNone;
         break;
       default:
         NS_ERROR("Unknown nsDateFormatSelector");
         return NS_ERROR_ILLEGAL_VALUE;
     }
 
-    // Get the time style for the formatter.
-    nsAutoString patternTime;
+    int32_t timeFormatStyle;
     switch (aTimeFormatSelector) {
       case kTimeFormatLong:
-        rv = OSPreferences::GetInstance()->GetDateTimePattern(
-            mozIOSPreferences::dateTimeFormatStyleNone,
-            mozIOSPreferences::dateTimeFormatStyleLong,
-            nsDependentCString(mLocale->get()), patternTime);
-        NS_ENSURE_SUCCESS(rv, rv);
+        timeFormatStyle = mozIOSPreferences::dateTimeFormatStyleLong;
         break;
       case kTimeFormatShort:
-        rv = OSPreferences::GetInstance()->GetDateTimePattern(
-            mozIOSPreferences::dateTimeFormatStyleNone,
-            mozIOSPreferences::dateTimeFormatStyleShort,
-            nsDependentCString(mLocale->get()), patternTime);
-        NS_ENSURE_SUCCESS(rv, rv);
+        timeFormatStyle = mozIOSPreferences::dateTimeFormatStyleShort;
         break;
       case kTimeFormatNone:
+        timeFormatStyle = mozIOSPreferences::dateTimeFormatStyleNone;
         break;
       default:
-        NS_ERROR("Unknown nsTimeFormatSelector");
+        NS_ERROR("Unknown nsDateFormatSelector");
         return NS_ERROR_ILLEGAL_VALUE;
     }
 
-    nsAutoString pattern;
-    if (patternTime.Length() == 0) {
-      pattern.Assign(patternDate);
-    } else if (patternDate.Length() == 0) {
-      pattern.Assign(patternTime);
-    } else {
-      OSPreferences::GetDateTimeConnectorPattern(
-          nsDependentCString(mLocale->get()), pattern);
-      int32_t index = pattern.Find("{1}");
-      if (index != kNotFound) pattern.Replace(index, 3, patternDate);
-      index = pattern.Find("{0}");
-      if (index != kNotFound) pattern.Replace(index, 3, patternTime);
-    }
+    rv = OSPreferences::GetInstance()->GetDateTimePattern(
+        dateFormatStyle, timeFormatStyle, nsDependentCString(mLocale->get()),
+        pattern);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     if (aTimeParameters) {
       nsAutoString timeZoneID;
       BuildTimeZoneString(*aTimeParameters, timeZoneID);
 
       dateTimeFormat =
           udat_open(UDAT_PATTERN, UDAT_PATTERN, mLocale->get(),
                     reinterpret_cast<const UChar*>(timeZoneID.BeginReading()),