Changeset 121415 in webkit


Ignore:
Timestamp:
Jun 28, 2012 12:30:11 AM (12 years ago)
Author:
yosin@chromium.org
Message:

[Platform] Implement functions for localized time format information
https://bugs.webkit.org/show_bug.cgi?id=89965

Reviewed by Kent Tamura.

Source/WebCore:

This patch introduces three functions for time format:

  1. localizedTimeFormatText()
  2. localizedShortTimeFormatText()
  3. timeAMPMLabels()

for input type "time" if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS) is true.

Having both localizedTimeFormat and localizedShortTimeFormat is for
displaying only two fields hour and minute when step >= 60. There is
no way to remove second field from "h:m:s" pattern string. We don't
know whether ":" after "m" belongs minute or second field.

Test: WebKit/chromium/tests/LocalizedDateICUTest.cpp

  • platform/text/LocaleICU.cpp:

(WebCore::LocaleICU::LocaleICU):
(WebCore::createFallbackAMPMLabels): Added.
(WebCore::LocaleICU::initializeDateTimeFormat): Added.
(WebCore::LocaleICU::localizedTimeFormatText): Added.
(WebCore::LocaleICU::localizedShortTimeFormatText): Added.
(WebCore::LocaleICU::timeAMPMLabels): Added.

  • platform/text/LocaleICU.h:

(LocaleICU):

  • platform/text/LocalizedDate.h:
  • platform/text/LocalizedDateICU.cpp:

(WebCore::localizedTimeFormatText): Added.
(WebCore::localizedShortTimeFormatText): Added.
(WebCore::timeAMPMLabels): Added.

Source/WebKit/chromium:

This patch adds new test LocalizedDateICUTest if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
is true.

  • WebKit.gypi:
  • tests/LocalizedDateICUTest.cpp: Added.

(LocalizedDateICUTest):
(Labels):
(LocalizedDateICUTest::Labels::Labels):
(LocalizedDateICUTest::Labels::operator==):
(LocalizedDateICUTest::Labels::toString):
(LocalizedDateICUTest::labels):
(LocalizedDateICUTest::localizedDateFormatText):
(LocalizedDateICUTest::localizedShortDateFormatText):
(LocalizedDateICUTest::timeAMPMLabels):
(operator<<):
(TEST_F):

