Changeset 134216 in webkit
- Timestamp:
- Nov 12, 2012 5:23:34 AM (11 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r134214 r134216 1 2012-11-12 Keishi Hattori <keishi@webkit.org> 2 3 Add support for week/month to Locale::formatDateTime() 4 https://bugs.webkit.org/show_bug.cgi?id=101878 5 6 Reviewed by Kent Tamura. 7 8 Adding support for week/month to Locale::formatDateTime() in preparation for datalist support for <input type=week/month>. 9 10 Added Chromium tests LocaleMacTest.formatWeek and LocaleMacTest.formatMonth. 11 12 * platform/text/PlatformLocale.cpp: 13 (WebCore::DateTimeStringBuilder::visitField): 14 (WebCore::Locale::formatDateTime): Support week and month types. 15 1 16 2012-11-12 Allan Sandfeld Jensen <allan.jensen@digia.com> 2 17 -
trunk/Source/WebCore/platform/text/PlatformLocale.cpp
r133284 r134216 33 33 34 34 #include "DateTimeFormat.h" 35 #include "LocalizedStrings.h" 35 36 #include <wtf/text/StringBuilder.h> 36 37 … … 99 100 appendNumber(m_date.fullYear(), 4); 100 101 return; 101 case DateTimeFormat::FieldTypeMonth: 102 // Always use padding width of 2 so it matches DateTimeEditElement. 103 appendNumber(m_date.month() + 1, 2); 102 case DateTimeFormat::FieldTypeMonth: 103 if (numberOfPatternCharacters == 3) 104 m_builder.append(m_localizer.shortMonthLabels()[m_date.month()]); 105 else if (numberOfPatternCharacters == 4) 106 m_builder.append(m_localizer.monthLabels()[m_date.month()]); 107 else { 108 // Always use padding width of 2 so it matches DateTimeEditElement. 109 appendNumber(m_date.month() + 1, 2); 110 } 111 return; 112 case DateTimeFormat::FieldTypeMonthStandAlone: 113 if (numberOfPatternCharacters == 3) 114 m_builder.append(m_localizer.shortStandAloneMonthLabels()[m_date.month()]); 115 else if (numberOfPatternCharacters == 4) 116 m_builder.append(m_localizer.standAloneMonthLabels()[m_date.month()]); 117 else { 118 // Always use padding width of 2 so it matches DateTimeEditElement. 119 appendNumber(m_date.month() + 1, 2); 120 } 104 121 return; 105 122 case DateTimeFormat::FieldTypeDayOfMonth: 106 123 // Always use padding width of 2 so it matches DateTimeEditElement. 107 124 appendNumber(m_date.monthDay(), 2); 125 return; 126 case DateTimeFormat::FieldTypeWeekOfYear: 127 // Always use padding width of 2 so it matches DateTimeEditElement. 128 appendNumber(m_date.week(), 2); 108 129 return; 109 130 case DateTimeFormat::FieldTypePeriod: … … 346 367 String Locale::formatDateTime(const DateComponents& date, FormatType formatType) 347 368 { 348 if (date.type() != DateComponents::Time && date.type() != DateComponents::Date)369 if (date.type() == DateComponents::DateTime || date.type() == DateComponents::DateTimeLocal || date.type() == DateComponents::Invalid) 349 370 return String(); 350 371 // FIXME: Supports all types. 351 372 352 373 DateTimeStringBuilder builder(*this, date); 353 if (date.type() == DateComponents::Time) 374 switch (date.type()) { 375 case DateComponents::Time: 354 376 builder.build(formatType == FormatTypeShort ? shortTimeFormat() : timeFormat()); 355 else if (date.type() == DateComponents::Date) 377 break; 378 case DateComponents::Date: 356 379 builder.build(dateFormat()); 380 break; 381 case DateComponents::Week: 382 builder.build(weekFormatInLDML()); 383 break; 384 case DateComponents::Month: 385 builder.build(monthFormat()); 386 break; 387 case DateComponents::Invalid: 388 case DateComponents::DateTime: 389 case DateComponents::DateTimeLocal: 390 ASSERT_NOT_REACHED(); 391 break; 392 } 357 393 return builder.toString(); 358 394 } -
trunk/Source/WebKit/chromium/ChangeLog
r134177 r134216 1 2012-11-12 Keishi Hattori <keishi@webkit.org> 2 3 Add support for week/month to Locale::formatDateTime() 4 https://bugs.webkit.org/show_bug.cgi?id=101878 5 6 Reviewed by Kent Tamura. 7 8 * tests/LocaleMacTest.cpp: 9 (LocaleMacTest::formatWeek): Takes ISO string and returns localized string. 10 (LocaleMacTest): 11 (LocaleMacTest::formatMonth): Ditto. 12 (TEST_F): 13 1 14 2012-11-11 Sadrul Habib Chowdhury <sadrul@chromium.org> 2 15 -
trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp
r133134 r134216 70 70 } 71 71 72 String formatWeek(const String& localeString, const String& isoString) 73 { 74 OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); 75 DateComponents date; 76 unsigned end; 77 date.parseWeek(isoString.characters(), isoString.length(), 0, end); 78 return locale->formatDateTime(date); 79 } 80 81 String formatMonth(const String& localeString, const String& isoString) 82 { 83 OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); 84 DateComponents date; 85 unsigned end; 86 date.parseMonth(isoString.characters(), isoString.length(), 0, end); 87 return locale->formatDateTime(date); 88 } 89 72 90 String formatDate(const String& localeString, int year, int month, int day) 73 91 { … … 158 176 #endif 159 177 }; 178 179 TEST_F(LocaleMacTest, formatWeek) 180 { 181 EXPECT_STREQ("Week 04, 2005", formatWeek("en_US", "2005-W04").utf8().data()); 182 EXPECT_STREQ("Week 52, 2005", formatWeek("en_US", "2005-W52").utf8().data()); 183 } 184 185 TEST_F(LocaleMacTest, formatMonth) 186 { 187 EXPECT_STREQ("April 2005", formatMonth("en_US", "2005-04").utf8().data()); 188 EXPECT_STREQ("avril 2005", formatMonth("fr_FR", "2005-04").utf8().data()); 189 EXPECT_STREQ("2005\xE5\xB9\xB4" "04\xE6\x9C\x88", formatMonth("ja_JP", "2005-04").utf8().data()); 190 } 160 191 161 192 TEST_F(LocaleMacTest, formatDate)
Note: See TracChangeset
for help on using the changeset viewer.