Changeset 142988 in webkit


Ignore:
Timestamp:
Feb 15, 2013 6:05:04 AM (11 years ago)
Author:
keishi@webkit.org
Message:

PagePopupController.formatMonth should support short month format
https://bugs.webkit.org/show_bug.cgi?id=109530

Reviewed by Kent Tamura.

Source/WebCore:

PagePopupController.formatMonth should support short month format so we
can use it in the new calendar picker.

Tested by LocaleMacTest::formatMonth.

  • page/PagePopupController.cpp:

(WebCore::PagePopupController::formatMonth): Take an extra bool argument to switch to short month format.

  • page/PagePopupController.h:

(PagePopupController):

  • page/PagePopupController.idl:
  • platform/text/LocaleICU.cpp:

(WebCore::LocaleICU::shortMonthFormat):
(WebCore):

  • platform/text/LocaleICU.h:

(LocaleICU):

  • platform/text/LocaleNone.cpp:

(WebCore::shortMonthFormat):
(WebCore):

  • platform/text/PlatformLocale.cpp:

(WebCore::DateTimeStringBuilder::visitField):
(WebCore::Locale::formatDateTime):

  • platform/text/PlatformLocale.h:

(Locale):

  • platform/text/mac/LocaleMac.h:

(LocaleMac):

  • platform/text/mac/LocaleMac.mm:

(WebCore::LocaleMac::shortMonthFormat):
(WebCore):

  • platform/text/win/LocaleWin.cpp:

(WebCore::LocaleWin::shortMonthFormat): Windows doesn't have a short
month format so we just replace MMMM with MMM.
(WebCore):

  • platform/text/win/LocaleWin.h:

(LocaleWin):

Source/WebKit/chromium:

  • tests/LocaleMacTest.cpp:

