зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
e370cc3706
Коммит
5ad41e1593
|
@ -107,6 +107,8 @@ DateTimeFormat::FormatUDateTime(const nsDateFormatSelector aDateFormatSelector,
|
||||||
dateStyle = UDAT_SHORT;
|
dateStyle = UDAT_SHORT;
|
||||||
break;
|
break;
|
||||||
case kDateFormatYearMonth:
|
case kDateFormatYearMonth:
|
||||||
|
case kDateFormatYearMonthLong:
|
||||||
|
case kDateFormatMonthLong:
|
||||||
case kDateFormatWeekday:
|
case kDateFormatWeekday:
|
||||||
dateStyle = UDAT_PATTERN;
|
dateStyle = UDAT_PATTERN;
|
||||||
break;
|
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();
|
int32_t dateSkeletonLen = skeleton.Length();
|
||||||
|
|
||||||
if (timeStyle != UDAT_NONE) {
|
if (timeStyle != UDAT_NONE) {
|
||||||
|
|
|
@ -13,6 +13,8 @@ enum
|
||||||
kDateFormatLong, // provides the long date format for the given locale
|
kDateFormatLong, // provides the long date format for the given locale
|
||||||
kDateFormatShort, // provides the short date format for the given locale
|
kDateFormatShort, // provides the short date format for the given locale
|
||||||
kDateFormatYearMonth, // formats using only the year and month
|
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)
|
kDateFormatWeekday // week day (e.g. Mon, Tue)
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -58,6 +58,14 @@ TEST(DateTimeFormat, DateFormatSelectors) {
|
||||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||||
ASSERT_STREQ("01/1970", NS_ConvertUTF16toUTF8(formattedTime).get());
|
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);
|
rv = mozilla::DateTimeFormat::FormatPRExplodedTime(kDateFormatYearMonth, kTimeFormatNoSeconds, &prExplodedTime, formattedTime);
|
||||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||||
ASSERT_STREQ("01/1970, 12:00 AM", NS_ConvertUTF16toUTF8(formattedTime).get());
|
ASSERT_STREQ("01/1970, 12:00 AM", NS_ConvertUTF16toUTF8(formattedTime).get());
|
||||||
|
|
Загрузка…
Ссылка в новой задаче