Changeset 122190 in webkit


Ignore:
Timestamp:
Jul 9, 2012 9:31:39 PM (12 years ago)
Author:
yosin@chromium.org
Message:

[Chromium-Mac] Implement functions for localized time format information
https://bugs.webkit.org/show_bug.cgi?id=90237

Reviewed by Kent Tamura.

Source/WebCore:

This patch introduces following localized time format related
functions:

  • localizeTimeFormatText()
  • localizeShortTimeFormatText()
  • timeAMPMLabels

for Mac OSX in feature flag: ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.

These function will be used by input type "time" with multiple input
fields UI.

Note: ICU version of localized time format functions are implemented
in https://bugs.webkit.org/show_bug.cgi?id=89965

Tests: WebKit/chromium/tests/LocaleMacTest.cpp

  • platform/text/mac/LocaleMac.h:

(LocaleMac): Added time format related functions and variables.

  • platform/text/mac/LocaleMac.mm:

(WebCore::createDateTimeFormatter): Added. A helper function for creating date time formatter.
(WebCore::LocaleMac::createShortDateFormatter): Changed to use createDateTimeFormatter.
(WebCore::LocaleMac::createTimeFormatter): Added.
(WebCore::LocaleMac::createShortTimeFormatter): Added.
(WebCore::LocaleMac::timeFormatText): Added.
(WebCore::LocaleMac::shortTimeFormatText): Added.
(WebCore::LocaleMac::timeAMPMLabels): Added.

Source/WebKit/chromium:

  • tests/LocaleMacTest.cpp:

