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:
@@ -61,8 +61,12 @@ BDateTimeFormat::SetDateTimeFormat(BDateFormatStyle dateStyle,
|
|||||||
skeleton << "dd";
|
skeleton << "dd";
|
||||||
if (elements & B_DATE_ELEMENT_AM_PM)
|
if (elements & B_DATE_ELEMENT_AM_PM)
|
||||||
skeleton << "a";
|
skeleton << "a";
|
||||||
if (elements & B_DATE_ELEMENT_HOUR)
|
if (elements & B_DATE_ELEMENT_HOUR) {
|
||||||
skeleton << "jj";
|
if (fConventions.Use24HourClock())
|
||||||
|
skeleton << "HH";
|
||||||
|
else
|
||||||
|
skeleton << "KK";
|
||||||
|
}
|
||||||
if (elements & B_DATE_ELEMENT_MINUTE)
|
if (elements & B_DATE_ELEMENT_MINUTE)
|
||||||
skeleton << "mm";
|
skeleton << "mm";
|
||||||
if (elements & B_DATE_ELEMENT_SECOND)
|
if (elements & B_DATE_ELEMENT_SECOND)
|
||||||
|
|||||||
@@ -28,15 +28,34 @@ DateFormatTest::~DateFormatTest()
|
|||||||
void
|
void
|
||||||
DateFormatTest::TestCustomFormat()
|
DateFormatTest::TestCustomFormat()
|
||||||
{
|
{
|
||||||
int32 fields = B_DATE_ELEMENT_HOUR | B_DATE_ELEMENT_MINUTE;
|
|
||||||
BDateTimeFormat format;
|
|
||||||
BString buffer;
|
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);
|
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);
|
B_SHORT_TIME_FORMAT);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(B_OK, result);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user