Location:
trunk/Source
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121412 r121415  
     12012-06-28  Yoshifumi Inoue  <yosin@chromium.org>
     2
     3        [Platform] Implement functions for localized time format information
     4        https://bugs.webkit.org/show_bug.cgi?id=89965
     5
     6        Reviewed by Kent Tamura.
     7
     8        This patch introduces three functions for time format:
     9          1. localizedTimeFormatText()
     10          2. localizedShortTimeFormatText()
     11          2. timeAMPMLabels()
     12        for input type "time" if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS) is true.
     13
     14        Having both localizedTimeFormat and localizedShortTimeFormat is for
     15        displaying only two fields hour and minute when step >= 60. There is
     16        no way to remove second field from "h:m:s" pattern string. We don't
     17        know whether ":" after "m" belongs minute or second field.
     18
     19        Test: WebKit/chromium/tests/LocalizedDateICUTest.cpp
     20
     21        * platform/text/LocaleICU.cpp:
     22        (WebCore::LocaleICU::LocaleICU):
     23        (WebCore::createFallbackAMPMLabels): Added.
     24        (WebCore::LocaleICU::initializeDateTimeFormat):  Added.
     25        (WebCore::LocaleICU::localizedTimeFormatText):  Added.
     26        (WebCore::LocaleICU::localizedShortTimeFormatText):  Added.
     27        (WebCore::LocaleICU::timeAMPMLabels):  Added.
     28        * platform/text/LocaleICU.h:
     29        (LocaleICU):
     30        * platform/text/LocalizedDate.h:
     31        * platform/text/LocalizedDateICU.cpp:
     32        (WebCore::localizedTimeFormatText):  Added.
     33        (WebCore::localizedShortTimeFormatText):  Added.
     34        (WebCore::timeAMPMLabels):  Added.
     35
    1362012-06-27  Kentaro Hara  <haraken@chromium.org>
    237
  • trunk/Source/WebCore/platform/text/LocaleICU.cpp

    r121404 r121415  
    5252    , m_firstDayOfWeek(0)
    5353#endif
     54#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     55    , m_mediumTimeFormat(0)
     56    , m_shortTimeFormat(0)
     57    , m_didCreateTimeFormat(false)
     58#endif
    5459{
    5560}
     
    318323}
    319324
    320 #if ENABLE(CALENDAR_PICKER)
     325#if ENABLE(CALENDAR_PICKER) || ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
    321326static String getDateFormatPattern(const UDateFormat* dateFormat)
    322327{
     
    335340    return String::adopt(buffer);
    336341}
    337 
     342#endif
     343
     344#if ENABLE(CALENDAR_PICKER)
    338345static inline bool isICUYearSymbol(UChar letter)
    339346{
     
    502509}
    503510
     511static PassOwnPtr<Vector<String> > createFallbackAMPMLabels()
     512{
     513    OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
     514    labels->reserveCapacity(2);
     515    labels->append("AM");
     516    labels->append("PM");
     517    return labels.release();
     518}
     519
     520void LocaleICU::initializeDateTimeFormat()
     521{
     522    if (m_didCreateTimeFormat)
     523        return;
     524
     525    // We assume ICU medium time pattern and short time pattern are compatible
     526    // with LDML, because ICU specific pattern character "V" doesn't appear
     527    // in both medium and short time pattern.
     528    m_mediumTimeFormat = openDateFormat(UDAT_MEDIUM, UDAT_NONE);
     529    m_localizedTimeFormatText = getDateFormatPattern(m_mediumTimeFormat);
     530
     531    m_shortTimeFormat = openDateFormat(UDAT_SHORT, UDAT_NONE);
     532    m_localizedShortTimeFormatText = getDateFormatPattern(m_shortTimeFormat);
     533
     534    m_timeAMPMLabels = createLabelVector(m_mediumTimeFormat, UDAT_AM_PMS, UCAL_AM, 2);
     535    if (!m_timeAMPMLabels)
     536        m_timeAMPMLabels = createFallbackAMPMLabels();
     537
     538    m_didCreateTimeFormat = true;
     539}
     540
     541String LocaleICU::localizedTimeFormatText()
     542{
     543    initializeDateTimeFormat();
     544    return m_localizedTimeFormatText;
     545}
     546
     547String LocaleICU::localizedShortTimeFormatText()
     548{
     549    initializeDateTimeFormat();
     550    return m_localizedShortTimeFormatText;
     551}
     552
     553const Vector<String>& LocaleICU::timeAMPMLabels()
     554{
     555    initializeDateTimeFormat();
     556    return *m_timeAMPMLabels;
     557}
     558
    504559#endif
    505560
  • trunk/Source/WebCore/platform/text/LocaleICU.h

    r121404 r121415  
    6868#endif
    6969
     70#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     71    String localizedTimeFormatText();
     72    String localizedShortTimeFormatText();
     73    const Vector<String>& timeAMPMLabels();
     74#endif
     75
    7076private:
    7177    static PassOwnPtr<LocaleICU> createForCurrentLocale();
     
    8389#if ENABLE(CALENDAR_PICKER)
    8490    void initializeLocalizedDateFormatText();
     91    void initializeCalendar();
     92#endif
     93
     94#if ENABLE(CALENDAR_PICKER) || ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
    8595    PassOwnPtr<Vector<String> > createLabelVector(const UDateFormat*, UDateFormatSymbolType, int32_t startIndex, int32_t size);
    86     void initializeCalendar();
     96#endif
     97
     98#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     99    void initializeDateTimeFormat();
    87100#endif
    88101
     
    110123    unsigned m_firstDayOfWeek;
    111124#endif
     125
     126#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     127    UDateFormat* m_mediumTimeFormat;
     128    UDateFormat* m_shortTimeFormat;
     129    String m_localizedTimeFormatText;
     130    String m_localizedShortTimeFormatText;
     131    OwnPtr<Vector<String> > m_timeAMPMLabels;
     132    bool m_didCreateTimeFormat;
     133#endif
    112134};
    113135
  • trunk/Source/WebCore/platform/text/LocalizedDate.h

    r115038 r121415  
    6161// The first day of a week. 0 is Sunday, and 6 is Saturday.
    6262unsigned firstDayOfWeek();
     63
     64#endif
     65
     66#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     67// Returns time format in Unicode TR35 LDML[1] containing hour, minute, and
     68// second with optional period(AM/PM), e.g. "h:mm:ss a"
     69// [1] LDML http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
     70String localizedTimeFormatText();
     71
     72// Returns time format in Unicode TR35 LDML containing hour, and minute
     73// with optional period(AM/PM), e.g. "h:mm a"
     74// Note: Some platforms return same value as localizedTimeFormatText().
     75String localizedShortTimeFormatText();
     76
     77// Returns localized period field(AM/PM) strings.
     78const Vector<String>& timeAMPMLabels();
    6379#endif
    6480} // namespace WebCore
  • trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp

    r116243 r121415  
    9393#endif
    9494
     95#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     96String localizedTimeFormatText()
     97{
     98    return LocaleICU::currentLocale()->localizedTimeFormatText();
    9599}
     100
     101String localizedShortTimeFormatText()
     102{
     103    return LocaleICU::currentLocale()->localizedShortTimeFormatText();
     104}
     105
     106const Vector<String>& timeAMPMLabels()
     107{
     108    return LocaleICU::currentLocale()->timeAMPMLabels();
     109}
     110#endif
     111
     112}
  • trunk/Source/WebKit/chromium/ChangeLog

    r121408 r121415  
     12012-06-28  Yoshifumi Inoue  <yosin@chromium.org>
     2
     3        [Platform] Implement functions for localized time format information
     4        https://bugs.webkit.org/show_bug.cgi?id=89965
     5
     6        Reviewed by Kent Tamura.
     7
     8        This patch adds new test LocalizedDateICUTest if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     9        is true.
     10
     11        * WebKit.gypi:
     12        * tests/LocalizedDateICUTest.cpp: Added.
     13        (LocalizedDateICUTest):
     14        (Labels):
     15        (LocalizedDateICUTest::Labels::Labels):
     16        (LocalizedDateICUTest::Labels::operator==):
     17        (LocalizedDateICUTest::Labels::toString):
     18        (LocalizedDateICUTest::labels):
     19        (LocalizedDateICUTest::localizedDateFormatText):
     20        (LocalizedDateICUTest::localizedShortDateFormatText):
     21        (LocalizedDateICUTest::timeAMPMLabels):
     22        (operator<<):
     23        (TEST_F):
     24
    1252012-06-27  Sheriff Bot  <webkit.review.bot@gmail.com>
    226
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r121408 r121415  
    124124            'tests/LinkHighlightTest.cpp',
    125125            'tests/ListenerLeakTest.cpp',
     126            'tests/LocalizedDateICUTest.cpp',
    126127            'tests/LocalizedNumberICUTest.cpp',
    127128            'tests/MockCCQuadCuller.h',
Note: See TracChangeset for help on using the changeset viewer.