(LocaleMacTest):
(LocaleMacTest::timeFormatText):
(LocaleMacTest::shortTimeFormatText):
(LocaleMacTest::timeAMPMLabel):
(TEST_F):

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r122189 r122190  
     12012-07-09  Yoshifumi Inoue  <yosin@chromium.org>
     2
     3        [Chromium-Mac] Implement functions for localized time format information
     4        https://bugs.webkit.org/show_bug.cgi?id=90237
     5
     6        Reviewed by Kent Tamura.
     7
     8        This patch introduces following localized time format related
     9        functions:
     10          - localizeTimeFormatText()
     11          - localizeShortTimeFormatText()
     12          - timeAMPMLabels
     13        for Mac OSX in feature flag: ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.
     14
     15        These function will be used by input type "time" with multiple input
     16        fields UI.
     17
     18        Note: ICU version of localized time format functions are implemented
     19        in https://bugs.webkit.org/show_bug.cgi?id=89965
     20
     21        Tests: WebKit/chromium/tests/LocaleMacTest.cpp
     22
     23        * platform/text/mac/LocaleMac.h:
     24        (LocaleMac): Added time format related functions and variables.
     25        * platform/text/mac/LocaleMac.mm:
     26        (WebCore::createDateTimeFormatter): Added. A helper function for creating date time formatter.
     27        (WebCore::LocaleMac::createShortDateFormatter): Changed to use createDateTimeFormatter.
     28        (WebCore::LocaleMac::createTimeFormatter): Added.
     29        (WebCore::LocaleMac::createShortTimeFormatter): Added.
     30        (WebCore::LocaleMac::timeFormatText): Added.
     31        (WebCore::LocaleMac::shortTimeFormatText): Added.
     32        (WebCore::LocaleMac::timeAMPMLabels): Added.
     33
    1342012-07-09  Alexandru Chiculita  <achicu@adobe.com>
    235
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.h

    r122184 r122190  
    5959#endif
    6060
     61#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     62    String timeFormatText();
     63    String shortTimeFormatText();
     64    const Vector<String>& timeAMPMLabels();
     65#endif
     66
    6167private:
    6268    explicit LocaleMac(const String&);
     
    6975    Vector<String> m_weekDayShortLabels;
    7076#endif
     77#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     78    NSDateFormatter *createTimeFormatter();
     79    NSDateFormatter *createShortTimeFormatter();
     80
     81    String m_localizedTimeFormatText;
     82    String m_localizedShortTimeFormatText;
     83    Vector<String> m_timeAMPMLabels;
     84#endif
    7185};
    7286
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.mm

    r122184 r122190  
    4545namespace WebCore {
    4646
    47 LocaleMac::LocaleMac(const String& localeIdentifier)
    48     : m_locale([[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier])
    49 {
    50 }
    51 
    52 LocaleMac::~LocaleMac()
    53 {
    54 }
    55 
    56 PassOwnPtr<LocaleMac> LocaleMac::create(const String& localeIdentifier)
    57 {
    58     return adoptPtr(new LocaleMac(localeIdentifier));
    59 }
    60 
    61 LocaleMac* LocaleMac::currentLocale()
    62 {
    63     static LocaleMac* currentLocale = LocaleMac::create([NSLocale currentLocale]).leakPtr();
    64     return currentLocale;
    65 }
    66 
    67 NSDateFormatter* LocaleMac::createShortDateFormatter()
     47static NSDateFormatter* createDateTimeFormatter(NSLocale* locale, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle)
    6848{
    6949    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    70     [formatter setLocale:m_locale.get()];
    71     [formatter setDateStyle:NSDateFormatterShortStyle];
    72     [formatter setTimeStyle:NSDateFormatterNoStyle];
     50    [formatter setLocale:locale];
     51    [formatter setDateStyle:dateStyle];
     52    [formatter setTimeStyle:timeStyle];
    7353    [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
    7454    [formatter setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]];
    7555    return formatter;
     56}
     57
     58LocaleMac::LocaleMac(const String& localeIdentifier)
     59    : m_locale([[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier])
     60{
     61}
     62
     63LocaleMac::~LocaleMac()
     64{
     65}
     66
     67PassOwnPtr<LocaleMac> LocaleMac::create(const String& localeIdentifier)
     68{
     69    return adoptPtr(new LocaleMac(localeIdentifier));
     70}
     71
     72LocaleMac* LocaleMac::currentLocale()
     73{
     74    static LocaleMac* currentLocale = LocaleMac::create([NSLocale currentLocale]).leakPtr();
     75    return currentLocale;
     76}
     77
     78NSDateFormatter* LocaleMac::createShortDateFormatter()
     79{
     80    return createDateTimeFormatter(m_locale.get(), NSDateFormatterShortStyle, NSDateFormatterNoStyle);
    7681}
    7782
     
    195200}
    196201#endif
    197 }
     202
     203#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     204NSDateFormatter* LocaleMac::createTimeFormatter()
     205{
     206    return createDateTimeFormatter(m_locale.get(), NSDateFormatterNoStyle, NSDateFormatterMediumStyle);
     207}
     208
     209NSDateFormatter* LocaleMac::createShortTimeFormatter()
     210{
     211    return createDateTimeFormatter(m_locale.get(), NSDateFormatterNoStyle, NSDateFormatterShortStyle);
     212}
     213
     214String LocaleMac::timeFormatText()
     215{
     216    if (!m_localizedTimeFormatText.isEmpty())
     217        return m_localizedTimeFormatText;
     218    RetainPtr<NSDateFormatter> formatter(AdoptNS, createTimeFormatter());
     219    m_localizedTimeFormatText = String([formatter.get() dateFormat]);
     220    return m_localizedTimeFormatText;
     221}
     222
     223String LocaleMac::shortTimeFormatText()
     224{
     225    if (!m_localizedShortTimeFormatText.isEmpty())
     226        return m_localizedShortTimeFormatText;
     227    RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortTimeFormatter());
     228    m_localizedShortTimeFormatText = String([formatter.get() dateFormat]);
     229    return m_localizedShortTimeFormatText;
     230}
     231
     232const Vector<String>& LocaleMac::timeAMPMLabels()
     233{
     234    if (!m_timeAMPMLabels.isEmpty())
     235        return m_timeAMPMLabels;
     236    m_timeAMPMLabels.reserveCapacity(2);
     237    RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortTimeFormatter());
     238    m_timeAMPMLabels.append(String([formatter.get() AMSymbol]));
     239    m_timeAMPMLabels.append(String([formatter.get() PMSymbol]));
     240    return m_timeAMPMLabels;
     241}
     242#endif
     243}
  • trunk/Source/WebKit/chromium/ChangeLog

    r122185 r122190  
     12012-07-09  Yoshifumi Inoue  <yosin@chromium.org>
     2
     3        [Chromium-Mac] Implement functions for localized time format information
     4        https://bugs.webkit.org/show_bug.cgi?id=90237
     5
     6        Reviewed by Kent Tamura.
     7
     8        * tests/LocaleMacTest.cpp:
     9        (LocaleMacTest):
     10        (LocaleMacTest::timeFormatText):
     11        (LocaleMacTest::shortTimeFormatText):
     12        (LocaleMacTest::timeAMPMLabel):
     13        (TEST_F):
     14
    1152012-07-09  Eric Penner  <epenner@google.com>
    216
  • trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp

    r122184 r122190  
    100100    }
    101101#endif
     102
     103#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     104    String timeFormatText(const String& localeString)
     105    {
     106        OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
     107        return locale->timeFormatText();
     108    }
     109
     110    String shortTimeFormatText(const String& localeString)
     111    {
     112        OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
     113        return locale->shortTimeFormatText();
     114    }
     115
     116    String timeAMPMLabel(const String& localeString, unsigned index)
     117    {
     118        OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
     119        return locale->timeAMPMLabels()[index];
     120    }
     121#endif
    102122};
    103123
     
    161181}
    162182#endif
     183
     184#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     185TEST_F(LocaleMacTest, timeFormatText)
     186{
     187    EXPECT_STREQ("h:mm:ss a", timeFormatText("en_US").utf8().data());
     188    EXPECT_STREQ("HH:mm:ss", timeFormatText("fr_FR").utf8().data());
     189    EXPECT_STREQ("H:mm:ss", timeFormatText("ja_JP").utf8().data());
     190}
     191
     192TEST_F(LocaleMacTest, shortTimeFormatText)
     193{
     194    EXPECT_STREQ("h:mm a", shortTimeFormatText("en_US").utf8().data());
     195    EXPECT_STREQ("HH:mm", shortTimeFormatText("fr_FR").utf8().data());
     196    EXPECT_STREQ("H:mm", shortTimeFormatText("ja_JP").utf8().data());
     197}
     198
     199TEST_F(LocaleMacTest, timeAMPMLabels)
     200{
     201    EXPECT_STREQ("AM", timeAMPMLabel("en_US", 0).utf8().data());
     202    EXPECT_STREQ("PM", timeAMPMLabel("en_US", 1).utf8().data());
     203
     204    EXPECT_STREQ("AM", timeAMPMLabel("fr_FR", 0).utf8().data());
     205    EXPECT_STREQ("PM", timeAMPMLabel("fr_FR", 1).utf8().data());
     206
     207    EXPECT_STREQ("\xE5\x8D\x88\xE5\x89\x8D", timeAMPMLabel("ja_JP", 0).utf8().data());
     208    EXPECT_STREQ("\xE5\x8D\x88\xE5\xBE\x8C", timeAMPMLabel("ja_JP", 1).utf8().data());
     209}
     210#endif
Note: See TracChangeset for help on using the changeset viewer.