From 5ad41e15930a1fec08ec6651928384b9927ec998 Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Mon, 20 Feb 2017 12:47:18 +0900 Subject: [PATCH] Bug 1225696 - Part 1. Add kDateFormatMonthLong and kDateFormatYearMonthLong to DateTimeFormat. r=emk MozReview-Commit-ID: CT2Gzd0AEXb --HG-- extra : rebase_source : 6b98c53f5a88e38cd19081b8a2559685a69ecc36 --- intl/locale/DateTimeFormat.cpp | 20 ++++++++++++++++++- intl/locale/nsIScriptableDateFormat.idl | 2 ++ .../locale/tests/gtest/TestDateTimeFormat.cpp | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/intl/locale/DateTimeFormat.cpp b/intl/locale/DateTimeFormat.cpp index 69822a90dc69..c558a0a75443 100644 --- a/intl/locale/DateTimeFormat.cpp +++ b/intl/locale/DateTimeFormat.cpp @@ -107,6 +107,8 @@ DateTimeFormat::FormatUDateTime(const nsDateFormatSelector aDateFormatSelector, dateStyle = UDAT_SHORT; break; case kDateFormatYearMonth: + case kDateFormatYearMonthLong: + case kDateFormatMonthLong: case kDateFormatWeekday: dateStyle = UDAT_PATTERN; break; @@ -169,7 +171,23 @@ DateTimeFormat::FormatUDateTime(const nsDateFormatSelector aDateFormatSelector, } } - 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) { diff --git a/intl/locale/nsIScriptableDateFormat.idl b/intl/locale/nsIScriptableDateFormat.idl index 6bd47037b349..f138d1eaab49 100644 --- a/intl/locale/nsIScriptableDateFormat.idl +++ b/intl/locale/nsIScriptableDateFormat.idl @@ -13,6 +13,8 @@ enum 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) }; %} diff --git a/intl/locale/tests/gtest/TestDateTimeFormat.cpp b/intl/locale/tests/gtest/TestDateTimeFormat.cpp index 5f2e20c7967d..a433961049fe 100644 --- a/intl/locale/tests/gtest/TestDateTimeFormat.cpp +++ b/intl/locale/tests/gtest/TestDateTimeFormat.cpp @@ -58,6 +58,14 @@ TEST(DateTimeFormat, DateFormatSelectors) { 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());