mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1225696 - Part 1. Add kDateFormatMonthLong and kDateFormatYearMonthLong to DateTimeFormat. r=emk
MozReview-Commit-ID: CT2Gzd0AEXb --HG-- extra : rebase_source : 6b98c53f5a88e38cd19081b8a2559685a69ecc36
This commit is contained in:
parent
e370cc3706
commit
5ad41e1593
@ -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) {
|
||||
|
@ -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)
|
||||
};
|
||||
%}
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user