Changeset 114085 in webkit


Ignore:
Timestamp:
Apr 12, 2012 11:07:40 PM (12 years ago)
Author:
tkent@chromium.org
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.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r114082 r114085  
     12012-04-12  Kent Tamura  <tkent@chromium.org>
     2
     3        LocalizedDateICU should ignore timezones
     4        https://bugs.webkit.org/show_bug.cgi?id=83859
     5
     6        Reviewed by Hajime Morita.
     7
     8        udat_parse() and udat_format() shift the input date by the offset of the
     9        default timezone. We don't need this behavior for type=date. So we
     10        specify "GMT" to udat_open().
     11
     12        No new tests. This behavior depends on the timezone setting of the local machine.
     13
     14        * platform/text/LocalizedDateICU.cpp:
     15        (WebCore::createShortDateFormatter):
     16        Added. Common factory functio for UDateFormat. Use "GMT" instead of the
     17        default timezone.
     18        (WebCore::parseLocalizedDate): Use createShortDateFormatter().
     19        (WebCore::formatLocalizedDate): ditto.
     20
    1212012-04-12  Adam Barth  <abarth@webkit.org>
    222
  • trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp

    r113422 r114085  
    4444namespace WebCore {
    4545
     46static inline UDateFormat* createShortDateFormatter()
     47{
     48    const UChar gmtTimezone[3] = {'G', 'M', 'T'};
     49    UErrorCode status = U_ZERO_ERROR;
     50    return udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
     51}
     52
    4653double parseLocalizedDate(const String& input, DateComponents::Type type)
    4754{
     
    5158            break;
    5259        int32_t inputLength = static_cast<int32_t>(input.length());
    53         UErrorCode status = U_ZERO_ERROR;
    54         UDateFormat* dateFormat = udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
     60        UDateFormat* dateFormat = createShortDateFormatter();
    5561        if (!dateFormat)
    5662            break;
    57         status = U_ZERO_ERROR;
     63        UErrorCode status = U_ZERO_ERROR;
    5864        int32_t parsePosition = 0;
    5965        UDate date = udat_parse(dateFormat, input.characters(), inputLength, &parsePosition, &status);
     
    7985    switch (dateComponents.type()) {
    8086    case DateComponents::Date: {
    81         UErrorCode status = U_ZERO_ERROR;
    82         UDateFormat* dateFormat = udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
     87        UDateFormat* dateFormat = createShortDateFormatter();
    8388        if (!dateFormat)
    8489            break;
    8590        double input = dateComponents.millisecondsSinceEpoch();
     91        UErrorCode status = U_ZERO_ERROR;
    8692        int32_t length = udat_format(dateFormat, input, 0, 0, 0, &status);
    8793        if (status != U_BUFFER_OVERFLOW_ERROR) {
Note: See TracChangeset for help on using the changeset viewer.