Bug 98237 - Implement localizeValue for TimeInputType
Summary: Implement localizeValue for TimeInputType
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Keishi Hattori
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-03 00:36 PDT by Keishi Hattori
Modified: 2012-10-03 20:36 PDT (History)
8 users (show)

See Also:


Attachments
Patch (22.58 KB, patch)
2012-10-03 00:54 PDT, Keishi Hattori
no flags Details | Formatted Diff | Diff
Patch (24.22 KB, patch)
2012-10-03 04:13 PDT, Keishi Hattori
no flags Details | Formatted Diff | Diff
Patch (24.30 KB, patch)
2012-10-03 05:16 PDT, Keishi Hattori
no flags Details | Formatted Diff | Diff
Just added if around DateTimeStringBuilder (24.34 KB, patch)
2012-10-03 05:23 PDT, Keishi Hattori
no flags Details | Formatted Diff | Diff
Added UNUSED_PARAM for Localizer::formatDateTime (24.40 KB, patch)
2012-10-03 05:30 PDT, Keishi Hattori
no flags Details | Formatted Diff | Diff
Patch (25.51 KB, patch)
2012-10-03 06:30 PDT, Keishi Hattori
no flags Details | Formatted Diff | Diff
Patch (25.88 KB, patch)
2012-10-03 19:14 PDT, Keishi Hattori
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Keishi Hattori 2012-10-03 00:36:26 PDT
We need to implement localizeValue for TimeInputType
Comment 1 Keishi Hattori 2012-10-03 00:54:18 PDT
Created attachment 166822 [details]
Patch
Comment 2 Kent Tamura 2012-10-03 01:38:50 PDT
Comment on attachment 166822 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166822&action=review

> Source/WebCore/platform/text/Localizer.cpp:44
> +    DateTimeStringBuilder(Localizer*, const DateComponents&);

The first argument should be Localizer& to make sure it's non-null.

> Source/WebCore/platform/text/Localizer.cpp:57
> +    Localizer* m_localizer;

ditto.  should be Localizer&.

> Source/WebCore/platform/text/Localizer.cpp:58
> +    const DateComponents m_date;

should be "const DateComponents&"

> Source/WebCore/platform/text/Localizer.cpp:79
> +    StringBuilder builder;

Existence of builder and m_builder in a function is confusing.  Please rename builder to something else.

> Source/WebCore/platform/text/Localizer.cpp:83
> +    builder.append(String::number(number));
> +    for (size_t i = builder.length(); i < width; ++i)
> +        builder.append("0");

It looks wrong.

String numberString = String::number(number);
for (size_t i = numberString.length(); i < width; ++i)
    builder.append("0");
builder.append(numberString);

> Source/WebCore/platform/text/Localizer.cpp:111
> +        appendNumber(hour24, numberOfPatternCharacters);
> +        appendNumber(hour24, numberOfPatternCharacters);

Why do you add twice?

