Title: [114085] trunk/Source/WebCore
Revision
114085
Author
[email protected]
Date
2012-04-12 23:07:40 -0700 (Thu, 12 Apr 2012)

Log Message

LocalizedDateICU should ignore timezones
https://bugs.webkit.org/show_bug.cgi?id=83859

Reviewed by Hajime Morita.

udat_parse() and udat_format() shift the input date by the offset of the
default timezone. We don't need this behavior for type=date. So we
specify "GMT" to udat_open().

No new tests. This behavior depends on the timezone setting of the local machine.

* platform/text/LocalizedDateICU.cpp:
(WebCore::createShortDateFormatter):
Added. Common factory functio for UDateFormat. Use "GMT" instead of the
default timezone.
(WebCore::parseLocalizedDate): Use createShortDateFormatter().
(WebCore::formatLocalizedDate): ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (114084 => 114085)


--- trunk/Source/WebCore/ChangeLog	2012-04-13 06:00:09 UTC (rev 114084)
+++ trunk/Source/WebCore/ChangeLog	2012-04-13 06:07:40 UTC (rev 114085)
@@ -1,3 +1,23 @@
+2012-04-12  Kent Tamura  <[email protected]>
+
+        LocalizedDateICU should ignore timezones
+        https://bugs.webkit.org/show_bug.cgi?id=83859
+
+        Reviewed by Hajime Morita.
+
+        udat_parse() and udat_format() shift the input date by the offset of the
+        default timezone. We don't need this behavior for type=date. So we
+        specify "GMT" to udat_open().
+
+        No new tests. This behavior depends on the timezone setting of the local machine.
+
+        * platform/text/LocalizedDateICU.cpp:
+        (WebCore::createShortDateFormatter):
+        Added. Common factory functio for UDateFormat. Use "GMT" instead of the
+        default timezone.
+        (WebCore::parseLocalizedDate): Use createShortDateFormatter().
+        (WebCore::formatLocalizedDate): ditto.
+
 2012-04-12  Adam Barth  <[email protected]>
 
         Prepare window.location for seamless navigation

Modified: trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp (114084 => 114085)


--- trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp	2012-04-13 06:00:09 UTC (rev 114084)
+++ trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp	2012-04-13 06:07:40 UTC (rev 114085)
@@ -43,6 +43,13 @@
 
 namespace WebCore {
 
+static inline UDateFormat* createShortDateFormatter()
+{
+    const UChar gmtTimezone[3] = {'G', 'M', 'T'};
+    UErrorCode status = U_ZERO_ERROR;
+    return udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
+}
+
 double parseLocalizedDate(const String& input, DateComponents::Type type)
 {
     switch (type) {
@@ -50,11 +57,10 @@
         if (input.length() > static_cast<unsigned>(numeric_limits<int32_t>::max()))
             break;
         int32_t inputLength = static_cast<int32_t>(input.length());
-        UErrorCode status = U_ZERO_ERROR;
-        UDateFormat* dateFormat = udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
+        UDateFormat* dateFormat = createShortDateFormatter();
         if (!dateFormat)
             break;
-        status = U_ZERO_ERROR;
+        UErrorCode status = U_ZERO_ERROR;
         int32_t parsePosition = 0;
         UDate date = udat_parse(dateFormat, input.characters(), inputLength, &parsePosition, &status);
         udat_close(dateFormat);
@@ -78,11 +84,11 @@
 {
     switch (dateComponents.type()) {
     case DateComponents::Date: {
-        UErrorCode status = U_ZERO_ERROR;
-        UDateFormat* dateFormat = udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
+        UDateFormat* dateFormat = createShortDateFormatter();
         if (!dateFormat)
             break;
         double input = dateComponents.millisecondsSinceEpoch();
+        UErrorCode status = U_ZERO_ERROR;
         int32_t length = udat_format(dateFormat, input, 0, 0, 0, &status);
         if (status != U_BUFFER_OVERFLOW_ERROR) {
             udat_close(dateFormat);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to