Changeset 131749 in webkit
- Timestamp:
- Oct 18, 2012 7:32:08 AM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r131744 r131749 1 2012-10-18 Kent Tamura <tkent@chromium.org> 2 3 Add Localizer::monthFormat and implementations 4 https://bugs.webkit.org/show_bug.cgi?id=99704 5 6 Reviewed by Kentaro Hara. 7 8 Localizer::monthFormat will be used for constructing input[type=month] UI. 9 10 Tests: Add unit tests to Source/WebKit/chromium/tests/. 11 12 * platform/text/Localizer.h: 13 (Localizer): Declare pure virtual monthFormat function. 14 15 * platform/text/LocaleNone.cpp: 16 (LocaleNone): Declare monthFormat. 17 (WebCore::LocaleNone::monthFormat): 18 Added. Always reutrns an ISO-8601 format, "yyyy-MM" 19 20 * platform/text/LocaleICU.h: 21 (LocaleICU): Declare monthFormat. 22 * platform/text/LocaleICU.cpp: 23 (WebCore::getFormatForSkeleton): 24 A helper to get a format for the specified skeleton. 25 The overflow-allocalte-try-again pattern is similar to 26 LocaleICU::decimalSymbol and LocaleICU::decimalTextAttribute. 27 (WebCore::LocaleICU::monthFormat): 28 Added. Calls getFormatForSkeleton with "yyyyMMM". 29 30 * platform/text/mac/LocaleMac.h: 31 (LocaleMac): Declare monthFormat. 32 * platform/text/mac/LocaleMac.mm: 33 (WebCore::LocaleMac::monthFormat): 34 Added. Calls NSDateFormatter::dateFormatFromTemplate with "yyyyMMM". 35 36 * platform/text/LocaleWin.h: 37 (LocaleWin): Declare monthFormat. 38 * platform/text/LocaleWin.cpp: 39 (WebCore::LocaleWin::monthFormat): 40 Get a format by LOCALE_SYEARMONTH, and convert it to an LDML format. 41 1 42 2012-10-18 Pavel Feldman <pfeldman@chromium.org> 2 43 -
trunk/Source/WebCore/platform/text/LocaleICU.cpp
r131585 r131749 34 34 #include "LocalizedStrings.h" 35 35 #include <limits> 36 #include <unicode/udatpg.h> 36 37 #include <unicode/uloc.h> 37 38 #include <wtf/DateMath.h> … … 399 400 } 400 401 402 static String getFormatForSkeleton(const char* locale, const String& skeleton) 403 { 404 String format = ASCIILiteral("yyyy-MM"); 405 UErrorCode status = U_ZERO_ERROR; 406 UDateTimePatternGenerator* patternGenerator = udatpg_open(locale, &status); 407 if (!patternGenerator) 408 return format; 409 status = U_ZERO_ERROR; 410 int32_t length = udatpg_getBestPattern(patternGenerator, skeleton.characters(), skeleton.length(), 0, 0, &status); 411 if (status == U_BUFFER_OVERFLOW_ERROR && length) { 412 Vector<UChar> buffer(length); 413 status = U_ZERO_ERROR; 414 udatpg_getBestPattern(patternGenerator, skeleton.characters(), skeleton.length(), buffer.data(), length, &status); 415 if (U_SUCCESS(status)) 416 format = String::adopt(buffer); 417 } 418 udatpg_close(patternGenerator); 419 return format; 420 } 421 422 String LocaleICU::monthFormat() 423 { 424 if (!m_monthFormat.isNull()) 425 return m_monthFormat; 426 // Gets a format for "MMM", not "MM" because Windows API always provides 427 // formats for "MMM". 428 m_monthFormat = getFormatForSkeleton(m_locale.data(), ASCIILiteral("yyyyMMM")); 429 return m_monthFormat; 430 } 431 401 432 String LocaleICU::timeFormat() 402 433 { -
trunk/Source/WebCore/platform/text/LocaleICU.h
r131585 r131749 63 63 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 64 64 virtual String dateFormat() OVERRIDE; 65 virtual String monthFormat() OVERRIDE; 65 66 virtual String timeFormat() OVERRIDE; 66 67 virtual String shortTimeFormat() OVERRIDE; … … 108 109 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 109 110 String m_dateFormat; 111 String m_monthFormat; 110 112 UDateFormat* m_mediumTimeFormat; 111 113 UDateFormat* m_shortTimeFormat; -
trunk/Source/WebCore/platform/text/LocaleNone.cpp
r131585 r131749 43 43 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 44 44 virtual String dateFormat() OVERRIDE; 45 virtual String monthFormat() OVERRIDE; 45 46 #endif 46 47 }; … … 81 82 return ASCIILiteral("dd/MM/yyyyy"); 82 83 } 84 85 String LocaleNone::monthFormat() 86 { 87 return ASCIILiteral("yyyy-MM"); 88 } 83 89 #endif 84 90 -
trunk/Source/WebCore/platform/text/LocaleWin.cpp
r131585 r131749 714 714 } 715 715 716 String LocaleWin::monthFormat() 717 { 718 if (!m_monthFormat.isNull()) 719 return m_monthFormat; 720 m_monthFormat = convertWindowsDateFormatToLDML(parseDateFormat(getLocaleInfoString(LOCALE_SYEARMONTH))); 721 return m_monthFormat; 722 } 723 716 724 String LocaleWin::timeFormat() 717 725 { -
trunk/Source/WebCore/platform/text/LocaleWin.h
r131585 r131749 58 58 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 59 59 virtual String dateFormat() OVERRIDE; 60 virtual String monthFormat() OVERRIDE; 60 61 virtual String timeFormat() OVERRIDE; 61 62 virtual String shortTimeFormat() OVERRIDE; … … 99 100 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 100 101 String m_dateFormat; 102 String m_monthFormat; 101 103 #endif 102 104 #if ENABLE(CALENDAR_PICKER) -
trunk/Source/WebCore/platform/text/Localizer.h
r131585 r131749 62 62 // [1] LDML http://unicode.org/reports/tr35/#Date_Format_Patterns 63 63 virtual String dateFormat() = 0; 64 65 // Returns a year-month format in Unicode TR35 LDML. 66 virtual String monthFormat() = 0; 64 67 65 68 // Returns time format in Unicode TR35 LDML[1] containing hour, minute, and -
trunk/Source/WebCore/platform/text/mac/LocaleMac.h
r131585 r131749 63 63 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 64 64 virtual String dateFormat() OVERRIDE; 65 virtual String monthFormat() OVERRIDE; 65 66 virtual String timeFormat() OVERRIDE; 66 67 virtual String shortTimeFormat() OVERRIDE; … … 85 86 86 87 String m_dateFormat; 88 String m_monthFormat; 87 89 String m_localizedTimeFormatText; 88 90 String m_localizedShortTimeFormatText; -
trunk/Source/WebCore/platform/text/mac/LocaleMac.mm
r131585 r131749 247 247 } 248 248 249 String LocaleMac::monthFormat() 250 { 251 if (!m_monthFormat.isNull()) 252 return m_monthFormat; 253 // Gets a format for "MMM", not "MM" because Windows API always provides 254 // formats for "MMM". 255 m_monthFormat = [NSDateFormatter dateFormatFromTemplate:@"yyyyMMM" options:0 locale:m_locale.get()]; 256 return m_monthFormat; 257 } 258 249 259 String LocaleMac::timeFormat() 250 260 { -
trunk/Source/WebKit/chromium/ChangeLog
r131704 r131749 1 2012-10-18 Kent Tamura <tkent@chromium.org> 2 3 Add Localizer::monthFormat and implementations 4 https://bugs.webkit.org/show_bug.cgi?id=99704 5 6 Reviewed by Kentaro Hara. 7 8 * tests/LocaleMacTest.cpp: 9 (LocaleMacTest::monthFormat): A helper function. 10 (TEST_F): Added some tests. 11 * tests/LocaleWinTest.cpp: 12 (LocaleWinTest::monthFormat): A helper function. 13 (TEST_F): Added some tests. 14 * tests/LocalizedDateICUTest.cpp: 15 (LocalizedDateICUTest::monthFormat): A helper function. 16 (TEST_F): Added some tests. 17 1 18 2012-10-17 Mike West <mkwst@chromium.org> 2 19 -
trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp
r131585 r131749 121 121 122 122 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 123 String monthFormat(const String& localeString) 124 { 125 OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); 126 return locale->monthFormat(); 127 } 128 123 129 String timeFormat(const String& localeString) 124 130 { … … 237 243 238 244 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 245 TEST_F(LocaleMacTest, monthFormat) 246 { 247 EXPECT_STREQ("MMM yyyy", monthFormat("en_US").utf8().data()); 248 EXPECT_STREQ("MMM y", monthFormat("fr_FR").utf8().data()); 249 EXPECT_STREQ("yyyy\xE5\xB9\xB4M\xE6\x9C\x88", monthFormat("ja_JP").utf8().data()); 250 EXPECT_STREQ("LLL y", monthFormat("ru").utf8().data()); 251 } 252 239 253 TEST_F(LocaleMacTest, timeFormat) 240 254 { -
trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp
r131585 r131749 130 130 131 131 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 132 String monthFormat(LCID lcid) 133 { 134 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid); 135 return locale->monthFormat(); 136 } 137 132 138 String timeFormat(LCID lcid) 133 139 { … … 285 291 } 286 292 293 TEST_F(LocaleWinTest, monthFormat) 294 { 295 EXPECT_STREQ("MMMM', 'yyyy", monthFormat(EnglishUS).utf8().data()); 296 EXPECT_STREQ("MMMM' 'yyyy", monthFormat(FrenchFR).utf8().data()); 297 EXPECT_STREQ("yyyy'\xE5\xB9\xB4'M'\xE6\x9C\x88'", monthFormat(JapaneseJP).utf8().data()); 298 } 299 287 300 TEST_F(LocaleWinTest, timeFormat) 288 301 { -
trunk/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp
r131030 r131749 89 89 } 90 90 91 String monthFormat(const char* localeString) 92 { 93 OwnPtr<LocaleICU> locale = LocaleICU::create(localeString); 94 return locale->monthFormat(); 95 } 96 91 97 String localizedDateFormatText(const char* localeString) 92 98 { … … 127 133 } 128 134 135 TEST_F(LocalizedDateICUTest, monthFormat) 136 { 137 EXPECT_STREQ("MMM yyyy", monthFormat("en_US").utf8().data()); 138 EXPECT_STREQ("MMM yyyy", monthFormat("fr").utf8().data()); 139 EXPECT_STREQ("yyyy\xE5\xB9\xB4M\xE6\x9C\x88", monthFormat("ja").utf8().data()); 140 } 141 129 142 TEST_F(LocalizedDateICUTest, localizedDateFormatText) 130 143 {
Note: See TracChangeset
for help on using the changeset viewer.