> Source/WebCore/platform/text/Localizer.cpp:126
> +    case DateTimeFormat::FieldTypeSecond:
> +        appendNumber(m_date.second(), numberOfPatternCharacters);
> +        return;
> +    case DateTimeFormat::FieldTypeFractionalSecond: {
> +        int fractionalSecond = m_date.millisecond();
> +        if (numberOfPatternCharacters > 3)
> +            fractionalSecond *= pow(10, numberOfPatternCharacters - 3);
> +        String fractionalSecondString = String::format("%03d", fractionalSecond).left(numberOfPatternCharacters);
> +        m_builder.append(m_localizer->convertToLocalizedNumber(fractionalSecondString));
> +        return;

We should serialize millisecond part of the DateComponents with non-zero millisecond even if the format has no fractional second field.
So, you can ignore DateTimeFormat::FieldTypeFractionalSecond case, and can do everything for second and millisecond in the DateTimeFormat::FieldTypeSecond block above.

> Source/WebCore/platform/text/Localizer.cpp:329
> +{
> +    DateTimeStringBuilder builder(this, date);

should reject non-time types.

> Source/WebCore/platform/text/Localizer.h:104
> +    enum FormatType { UnspecifiedFormatType, ShortFormatType, MediumFormatType };

Enum names should be FormatTypeUnspecified, FormatTypeShort, FormatTypeMedium.

> Source/WebKit/chromium/tests/LocaleMacTest.cpp:157
> +    EXPECT_STREQ("1:23:00 PM", formatTime("en_US", 13, 23).utf8().data());
> +    EXPECT_STREQ("13:23:00", formatTime("fr_FR", 13, 23).utf8().data());
> +    EXPECT_STREQ("13:23:00", formatTime("ja_JP", 13, 23).utf8().data());
> +    EXPECT_STREQ("12:00:00 AM", formatTime("en_US", 00, 00).utf8().data());
> +    EXPECT_STREQ("00:00:00", formatTime("fr_FR", 00, 00).utf8().data());
> +    EXPECT_STREQ("0:00:00", formatTime("ja_JP", 00, 00).utf8().data());

We should have tests for:
  - the short format.
  - non-short format + non-zero second time.
  - non-zero millisecond time.
  - native digits such as "ar", "fa" locales
Comment 3 Keishi Hattori 2012-10-03 04:08:24 PDT
Comment on attachment 166822 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166822&action=review

>> Source/WebCore/platform/text/Localizer.cpp:44
>> +    DateTimeStringBuilder(Localizer*, const DateComponents&);
> 
> The first argument should be Localizer& to make sure it's non-null.

Done.

>> Source/WebCore/platform/text/Localizer.cpp:57
>> +    Localizer* m_localizer;
> 
> ditto.  should be Localizer&.

Done.

>> Source/WebCore/platform/text/Localizer.cpp:58
>> +    const DateComponents m_date;
> 
> should be "const DateComponents&"

Done.

>> Source/WebCore/platform/text/Localizer.cpp:79
>> +    StringBuilder builder;
> 
> Existence of builder and m_builder in a function is confusing.  Please rename builder to something else.

Done. Renamed to zeroPaddedStringBuilder.

>> Source/WebCore/platform/text/Localizer.cpp:83
>> +        builder.append("0");
> 
> It looks wrong.
> 
> String numberString = String::number(number);
> for (size_t i = numberString.length(); i < width; ++i)
>     builder.append("0");
> builder.append(numberString);

Done.

>> Source/WebCore/platform/text/Localizer.cpp:111
>> +        appendNumber(hour24, numberOfPatternCharacters);
> 
> Why do you add twice?

Done.

>> Source/WebCore/platform/text/Localizer.cpp:126
>> +        return;
> 
> We should serialize millisecond part of the DateComponents with non-zero millisecond even if the format has no fractional second field.
> So, you can ignore DateTimeFormat::FieldTypeFractionalSecond case, and can do everything for second and millisecond in the DateTimeFormat::FieldTypeSecond block above.

Done.

>> Source/WebCore/platform/text/Localizer.cpp:329
>> +    DateTimeStringBuilder builder(this, date);
> 
> should reject non-time types.

Done.

>> Source/WebKit/chromium/tests/LocaleMacTest.cpp:157
>> +    EXPECT_STREQ("0:00:00", formatTime("ja_JP", 00, 00).utf8().data());
> 
> We should have tests for:
>   - the short format.
>   - non-short format + non-zero second time.
>   - non-zero millisecond time.
>   - native digits such as "ar", "fa" locales

Done.
Comment 4 Keishi Hattori 2012-10-03 04:13:54 PDT
Created attachment 166853 [details]
Patch
Comment 5 Early Warning System Bot 2012-10-03 04:20:24 PDT
Comment on attachment 166853 [details]
Patch

Attachment 166853 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/14126714
Comment 6 Peter Beverloo (cr-android ews) 2012-10-03 04:25:10 PDT
Comment on attachment 166853 [details]
Patch

Attachment 166853 [details] did not pass cr-android-ews (chromium-android):
Output: http://queues.webkit.org/results/14130700
Comment 7 Build Bot 2012-10-03 04:26:41 PDT
Comment on attachment 166853 [details]
Patch

Attachment 166853 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14118844
Comment 8 Gyuyoung Kim 2012-10-03 04:26:54 PDT
Comment on attachment 166853 [details]
Patch

Attachment 166853 [details] did not pass efl-ews (efl):
Output: http://queues.webkit.org/results/14142004
Comment 9 Early Warning System Bot 2012-10-03 04:28:52 PDT
Comment on attachment 166853 [details]
Patch

Attachment 166853 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/14148002
Comment 10 Kent Tamura 2012-10-03 04:29:32 PDT
Comment on attachment 166853 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166853&action=review

> Source/WebCore/platform/text/Localizer.cpp:126
> +            float second = m_date.second() + m_date.millisecond() / 1000.0;
> +            String zeroPaddedSecondString = zeroPadString(String::format("%.03f", second), numberOfPatternCharacters + 4);

The variable 'second' should be double because
 - printf accepts only double for floating point numbers
 - m_date.millisecond() / 1000.0 is double
Comment 11 Build Bot 2012-10-03 04:35:44 PDT
Comment on attachment 166853 [details]
Patch

Attachment 166853 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/14137545
Comment 12 Keishi Hattori 2012-10-03 05:16:09 PDT
Created attachment 166862 [details]
Patch
Comment 13 Build Bot 2012-10-03 05:20:26 PDT
Comment on attachment 166862 [details]
Patch

Attachment 166862 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14118854
Comment 14 Keishi Hattori 2012-10-03 05:23:30 PDT
Created attachment 166864 [details]
Just added if around DateTimeStringBuilder
Comment 15 Build Bot 2012-10-03 05:26:53 PDT
Comment on attachment 166864 [details]
Just added if around DateTimeStringBuilder

Attachment 166864 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14152083
Comment 16 Keishi Hattori 2012-10-03 05:30:02 PDT
Created attachment 166866 [details]
Added UNUSED_PARAM for Localizer::formatDateTime
Comment 17 Kent Tamura 2012-10-03 05:32:00 PDT
Comment on attachment 166866 [details]
Added UNUSED_PARAM for Localizer::formatDateTime

ok.
Please make sure this won't break builds.
Comment 18 Peter Beverloo (cr-android ews) 2012-10-03 05:46:30 PDT
Comment on attachment 166866 [details]
Added UNUSED_PARAM for Localizer::formatDateTime

Attachment 166866 [details] did not pass cr-android-ews (chromium-android):
Output: http://queues.webkit.org/results/14123718
Comment 19 Build Bot 2012-10-03 05:59:32 PDT
Comment on attachment 166866 [details]
Added UNUSED_PARAM for Localizer::formatDateTime

Attachment 166866 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/14125762
Comment 20 Keishi Hattori 2012-10-03 06:30:24 PDT
Created attachment 166880 [details]
Patch
Comment 21 Peter Beverloo (cr-android ews) 2012-10-03 06:44:04 PDT
Comment on attachment 166880 [details]
Patch

Attachment 166880 [details] did not pass cr-android-ews (chromium-android):
Output: http://queues.webkit.org/results/14130747
Comment 22 Keishi Hattori 2012-10-03 19:14:22 PDT
Created attachment 167020 [details]
Patch
Comment 23 WebKit Review Bot 2012-10-03 20:36:31 PDT
Comment on attachment 167020 [details]
Patch

Clearing flags on attachment: 167020

Committed r130357: <http://trac.webkit.org/changeset/130357>
Comment 24 WebKit Review Bot 2012-10-03 20:36:36 PDT
All reviewed patches have been landed.  Closing bug.