Changeset 131749 in webkit


Ignore:
Timestamp:
Oct 18, 2012 7:32:08 AM (12 years ago)
Author:
tkent@chromium.org
Message:

Add Localizer::monthFormat and implementations
https://bugs.webkit.org/show_bug.cgi?id=99704

Reviewed by Kentaro Hara.

Source/WebCore:

Localizer::monthFormat will be used for constructing input[type=month] UI.

Tests: Add unit tests to Source/WebKit/chromium/tests/.

  • platform/text/Localizer.h:

(Localizer): Declare pure virtual monthFormat function.

  • platform/text/LocaleNone.cpp:

(LocaleNone): Declare monthFormat.
(WebCore::LocaleNone::monthFormat):
Added. Always reutrns an ISO-8601 format, "yyyy-MM"

  • platform/text/LocaleICU.h:

(LocaleICU): Declare monthFormat.

  • platform/text/LocaleICU.cpp:

(WebCore::getFormatForSkeleton):
A helper to get a format for the specified skeleton.
The overflow-allocalte-try-again pattern is similar to
LocaleICU::decimalSymbol and LocaleICU::decimalTextAttribute.
(WebCore::LocaleICU::monthFormat):
Added. Calls getFormatForSkeleton with "yyyyMMM".

  • platform/text/mac/LocaleMac.h:

(LocaleMac): Declare monthFormat.

  • platform/text/mac/LocaleMac.mm:

(WebCore::LocaleMac::monthFormat):
Added. Calls NSDateFormatter::dateFormatFromTemplate with "yyyyMMM".

  • platform/text/LocaleWin.h:

(LocaleWin): Declare monthFormat.

  • platform/text/LocaleWin.cpp:

(WebCore::LocaleWin::monthFormat):
Get a format by LOCALE_SYEARMONTH, and convert it to an LDML format.

Source/WebKit/chromium:

  • tests/LocaleMacTest.cpp:

(LocaleMacTest::monthFormat): A helper function.
(TEST_F): Added some tests.

  • tests/LocaleWinTest.cpp:

(LocaleWinTest::monthFormat): A helper function.
(TEST_F): Added some tests.

  • tests/LocalizedDateICUTest.cpp:

(LocalizedDateICUTest::monthFormat): A helper function.
(TEST_F): Added some tests.

Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r131744 r131749  
     12012-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
    1422012-10-18  Pavel Feldman  <pfeldman@chromium.org>
    243
  • trunk/Source/WebCore/platform/text/LocaleICU.cpp

    r131585 r131749  
    3434#include "LocalizedStrings.h"
    3535#include <limits>
     36#include <unicode/udatpg.h>
    3637#include <unicode/uloc.h>
    3738#include <wtf/DateMath.h>
     
    399400}
    400401
     402static 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
     422String 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
    401432String LocaleICU::timeFormat()
    402433{
  • trunk/Source/WebCore/platform/text/LocaleICU.h

    r131585 r131749  
    6363#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    6464    virtual String dateFormat() OVERRIDE;
     65    virtual String monthFormat() OVERRIDE;
    6566    virtual String timeFormat() OVERRIDE;
    6667    virtual String shortTimeFormat() OVERRIDE;
     
    108109#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    109110    String m_dateFormat;
     111    String m_monthFormat;
    110112    UDateFormat* m_mediumTimeFormat;
    111113    UDateFormat* m_shortTimeFormat;
  • trunk/Source/WebCore/platform/text/LocaleNone.cpp

    r131585 r131749  
    4343#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    4444    virtual String dateFormat() OVERRIDE;
     45    virtual String monthFormat() OVERRIDE;
    4546#endif
    4647};
     
    8182    return ASCIILiteral("dd/MM/yyyyy");
    8283}
     84
     85String LocaleNone::monthFormat()
     86{
     87    return ASCIILiteral("yyyy-MM");
     88}
    8389#endif
    8490
  • trunk/Source/WebCore/platform/text/LocaleWin.cpp

    r131585 r131749  
    714714}
    715715
     716String 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
    716724String LocaleWin::timeFormat()
    717725{
  • trunk/Source/WebCore/platform/text/LocaleWin.h

    r131585 r131749  
    5858#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    5959    virtual String dateFormat() OVERRIDE;
     60    virtual String monthFormat() OVERRIDE;
    6061    virtual String timeFormat() OVERRIDE;
    6162    virtual String shortTimeFormat() OVERRIDE;
     
    99100#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    100101    String m_dateFormat;
     102    String m_monthFormat;
    101103#endif
    102104#if ENABLE(CALENDAR_PICKER)
  • trunk/Source/WebCore/platform/text/Localizer.h

    r131585 r131749  
    6262    // [1] LDML http://unicode.org/reports/tr35/#Date_Format_Patterns
    6363    virtual String dateFormat() = 0;
     64
     65    // Returns a year-month format in Unicode TR35 LDML.
     66    virtual String monthFormat() = 0;
    6467
    6568    // Returns time format in Unicode TR35 LDML[1] containing hour, minute, and
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.h

    r131585 r131749  
    6363#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    6464    virtual String dateFormat() OVERRIDE;
     65    virtual String monthFormat() OVERRIDE;
    6566    virtual String timeFormat() OVERRIDE;
    6667    virtual String shortTimeFormat() OVERRIDE;
     
    8586
    8687    String m_dateFormat;
     88    String m_monthFormat;
    8789    String m_localizedTimeFormatText;
    8890    String m_localizedShortTimeFormatText;
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.mm

    r131585 r131749  
    247247}
    248248
     249String 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
    249259String LocaleMac::timeFormat()
    250260{
  • trunk/Source/WebKit/chromium/ChangeLog

    r131704 r131749  
     12012-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
    1182012-10-17  Mike West  <mkwst@chromium.org>
    219
  • trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp

    r131585 r131749  
    121121
    122122#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
    123129    String timeFormat(const String& localeString)
    124130    {
     
    237243
    238244#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
     245TEST_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
    239253TEST_F(LocaleMacTest, timeFormat)
    240254{
  • trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp

    r131585 r131749  
    130130
    131131#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
    132138    String timeFormat(LCID lcid)
    133139    {
     
    285291}
    286292
     293TEST_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
    287300TEST_F(LocaleWinTest, timeFormat)
    288301{
  • trunk/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp

    r131030 r131749  
    8989    }
    9090
     91    String monthFormat(const char* localeString)
     92    {
     93        OwnPtr<LocaleICU> locale = LocaleICU::create(localeString);
     94        return locale->monthFormat();
     95    }
     96
    9197    String localizedDateFormatText(const char* localeString)
    9298    {
     
    127133}
    128134
     135TEST_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
    129142TEST_F(LocalizedDateICUTest, localizedDateFormatText)
    130143{
Note: See TracChangeset for help on using the changeset viewer.