(LocaleMacTest::formatMonth):
(TEST_F):

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142987 r142988  
     12013-02-15  Keishi Hattori  <keishi@webkit.org>
     2
     3        PagePopupController.formatMonth should support short month format
     4        https://bugs.webkit.org/show_bug.cgi?id=109530
     5
     6        Reviewed by Kent Tamura.
     7
     8        PagePopupController.formatMonth should support short month format so we
     9        can use it in the new calendar picker.
     10
     11        Tested by LocaleMacTest::formatMonth.
     12
     13        * page/PagePopupController.cpp:
     14        (WebCore::PagePopupController::formatMonth): Take an extra bool argument to switch to short month format.
     15        * page/PagePopupController.h:
     16        (PagePopupController):
     17        * page/PagePopupController.idl:
     18        * platform/text/LocaleICU.cpp:
     19        (WebCore::LocaleICU::shortMonthFormat):
     20        (WebCore):
     21        * platform/text/LocaleICU.h:
     22        (LocaleICU):
     23        * platform/text/LocaleNone.cpp:
     24        (WebCore::shortMonthFormat):
     25        (WebCore):
     26        * platform/text/PlatformLocale.cpp:
     27        (WebCore::DateTimeStringBuilder::visitField):
     28        (WebCore::Locale::formatDateTime):
     29        * platform/text/PlatformLocale.h:
     30        (Locale):
     31        * platform/text/mac/LocaleMac.h:
     32        (LocaleMac):
     33        * platform/text/mac/LocaleMac.mm:
     34        (WebCore::LocaleMac::shortMonthFormat):
     35        (WebCore):
     36        * platform/text/win/LocaleWin.cpp:
     37        (WebCore::LocaleWin::shortMonthFormat): Windows doesn't have a short
     38        month format so we just replace MMMM with MMM.
     39        (WebCore):
     40        * platform/text/win/LocaleWin.h:
     41        (LocaleWin):
     42
    1432013-02-15  Keishi Hattori  <keishi@webkit.org>
    244
  • trunk/Source/WebCore/page/PagePopupController.cpp

    r142987 r142988  
    8282    DateComponents date;
    8383    date.setMonthsSinceEpoch((year - 1970) * 12.0 + zeroBaseMonth);
    84     return m_popupClient->locale().formatDateTime(date);
     84    return m_popupClient->locale().formatDateTime(date, Locale::FormatTypeMedium);
     85}
     86
     87String PagePopupController::formatShortMonth(int year, int zeroBaseMonth)
     88{
     89    if (!m_popupClient)
     90        return emptyString();
     91    DateComponents date;
     92    date.setMonthsSinceEpoch((year - 1970) * 12.0 + zeroBaseMonth);
     93    return m_popupClient->locale().formatDateTime(date, Locale::FormatTypeShort);
    8594}
    8695#endif
  • trunk/Source/WebCore/page/PagePopupController.h

    r142987 r142988  
    5050#if ENABLE(CALENDAR_PICKER)
    5151    String formatMonth(int year, int zeroBaseMonth);
     52    String formatShortMonth(int year, int zeroBaseMonth);
    5253#endif
    5354    void clearPagePopupClient();
  • trunk/Source/WebCore/page/PagePopupController.idl

    r142987 r142988  
    3838    DOMString localizeNumberString(in DOMString numberString);
    3939    [Conditional=CALENDAR_PICKER] DOMString formatMonth(in long year, in long zeroBaseMonth);
     40    [Conditional=CALENDAR_PICKER] DOMString formatShortMonth(in long year, in long zeroBaseMonth);
    4041    void histogramEnumeration(DOMString name, long sample, long boundaryValue);
    4142};
  • trunk/Source/WebCore/platform/text/LocaleICU.cpp

    r140308 r142988  
    356356}
    357357
     358String LocaleICU::shortMonthFormat()
     359{
     360    if (!m_shortMonthFormat.isNull())
     361        return m_shortMonthFormat;
     362    m_shortMonthFormat = getFormatForSkeleton(m_locale.data(), ASCIILiteral("yyyyMMM"));
     363    return m_shortMonthFormat;
     364}
     365
    358366String LocaleICU::timeFormat()
    359367{
  • trunk/Source/WebCore/platform/text/LocaleICU.h

    r135263 r142988  
    5858    virtual String dateFormat() OVERRIDE;
    5959    virtual String monthFormat() OVERRIDE;
     60    virtual String shortMonthFormat() OVERRIDE;
    6061    virtual String timeFormat() OVERRIDE;
    6162    virtual String shortTimeFormat() OVERRIDE;
     
    104105    String m_dateFormat;
    105106    String m_monthFormat;
     107    String m_shortMonthFormat;
    106108    String m_timeFormatWithSeconds;
    107109    String m_timeFormatWithoutSeconds;
  • trunk/Source/WebCore/platform/text/LocaleNone.cpp

    r140308 r142988  
    100100}
    101101
     102String shortMonthFormat()
     103{
     104    return ASCIILiteral("yyyy-MM");
     105}
     106
    102107String LocaleNone::timeFormat()
    103108{
  • trunk/Source/WebCore/platform/text/PlatformLocale.cpp

    r142122 r142988  
    100100        appendNumber(m_date.fullYear(), 4);
    101101        return;
    102     case DateTimeFormat::FieldTypeMonth:   
     102    case DateTimeFormat::FieldTypeMonth:
    103103        if (numberOfPatternCharacters == 3)
    104104            m_builder.append(m_localizer.shortMonthLabels()[m_date.month()]);
     
    355355        break;
    356356    case DateComponents::Month:
    357         builder.build(monthFormat());
     357        builder.build(formatType == FormatTypeShort ? shortMonthFormat() : monthFormat());
    358358        break;
    359359    case DateComponents::Week:   
  • trunk/Source/WebCore/platform/text/PlatformLocale.h

    r135263 r142988  
    6868    virtual String monthFormat() = 0;
    6969
     70    // Returns a year-month format using short month lanel in Unicode TR35 LDML.
     71    virtual String shortMonthFormat() = 0;
     72
    7073    // Returns time format in Unicode TR35 LDML[1] containing hour, minute, and
    7174    // second with optional period(AM/PM), e.g. "h:mm:ss a"
     
    129132    // display to the user. If an implementation doesn't support
    130133    // localized dates the function should return an empty string.
     134    // FormatType can be used to specify if you want the short format.
    131135    String formatDateTime(const DateComponents&, FormatType = FormatTypeUnspecified);
    132136#endif
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.h

    r135263 r142988  
    6161    virtual String dateFormat() OVERRIDE;
    6262    virtual String monthFormat() OVERRIDE;
     63    virtual String shortMonthFormat() OVERRIDE;
    6364    virtual String timeFormat() OVERRIDE;
    6465    virtual String shortTimeFormat() OVERRIDE;
     
    9192    String m_dateFormat;
    9293    String m_monthFormat;
     94    String m_shortMonthFormat;
    9395    String m_timeFormatWithSeconds;
    9496    String m_timeFormatWithoutSeconds;
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.mm

    r135263 r142988  
    205205}
    206206
     207String LocaleMac::shortMonthFormat()
     208{
     209    if (!m_shortMonthFormat.isNull())
     210        return m_shortMonthFormat;
     211    m_shortMonthFormat = [NSDateFormatter dateFormatFromTemplate:@"yyyyMMM" options:0 locale:m_locale.get()];
     212    return m_shortMonthFormat;
     213}
     214
    207215String LocaleMac::timeFormat()
    208216{
  • trunk/Source/WebCore/platform/text/win/LocaleWin.cpp

    r141741 r142988  
    428428}
    429429
     430String LocaleWin::shortMonthFormat()
     431{
     432    if (m_shortMonthFormat.isNull())
     433        m_shortMonthFormat = convertWindowsDateTimeFormat(getLocaleInfoString(LOCALE_SYEARMONTH)).replace("MMMM", "MMM");
     434    return m_shortMonthFormat;
     435}
     436
    430437String LocaleWin::timeFormat()
    431438{
  • trunk/Source/WebCore/platform/text/win/LocaleWin.h

    r135263 r142988  
    5555    virtual String dateFormat() OVERRIDE;
    5656    virtual String monthFormat() OVERRIDE;
     57    virtual String shortMonthFormat() OVERRIDE;
    5758    virtual String timeFormat() OVERRIDE;
    5859    virtual String shortTimeFormat() OVERRIDE;
     
    8687    String m_dateFormat;
    8788    String m_monthFormat;
     89    String m_shortMonthFormat;
    8890    String m_timeFormatWithSeconds;
    8991    String m_timeFormatWithoutSeconds;
  • trunk/Source/WebKit/chromium/ChangeLog

    r142987 r142988  
     12013-02-15  Keishi Hattori  <keishi@webkit.org>
     2
     3        PagePopupController.formatMonth should support short month format
     4        https://bugs.webkit.org/show_bug.cgi?id=109530
     5
     6        Reviewed by Kent Tamura.
     7
     8        * tests/LocaleMacTest.cpp:
     9        (LocaleMacTest::formatMonth):
     10        (TEST_F):
     11
    1122013-02-15  Keishi Hattori  <keishi@webkit.org>
    213
  • trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp

    r134216 r142988  
    7979    }
    8080
    81     String formatMonth(const String& localeString, const String& isoString)
     81    String formatMonth(const String& localeString, const String& isoString, bool useShortFormat)
    8282    {
    8383        OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
     
    8585        unsigned end;
    8686        date.parseMonth(isoString.characters(), isoString.length(), 0, end);
    87         return locale->formatDateTime(date);
     87        return locale->formatDateTime(date, (useShortFormat ? Locale::FormatTypeShort : Locale::FormatTypeMedium));
    8888    }
    8989
     
    185185TEST_F(LocaleMacTest, formatMonth)
    186186{
    187     EXPECT_STREQ("April 2005", formatMonth("en_US", "2005-04").utf8().data());
    188     EXPECT_STREQ("avril 2005", formatMonth("fr_FR", "2005-04").utf8().data());
    189     EXPECT_STREQ("2005\xE5\xB9\xB4" "04\xE6\x9C\x88", formatMonth("ja_JP", "2005-04").utf8().data());
     187    EXPECT_STREQ("April 2005", formatMonth("en_US", "2005-04", false).utf8().data());
     188    EXPECT_STREQ("avril 2005", formatMonth("fr_FR", "2005-04", false).utf8().data());
     189    EXPECT_STREQ("2005\xE5\xB9\xB4" "04\xE6\x9C\x88", formatMonth("ja_JP", "2005-04", false).utf8().data());
     190
     191    EXPECT_STREQ("Apr 2005", formatMonth("en_US", "2005-04", true).utf8().data());
     192    EXPECT_STREQ("avr. 2005", formatMonth("fr_FR", "2005-04", true).utf8().data());
     193    EXPECT_STREQ("2005\xE5\xB9\xB4" "04\xE6\x9C\x88", formatMonth("ja_JP", "2005-04", true).utf8().data());
    190194}
    191195
Note: See TracChangeset for help on using the changeset viewer.