DateTimeFormat: handle custom 24 hours clock.
The "j" format pattern selects a 12 or 24 hours clock automatically depending on the locale, but it doesn't work when the format is forced in the locale preflet or through the BFormattingConventions API. So we manually pick either K or H depending on that setting.
This commit is contained in:
parent
7fe7ce6748
commit
824cb460ac
@ -61,8 +61,12 @@ BDateTimeFormat::SetDateTimeFormat(BDateFormatStyle dateStyle,
|
||||
skeleton << "dd";
|
||||
if (elements & B_DATE_ELEMENT_AM_PM)
|
||||
skeleton << "a";
|
||||
if (elements & B_DATE_ELEMENT_HOUR)
|
||||
skeleton << "jj";
|
||||
if (elements & B_DATE_ELEMENT_HOUR) {
|
||||
if (fConventions.Use24HourClock())
|
||||
skeleton << "HH";
|
||||
else
|
||||
skeleton << "KK";
|
||||
}
|
||||
if (elements & B_DATE_ELEMENT_MINUTE)
|
||||
skeleton << "mm";
|
||||
if (elements & B_DATE_ELEMENT_SECOND)
|
||||
|
@ -28,15 +28,34 @@ DateFormatTest::~DateFormatTest()
|
||||
void
|
||||
DateFormatTest::TestCustomFormat()
|
||||
{
|
||||
int32 fields = B_DATE_ELEMENT_HOUR | B_DATE_ELEMENT_MINUTE;
|
||||
BDateTimeFormat format;
|
||||
BString buffer;
|
||||
BLanguage language("en");
|
||||
BFormattingConventions formatting("en_US");
|
||||
int32 fields = B_DATE_ELEMENT_HOUR | B_DATE_ELEMENT_MINUTE;
|
||||
|
||||
BDateTimeFormat format(&language, &formatting);
|
||||
|
||||
NextSubTest();
|
||||
|
||||
formatting.SetExplicitUse24HourClock(true);
|
||||
format.SetFormattingConventions(formatting);
|
||||
format.SetDateTimeFormat(B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT, fields);
|
||||
status_t result = format.Format(buffer, 12345, B_SHORT_DATE_FORMAT,
|
||||
status_t result = format.Format(buffer, 12345678, B_SHORT_DATE_FORMAT,
|
||||
B_SHORT_TIME_FORMAT);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(B_OK, result);
|
||||
CPPUNIT_ASSERT_EQUAL(BString("04:25"), buffer);
|
||||
CPPUNIT_ASSERT_EQUAL(BString("22:21"), buffer);
|
||||
|
||||
NextSubTest();
|
||||
|
||||
formatting.SetExplicitUse24HourClock(false);
|
||||
format.SetFormattingConventions(formatting);
|
||||
format.SetDateTimeFormat(B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT, fields);
|
||||
result = format.Format(buffer, 12345678, B_SHORT_DATE_FORMAT,
|
||||
B_SHORT_TIME_FORMAT);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(B_OK, result);
|
||||
CPPUNIT_ASSERT_EQUAL(BString("10:21 PM"), buffer);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user