Implement functions to get localized long/short dayofweek name and short month name in BDateFormat.
Signed-off-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
f2c460497c
commit
bb3ad41ada
@@ -71,7 +71,10 @@ public:
|
||||
) const;
|
||||
|
||||
status_t GetStartOfWeek(BWeekday* weekday) const;
|
||||
status_t GetMonthName(int month, BString& outName);
|
||||
status_t GetMonthName(int month, BString& outName,
|
||||
const BDateFormatStyle style) const;
|
||||
status_t GetDayName(int day, BString& outName,
|
||||
const BDateFormatStyle style) const;
|
||||
|
||||
// parsing
|
||||
|
||||
|
||||
@@ -27,6 +27,14 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
static const DateFormatSymbols::DtWidthType kDateFormatStyleToWidth[] = {
|
||||
DateFormatSymbols::WIDE,
|
||||
DateFormatSymbols::ABBREVIATED,
|
||||
DateFormatSymbols::SHORT,
|
||||
DateFormatSymbols::NARROW,
|
||||
};
|
||||
|
||||
|
||||
BDateFormat::BDateFormat(const BLocale* locale)
|
||||
: BFormat(locale)
|
||||
{
|
||||
@@ -298,8 +306,12 @@ BDateFormat::GetStartOfWeek(BWeekday* startOfWeek) const
|
||||
|
||||
|
||||
status_t
|
||||
BDateFormat::GetMonthName(int month, BString& outName)
|
||||
BDateFormat::GetMonthName(int month, BString& outName,
|
||||
const BDateFormatStyle style) const
|
||||
{
|
||||
if (style < 0 || style >= B_DATE_FORMAT_STYLE_COUNT)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
DateFormat* format = _CreateDateFormatter(B_LONG_DATE_FORMAT);
|
||||
|
||||
SimpleDateFormat* simpleFormat = dynamic_cast<SimpleDateFormat*>(format);
|
||||
@@ -311,7 +323,8 @@ BDateFormat::GetMonthName(int month, BString& outName)
|
||||
const DateFormatSymbols* symbols = simpleFormat->getDateFormatSymbols();
|
||||
|
||||
int32_t count;
|
||||
const UnicodeString* names = symbols->getMonths(count);
|
||||
const UnicodeString* names = symbols->getMonths(count,
|
||||
DateFormatSymbols::STANDALONE, kDateFormatStyleToWidth[style]);
|
||||
|
||||
if (month > count || month <= 0) {
|
||||
delete simpleFormat;
|
||||
@@ -326,6 +339,40 @@ BDateFormat::GetMonthName(int month, BString& outName)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BDateFormat::GetDayName(int day, BString& outName,
|
||||
const BDateFormatStyle style) const
|
||||
{
|
||||
if (style < 0 || style >= B_DATE_FORMAT_STYLE_COUNT)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
DateFormat* format = _CreateDateFormatter(B_LONG_DATE_FORMAT);
|
||||
|
||||
SimpleDateFormat* simpleFormat = dynamic_cast<SimpleDateFormat*>(format);
|
||||
if (simpleFormat == NULL) {
|
||||
delete format;
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
const DateFormatSymbols* symbols = simpleFormat->getDateFormatSymbols();
|
||||
|
||||
int32_t count;
|
||||
const UnicodeString* names = symbols->getWeekdays(count,
|
||||
DateFormatSymbols::STANDALONE, kDateFormatStyleToWidth[style]);
|
||||
|
||||
if (day >= count || day <= 0) {
|
||||
delete simpleFormat;
|
||||
return B_BAD_DATA;
|
||||
}
|
||||
|
||||
BStringByteSink stringConverter(&outName);
|
||||
names[day].toUTF8(stringConverter);
|
||||
|
||||
delete simpleFormat;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BDateFormat::Parse(BString source, BDateFormatStyle style, BDate& output)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user