Log Message
[Chromium-Windows] Implement functions for localized time format information https://bugs.webkit.org/show_bug.cgi?id=90236
Reviewed by Kent Tamura.
Source/WebCore:
This patch introduces following localized time format related
functions:
- localizedTimeFormatText
- localizeShortTimeFormatText()
- timeAMPMLabels
for Windows in feature flag: ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.
See also:
ICU version: https://bugs.webkit.org/show_bug.cgi?id=89965
Mac version: https://bugs.webkit.org/show_bug.cgi?id=90237
Tests: WebKit/chromium/tests/LocalWinTest.cpp
* platform/text/LocaleWin.cpp:
(WebCore::mapCharacterToDateTimeFieldType): Added.
(WebCore::convertWindowsTimeFormatToLDML): Added.
(WebCore::LocaleWin::timeFormatText): Added.
(WebCore::LocaleWin::shortTimeFormatText): Added.
(WebCore::LocaleWin::timeAMPMLabels): Added.
* platform/text/LocaleWin.h:
(LocaleWin): Added time format related functions and variables.
* platform/text/LocalizedDateWin.cpp:
(WebCore::localizedTimeFormatText): Added.
(WebCore::localizedShortTimeFormatText): Added.
(WebCore::timeAMPMLabels): Added.
Source/WebKit/chromium:
This patch introduces test cases for date and time format related
functions in LocaleWin.
* tests/LocaleWinTest.cpp:
(LocaleWinTest):
(LocaleWinTest::dateComponents): Added.
(LocaleWinTest::msForDate): Moved inside class LocaleWinTest.
(LocaleWinTest::formatDate): Added.
(LocaleWinTest::parseDate): Added.
(LocaleWinTest::dateFormatText): Added.
(LocaleWinTest::firstDayOfWeek): Added.
(LocaleWinTest::monthLabel): Added.
(LocaleWinTest::weekDayShortLabel): Added.
(LocaleWinTest::timeFormatText): Added.
(LocaleWinTest::shortTimeFormatText): Added.
(LocaleWinTest::timeAMPMLabel): Added.
(TEST_F):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (122302 => 122303)
--- trunk/Source/WebCore/ChangeLog 2012-07-11 06:23:02 UTC (rev 122302)
+++ trunk/Source/WebCore/ChangeLog 2012-07-11 06:52:27 UTC (rev 122303)
@@ -1,3 +1,36 @@
+2012-07-10 Yoshifumi Inoue <[email protected]>
+
+ [Chromium-Windows] Implement functions for localized time format information
+ https://bugs.webkit.org/show_bug.cgi?id=90236
+
+ Reviewed by Kent Tamura.
+
+ This patch introduces following localized time format related
+ functions:
+ - localizedTimeFormatText
+ - localizeShortTimeFormatText()
+ - timeAMPMLabels
+ for Windows in feature flag: ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.
+
+ See also:
+ ICU version: https://bugs.webkit.org/show_bug.cgi?id=89965
+ Mac version: https://bugs.webkit.org/show_bug.cgi?id=90237
+
+ Tests: WebKit/chromium/tests/LocalWinTest.cpp
+
+ * platform/text/LocaleWin.cpp:
+ (WebCore::mapCharacterToDateTimeFieldType): Added.
+ (WebCore::convertWindowsTimeFormatToLDML): Added.
+ (WebCore::LocaleWin::timeFormatText): Added.
+ (WebCore::LocaleWin::shortTimeFormatText): Added.
+ (WebCore::LocaleWin::timeAMPMLabels): Added.
+ * platform/text/LocaleWin.h:
+ (LocaleWin): Added time format related functions and variables.
+ * platform/text/LocalizedDateWin.cpp:
+ (WebCore::localizedTimeFormatText): Added.
+ (WebCore::localizedShortTimeFormatText): Added.
+ (WebCore::timeAMPMLabels): Added.
+
2012-07-10 Douglas Stockwell <[email protected]>
Style not updated for element with display:none becoming first/last-child
Modified: trunk/Source/WebCore/platform/text/LocaleWin.cpp (122302 => 122303)
--- trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-07-11 06:23:02 UTC (rev 122302)
+++ trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-07-11 06:52:27 UTC (rev 122303)
@@ -32,6 +32,9 @@
#include "LocaleWin.h"
#include "DateComponents.h"
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+#include "DateTimeFormat.h"
+#endif
#include "LocalizedStrings.h"
#include <limits>
#include <windows.h>
@@ -590,4 +593,81 @@
}
#endif
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+static DateTimeFormat::FieldType mapCharacterToDateTimeFieldType(UChar ch)
+{
+ switch (ch) {
+ case 'h':
+ return DateTimeFormat::FieldTypeHour12;
+
+ case 'H':
+ return DateTimeFormat::FieldTypeHour23;
+
+ case 'm':
+ return DateTimeFormat::FieldTypeMinute;
+
+ case 's':
+ return DateTimeFormat::FieldTypeSecond;
+
+ case 't':
+ return DateTimeFormat::FieldTypePeriod;
+
+ default:
+ return DateTimeFormat::FieldTypeLiteral;
+ }
}
+
+// This class used for converting Windows time pattern format[1] into LDML[2]
+// time format string.
+// [1] http://msdn.microsoft.com/en-us/library/windows/desktop/dd318148(v=vs.85).aspx
+// [2] LDML http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
+static String convertWindowsTimeFormatToLDML(const String& windowsTimeFormat)
+{
+ StringBuilder builder;
+ int counter = 0;
+ DateTimeFormat::FieldType lastFieldType = DateTimeFormat::FieldTypeLiteral;
+ for (unsigned index = 0; index < windowsTimeFormat.length(); ++index) {
+ UChar const ch = windowsTimeFormat[index];
+ DateTimeFormat::FieldType fieldType = mapCharacterToDateTimeFieldType(ch);
+ if (fieldType == DateTimeFormat::FieldTypeLiteral)
+ builder.append(ch);
+ else if (fieldType == lastFieldType) {
+ ++counter;
+ if (counter == 2 && lastFieldType != DateTimeFormat::FieldTypePeriod)
+ builder.append(static_cast<UChar>(lastFieldType));
+ } else {
+ if (lastFieldType != DateTimeFormat::FieldTypeLiteral)
+ builder.append(static_cast<UChar>(lastFieldType));
+ builder.append(static_cast<UChar>(fieldType));
+ counter = 1;
+ }
+ lastFieldType = fieldType;
+ }
+ return builder.toString();
+}
+
+String LocaleWin::timeFormatText()
+{
+ if (m_timeFormatText.isEmpty())
+ m_timeFormatText = convertWindowsTimeFormatToLDML(getLocaleInfoString(LOCALE_STIMEFORMAT));
+ return m_timeFormatText;
+}
+
+// Note: To make XP/Vista and Windows 7/later same behavior, we don't use
+// LOCALE_SSHORTTIME.
+String LocaleWin::shortTimeFormatText()
+{
+ return timeFormatText();
+}
+
+const Vector<String>& LocaleWin::timeAMPMLabels()
+{
+ if (m_timeAMPMLabels.isEmpty()) {
+ m_timeAMPMLabels.append(getLocaleInfoString(LOCALE_S1159));
+ m_timeAMPMLabels.append(getLocaleInfoString(LOCALE_S2359));
+ }
+ return m_timeAMPMLabels;
+}
+#endif
+
+}
Modified: trunk/Source/WebCore/platform/text/LocaleWin.h (122302 => 122303)
--- trunk/Source/WebCore/platform/text/LocaleWin.h 2012-07-11 06:23:02 UTC (rev 122302)
+++ trunk/Source/WebCore/platform/text/LocaleWin.h 2012-07-11 06:52:27 UTC (rev 122303)
@@ -34,6 +34,7 @@
#include <windows.h>
#include <wtf/Forward.h>
#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -54,6 +55,12 @@
unsigned firstDayOfWeek() { return m_firstDayOfWeek; }
#endif
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+ String timeFormatText();
+ String shortTimeFormatText();
+ const Vector<String>& timeAMPMLabels();
+#endif
+
// For testing.
double parseDate(const String& format, int baseYear, const String& input);
String formatDate(const String& format, int baseYear, int year, int month, int day);
@@ -81,7 +88,10 @@
Vector<String> m_weekDayShortLabels;
unsigned m_firstDayOfWeek;
#endif
-
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+ String m_timeFormatText;
+ Vector<String> m_timeAMPMLabels;
+#endif
};
}
Modified: trunk/Source/WebCore/platform/text/LocalizedDateWin.cpp (122302 => 122303)
--- trunk/Source/WebCore/platform/text/LocalizedDateWin.cpp 2012-07-11 06:23:02 UTC (rev 122302)
+++ trunk/Source/WebCore/platform/text/LocalizedDateWin.cpp 2012-07-11 06:52:27 UTC (rev 122303)
@@ -92,4 +92,21 @@
}
#endif
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+String localizedTimeFormatText()
+{
+ return LocaleWin::currentLocale()->timeFormatText();
}
+
+String localizedShortTimeFormatText()
+{
+ return LocaleWin::currentLocale()->shortTimeFormatText();
+}
+
+const Vector<String>& timeAMPMLabels()
+{
+ return LocaleWin::currentLocale()->timeAMPMLabels();
+}
+#endif
+
+}
Modified: trunk/Source/WebKit/chromium/ChangeLog (122302 => 122303)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-07-11 06:23:02 UTC (rev 122302)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-07-11 06:52:27 UTC (rev 122303)
@@ -1,3 +1,28 @@
+2012-07-10 Yoshifumi Inoue <[email protected]>
+
+ [Chromium-Windows] Implement functions for localized time format information
+ https://bugs.webkit.org/show_bug.cgi?id=90236
+
+ Reviewed by Kent Tamura.
+
+ This patch introduces test cases for date and time format related
+ functions in LocaleWin.
+
+ * tests/LocaleWinTest.cpp:
+ (LocaleWinTest):
+ (LocaleWinTest::dateComponents): Added.
+ (LocaleWinTest::msForDate): Moved inside class LocaleWinTest.
+ (LocaleWinTest::formatDate): Added.
+ (LocaleWinTest::parseDate): Added.
+ (LocaleWinTest::dateFormatText): Added.
+ (LocaleWinTest::firstDayOfWeek): Added.
+ (LocaleWinTest::monthLabel): Added.
+ (LocaleWinTest::weekDayShortLabel): Added.
+ (LocaleWinTest::timeFormatText): Added.
+ (LocaleWinTest::shortTimeFormatText): Added.
+ (LocaleWinTest::timeAMPMLabel): Added.
+ (TEST_F):
+
2012-07-10 Adam Barth <[email protected]>
[Chromium-Android] Add apk test targets for webkit_unit_tests and TestWebKitAPI
Modified: trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp (122302 => 122303)
--- trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-07-11 06:23:02 UTC (rev 122302)
+++ trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-07-11 06:52:27 UTC (rev 122303)
@@ -31,6 +31,7 @@
#include "config.h"
#include "LocaleWin.h"
+#include "DateComponents.h"
#include <gtest/gtest.h>
#include <wtf/DateMath.h>
#include <wtf/MathExtras.h>
@@ -40,20 +41,101 @@
using namespace WebCore;
using namespace std;
-enum {
- January = 0, February, March,
- April, May, June,
- July, August, September,
- October, November, December,
+class LocaleWinTest : public ::testing::Test {
+protected:
+ enum {
+ January = 0, February, March,
+ April, May, June,
+ July, August, September,
+ October, November, December,
+ };
+
+ enum {
+ Sunday = 0, Monday, Tuesday,
+ Wednesday, Thursday, Friday,
+ Saturday,
+ };
+
+ // See http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
+ enum {
+ EnglishUS = 0x409,
+ FrenchFR = 0x40C,
+ JapaneseJP = 0x411,
+ };
+
+ DateComponents dateComponents(int year, int month, int day)
+ {
+ DateComponents date;
+ date.setMillisecondsSinceEpochForDate(msForDate(year, month, day));
+ return date;
+ }
+
+ double msForDate(int year, int month, int day)
+ {
+ return dateToDaysFrom1970(year, month, day) * msPerDay;
+ }
+
+ String formatDate(LCID lcid, int year, int month, int day)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->formatDate(dateComponents(year, month, day));
+ }
+
+ double parseDate(LCID lcid, const String& dateString)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->parseDate(dateString);
+ }
+
+#if ENABLE(CALENDAR_PICKER)
+ String dateFormatText(LCID lcid)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->dateFormatText();
+ }
+
+ unsigned firstDayOfWeek(LCID lcid)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->firstDayOfWeek();
+ }
+
+ String monthLabel(LCID lcid, unsigned index)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->monthLabels()[index];
+ }
+
+ String weekDayShortLabel(LCID lcid, unsigned index)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->weekDayShortLabels()[index];
+ }
+#endif
+
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+ String timeFormatText(LCID lcid)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->timeFormatText();
+ }
+
+ String shortTimeFormatText(LCID lcid)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->shortTimeFormatText();
+ }
+
+ String timeAMPMLabel(LCID lcid, unsigned index)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->timeAMPMLabels()[index];
+ }
+#endif
};
-static double msForDate(int year, int month, int day)
+TEST_F(LocaleWinTest, TestLocalizedDateFormatText)
{
- return dateToDaysFrom1970(year, month, day) * msPerDay;
-}
-
-TEST(LocaleWinTest, TestLocalizedDateFormatText)
-{
EXPECT_STREQ("year/month/day", LocaleWin::dateFormatText("y/M/d", "year", "month", "day").utf8().data());
EXPECT_STREQ("year/month/day", LocaleWin::dateFormatText("yy/MM/dd", "year", "month", "day").utf8().data());
EXPECT_STREQ("year/month/day", LocaleWin::dateFormatText("yyy/MMM/ddd", "year", "month", "day").utf8().data());
@@ -66,9 +148,8 @@
EXPECT_STREQ("YY/mm/DD", LocaleWin::dateFormatText("YY/mm/DD", "year", "month", "day").utf8().data());
}
-TEST(LocaleWinTest, TestFormat)
+TEST_F(LocaleWinTest, TestFormat)
{
- const LCID EnglishUS = 0x0409;
OwnPtr<LocaleWin> locale = LocaleWin::create(EnglishUS);
EXPECT_STREQ("4/7/2", locale->formatDate("M/d/y", 2012, 2012, April, 7).utf8().data());
@@ -126,9 +207,8 @@
}
-TEST(LocaleWinTest, TestParse)
+TEST_F(LocaleWinTest, TestParse)
{
- const LCID EnglishUS = 0x0409;
OwnPtr<LocaleWin> locale = LocaleWin::create(EnglishUS);
EXPECT_EQ(msForDate(2012, April, 27), locale->parseDate("MM/dd/yy", 2012, "04/27/12"));
@@ -161,3 +241,91 @@
EXPECT_TRUE(isnan(locale->parseDate("MMMM/d/y", 2012, "November 32 2")));
EXPECT_TRUE(isnan(locale->parseDate("MMMM/d/y", 2012, "-1/-1/-1")));
}
+
+TEST_F(LocaleWinTest, formatDate)
+{
+ EXPECT_STREQ("4/27/2005", formatDate(EnglishUS, 2005, April, 27).utf8().data());
+ EXPECT_STREQ("27/04/2005", formatDate(FrenchFR, 2005, April, 27).utf8().data());
+ EXPECT_STREQ("2005/04/27", formatDate(JapaneseJP, 2005, April, 27).utf8().data());
+}
+
+TEST_F(LocaleWinTest, parseDate)
+{
+ EXPECT_EQ(msForDate(2005, April, 27), parseDate(EnglishUS, "April/27/2005"));
+ EXPECT_EQ(msForDate(2005, April, 27), parseDate(FrenchFR, "27/avril/2005"));
+ EXPECT_EQ(msForDate(2005, April, 27), parseDate(JapaneseJP, "2005/04/27"));
+}
+
+#if ENABLE(CALENDAR_PICKER)
+TEST_F(LocaleWinTest, dateFormatText)
+{
+ EXPECT_STREQ("Month/Day/Year", dateFormatText(EnglishUS).utf8().data());
+ EXPECT_STREQ("Day/Month/Year", dateFormatText(FrenchFR).utf8().data());
+ EXPECT_STREQ("Year/Month/Day", dateFormatText(JapaneseJP).utf8().data());
+}
+
+TEST_F(LocaleWinTest, firstDayOfWeek)
+{
+ EXPECT_EQ(Sunday, firstDayOfWeek(EnglishUS));
+ EXPECT_EQ(Monday, firstDayOfWeek(FrenchFR));
+ EXPECT_EQ(Sunday, firstDayOfWeek(JapaneseJP));
+}
+
+TEST_F(LocaleWinTest, monthLabels)
+{
+ EXPECT_STREQ("January", monthLabel(EnglishUS, January).utf8().data());
+ EXPECT_STREQ("June", monthLabel(EnglishUS, June).utf8().data());
+ EXPECT_STREQ("December", monthLabel(EnglishUS, December).utf8().data());
+
+ EXPECT_STREQ("janvier", monthLabel(FrenchFR, January).utf8().data());
+ EXPECT_STREQ("juin", monthLabel(FrenchFR, June).utf8().data());
+ EXPECT_STREQ("d\xC3\xA9" "cembre", monthLabel(FrenchFR, December).utf8().data());
+
+ EXPECT_STREQ("1\xE6\x9C\x88", monthLabel(JapaneseJP, January).utf8().data());
+ EXPECT_STREQ("6\xE6\x9C\x88", monthLabel(JapaneseJP, June).utf8().data());
+ EXPECT_STREQ("12\xE6\x9C\x88", monthLabel(JapaneseJP, December).utf8().data());
+}
+
+TEST_F(LocaleWinTest, weekDayShortLabels)
+{
+ EXPECT_STREQ("Sun", weekDayShortLabel(EnglishUS, Sunday).utf8().data());
+ EXPECT_STREQ("Wed", weekDayShortLabel(EnglishUS, Wednesday).utf8().data());
+ EXPECT_STREQ("Sat", weekDayShortLabel(EnglishUS, Saturday).utf8().data());
+
+ EXPECT_STREQ("dim.", weekDayShortLabel(FrenchFR, Sunday).utf8().data());
+ EXPECT_STREQ("mer.", weekDayShortLabel(FrenchFR, Wednesday).utf8().data());
+ EXPECT_STREQ("sam.", weekDayShortLabel(FrenchFR, Saturday).utf8().data());
+
+ EXPECT_STREQ("\xE6\x97\xA5", weekDayShortLabel(JapaneseJP, Sunday).utf8().data());
+ EXPECT_STREQ("\xE6\xB0\xB4", weekDayShortLabel(JapaneseJP, Wednesday).utf8().data());
+ EXPECT_STREQ("\xE5\x9C\x9F", weekDayShortLabel(JapaneseJP, Saturday).utf8().data());
+}
+#endif
+
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+TEST_F(LocaleWinTest, timeFormatText)
+{
+ EXPECT_STREQ("h:mm:ss a", timeFormatText(EnglishUS).utf8().data());
+ EXPECT_STREQ("HH:mm:ss", timeFormatText(FrenchFR).utf8().data());
+ EXPECT_STREQ("H:mm:ss", timeFormatText(JapaneseJP).utf8().data());
+}
+
+TEST_F(LocaleWinTest, shortTimeFormatText)
+{
+ EXPECT_STREQ("h:mm:ss a", shortTimeFormatText(EnglishUS).utf8().data());
+ EXPECT_STREQ("HH:mm:ss", shortTimeFormatText(FrenchFR).utf8().data());
+ EXPECT_STREQ("H:mm:ss", shortTimeFormatText(JapaneseJP).utf8().data());
+}
+
+TEST_F(LocaleWinTest, timeAMPMLabels)
+{
+ EXPECT_STREQ("AM", timeAMPMLabel(EnglishUS, 0).utf8().data());
+ EXPECT_STREQ("PM", timeAMPMLabel(EnglishUS, 1).utf8().data());
+
+ EXPECT_STREQ("", timeAMPMLabel(FrenchFR, 0).utf8().data());
+ EXPECT_STREQ("", timeAMPMLabel(FrenchFR, 1).utf8().data());
+
+ EXPECT_STREQ("\xE5\x8D\x88\xE5\x89\x8D", timeAMPMLabel(JapaneseJP, 0).utf8().data());
+ EXPECT_STREQ("\xE5\x8D\x88\xE5\xBE\x8C", timeAMPMLabel(JapaneseJP, 1).utf8().data());
+}
+#endif
_______________________________________________ webkit-changes mailing list [email protected] http://lists.webkit.org/mailman/listinfo/webkit-changes
