Bug 1225696 - Part 1. Add kDateFormatMonthLong and kDateFormatYearMonthLong to DateTimeFormat. r=emk
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 20 Feb 2017 12:47:18 +0900
changeset 392817 87908aced1112d2fe469d2042ce8ce22e72a7f34
parent 392816 87d88eed04b26d799285a287a06fac287e2a88e6
child 392818 b10f3f8d8d7776b38308825738db5f6a4b10fc54
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)
reviewersemk
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 1. Add kDateFormatMonthLong and kDateFormatYearMonthLong to DateTimeFormat. r=emk MozReview-Commit-ID: CT2Gzd0AEXb
intl/locale/DateTimeFormat.cpp
intl/locale/nsIScriptableDateFormat.idl
intl/locale/tests/gtest/TestDateTimeFormat.cpp
--- a/intl/locale/DateTimeFormat.cpp
+++ b/intl/locale/DateTimeFormat.cpp
@@ -102,16 +102,18 @@ DateTimeFormat::FormatUDateTime(const ns
   switch (aDateFormatSelector) {
     case kDateFormatLong:
       dateStyle = UDAT_LONG;
       break;
     case kDateFormatShort:
       dateStyle = UDAT_SHORT;
       break;
     case kDateFormatYearMonth:
+    case kDateFormatYearMonthLong:
+    case kDateFormatMonthLong:
     case kDateFormatWeekday:
       dateStyle = UDAT_PATTERN;
       break;
     case kDateFormatNone:
       dateStyle = UDAT_NONE;
       break;
     default:
       NS_ERROR("Unknown nsDateFormatSelector");
@@ -164,17 +166,33 @@ DateTimeFormat::FormatUDateTime(const ns
         pattern.SetLength(patternLength);
 
         if (status == U_BUFFER_OVERFLOW_ERROR) {
           status = U_ZERO_ERROR;
           udat_toPattern(dateTimeFormat, FALSE, reinterpret_cast<UChar*>(pattern.BeginWriting()), patternLength, &status);
         }
       }
 
-      nsAutoString skeleton(aDateFormatSelector == kDateFormatYearMonth ? u"yyyyMM " : u"EEE ");
+      nsAutoString skeleton;
+      switch (aDateFormatSelector) {
+      case kDateFormatYearMonth:
+        skeleton.AssignLiteral("yyyyMM ");
+        break;
+      case kDateFormatYearMonthLong:
+        skeleton.AssignLiteral("yyyyMMMM ");
+        break;
+      case kDateFormatMonthLong:
+        skeleton.AssignLiteral("MMMM ");
+        break;
+      case kDateFormatWeekday:
+        skeleton.AssignLiteral("EEE ");
+        break;
+      default:
+        break;
+      }
       int32_t dateSkeletonLen = skeleton.Length();
 
       if (timeStyle != UDAT_NONE) {
         skeleton.SetLength(DATETIME_FORMAT_INITIAL_LEN);
         int32_t skeletonLength = udatpg_getSkeleton(nullptr, reinterpret_cast<const UChar*>(pattern.BeginReading()), patternLength,
           reinterpret_cast<UChar*>(skeleton.BeginWriting() + dateSkeletonLen), DATETIME_FORMAT_INITIAL_LEN - dateSkeletonLen, &status);
         skeleton.SetLength(dateSkeletonLen + skeletonLength);
 
--- a/intl/locale/nsIScriptableDateFormat.idl
+++ b/intl/locale/nsIScriptableDateFormat.idl
@@ -8,16 +8,18 @@
 typedef long nsDateFormatSelector;
 %{ C++
 enum
 {
     kDateFormatNone = 0,            // do not include the date  in the format string
     kDateFormatLong,                // provides the long date format for the given locale
     kDateFormatShort,               // provides the short date format for the given locale
     kDateFormatYearMonth,           // formats using only the year and month 
+    kDateFormatYearMonthLong,       // long version of kDateFormatYearMonth
+    kDateFormatMonthLong,           // long format of month name only
     kDateFormatWeekday              // week day (e.g. Mon, Tue)
 };
 %}
 
 typedef long nsTimeFormatSelector;
 %{ C++
 enum
 {
--- a/intl/locale/tests/gtest/TestDateTimeFormat.cpp
+++ b/intl/locale/tests/gtest/TestDateTimeFormat.cpp
@@ -53,16 +53,24 @@ TEST(DateTimeFormat, DateFormatSelectors
 
   mozilla::DateTimeFormat::mLocale = new nsCString("en-US");
 
   nsAutoString formattedTime;
   nsresult rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonth, kTimeFormatNone, &prExplodedTime, formattedTime);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   ASSERT_STREQ("01/1970", NS_ConvertUTF16toUTF8(formattedTime).get());
 
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonthLong, kTimeFormatNone, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("January 1970", NS_ConvertUTF16toUTF8(formattedTime).get());
+
+  rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatMonthLong, kTimeFormatNone, &prExplodedTime, formattedTime);
+  ASSERT_TRUE(NS_SUCCEEDED(rv));
+  ASSERT_STREQ("January", NS_ConvertUTF16toUTF8(formattedTime).get());
+
   rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonth, kTimeFormatNoSeconds, &prExplodedTime, formattedTime);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   ASSERT_STREQ("01/1970, 12:00 AM", NS_ConvertUTF16toUTF8(formattedTime).get());
 
   rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonth, kTimeFormatSeconds, &prExplodedTime, formattedTime);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
   ASSERT_STREQ("01/1970, 12:00:00 AM", NS_ConvertUTF16toUTF8(formattedTime).get());