[haiku-commits] haiku: hrev47981 - in src: tests/kits/locale kits/locale

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 8 Oct 2014 11:38:43 +0200 (CEST)

hrev47981 adds 1 changeset to branch 'master'
old head: 7fe7ce67487516f39aa10b8857726e97dee031f2
new head: 824cb460ac8ac243f8d0dd3c88e3d482df104599
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=824cb46+%5E7fe7ce6

----------------------------------------------------------------------------

824cb46: 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.

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev47981
Commit:      824cb460ac8ac243f8d0dd3c88e3d482df104599
URL:         http://cgit.haiku-os.org/haiku/commit/?id=824cb46
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Wed Oct  8 09:36:52 2014 UTC

----------------------------------------------------------------------------

2 files changed, 29 insertions(+), 6 deletions(-)
src/kits/locale/DateTimeFormat.cpp       |  8 ++++++--
src/tests/kits/locale/DateFormatTest.cpp | 27 +++++++++++++++++++++++----

----------------------------------------------------------------------------

diff --git a/src/kits/locale/DateTimeFormat.cpp 
b/src/kits/locale/DateTimeFormat.cpp
index 794edc1..eb4bcea 100644
--- a/src/kits/locale/DateTimeFormat.cpp
+++ b/src/kits/locale/DateTimeFormat.cpp
@@ -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)
diff --git a/src/tests/kits/locale/DateFormatTest.cpp 
b/src/tests/kits/locale/DateFormatTest.cpp
index 0eb96ff..733282d 100644
--- a/src/tests/kits/locale/DateFormatTest.cpp
+++ b/src/tests/kits/locale/DateFormatTest.cpp
@@ -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, 12345678, B_SHORT_DATE_FORMAT,
+               B_SHORT_TIME_FORMAT);
+
+       CPPUNIT_ASSERT_EQUAL(B_OK, result);
+       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);
-       status_t result = format.Format(buffer, 12345, B_SHORT_DATE_FORMAT,
+       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("10:21 PM"), buffer);
 }
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev47981 - in src: tests/kits/locale kits/locale - pulkomandy