Changeset 53551 in webkit


Ignore:
Timestamp:
Jan 20, 2010 9:38:36 AM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-01-20 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate setter support for type=time.
https://bugs.webkit.org/show_bug.cgi?id=33825

Add setter tests to input-valueasdate-time.js, and update the
expectation.

Note: the expectation file contains some FAIL lines. They are
intentional because they test a unimplemented feature.

  • fast/forms/input-valueasdate-time-expected.txt:
  • fast/forms/script-tests/input-valueasdate-time.js:

2010-01-20 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate setter support for type=time.
https://bugs.webkit.org/show_bug.cgi?id=33825

Introduce ISODateTime::setMillisecondsSinceMidnight() and add a
SecondFormat parameter to ISODateTime::toString(). The main code
logic for type=time is implemented in
setMillisecondsSinceMidnightInternal() and toStringForTime()
because the logic is going to be used for other types.

  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setValueAsDate):
  • html/ISODateTime.cpp: (WebCore::positiveFmod): (WebCore::ISODateTime::setMillisecondsSinceMidnightInternal): (WebCore::ISODateTime::setMillisecondsSinceMidnight): (WebCore::ISODateTime::toStringForTime): (WebCore::ISODateTime::toString):
  • html/ISODateTime.h: (WebCore::ISODateTime::):
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r53550 r53551  
     12010-01-20  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate setter support for type=time.
     6        https://bugs.webkit.org/show_bug.cgi?id=33825
     7
     8        Add setter tests to input-valueasdate-time.js, and update the
     9        expectation.
     10
     11        Note: the expectation file contains some FAIL lines. They are
     12        intentional because they test a unimplemented feature.
     13
     14        * fast/forms/input-valueasdate-time-expected.txt:
     15        * fast/forms/script-tests/input-valueasdate-time.js:
     16
    1172010-01-20  Philippe Normand  <pnormand@igalia.com>
    218
  • trunk/LayoutTests/fast/forms/input-valueasdate-time-expected.txt

    r52524 r53551  
    88PASS valueAsDateFor("04:35").getTime() is Date.UTC(1970, 0, 1, 4, 35, 0, 0)
    99PASS valueAsDateFor("23:59:59.999").getTime() is Date.UTC(1970, 0, 1, 23, 59, 59, 999)
     10PASS setValueAsDateAndGetValue(0, 0, 0, 0) is "00:00"
     11PASS setValueAsDateAndGetValue(0, 0, 1, 0) is "00:00:01"
     12PASS setValueAsDateAndGetValue(0, 0, 0, 2) is "00:00:00.002"
     13PASS setValueAsDateAndGetValue(11, 59, 59, 999) is "11:59:59.999"
     14PASS setValueAsDateAndGetValue(12, 0, 0, 0) is "12:00"
     15PASS setValueAsDateAndGetValue(23, 59, 59, 999) is "23:59:59.999"
     16PASS setValueAsDateAndGetValue(24, 0, 0, 0) is "00:00"
     17PASS setValueAsDateAndGetValue(48, 0, 13, 0) is "00:00:13"
     18PASS setValueAsDateAndGetValue(-23, -59, -59, 0) is "00:00:01"
     19Invalid Date:
     20PASS var date = new Date(); date.setTime(8.65E15); input.valueAsDate = date; input.value is ""
     21Invalid objects:
     22PASS input.value = "00:00"; input.valueAsDate = document; input.value is ""
     23PASS input.value = "00:00"; input.valueAsDate = null; input.value is ""
     24Step attribute value and string representation:
     25FAIL input.step = "1"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00. Was 00:00.
     26FAIL input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00.000. Was 00:00.
    1027PASS successfullyParsed is true
    1128
  • trunk/LayoutTests/fast/forms/script-tests/input-valueasdate-time.js

    r52524 r53551  
    99}
    1010
     11function setValueAsDateAndGetValue(hour, minute, second, ms) {
     12    var date = new Date();
     13    date.setTime(((hour * 60 + minute) * 60 + second) * 1000 + ms);
     14    input.valueAsDate = date;
     15    return input.value;
     16}
     17
    1118shouldBe('valueAsDateFor("")', 'null');
    1219shouldBe('valueAsDateFor("00:00:00.000").getTime()', 'Date.UTC(1970, 0, 1, 0, 0, 0, 0)');
     
    1421shouldBe('valueAsDateFor("23:59:59.999").getTime()', 'Date.UTC(1970, 0, 1, 23, 59, 59, 999)');
    1522
     23shouldBe('setValueAsDateAndGetValue(0, 0, 0, 0)', '"00:00"');
     24shouldBe('setValueAsDateAndGetValue(0, 0, 1, 0)', '"00:00:01"');
     25shouldBe('setValueAsDateAndGetValue(0, 0, 0, 2)', '"00:00:00.002"');
     26shouldBe('setValueAsDateAndGetValue(11, 59, 59, 999)', '"11:59:59.999"');
     27shouldBe('setValueAsDateAndGetValue(12, 0, 0, 0)', '"12:00"');
     28shouldBe('setValueAsDateAndGetValue(23, 59, 59, 999)', '"23:59:59.999"');
     29shouldBe('setValueAsDateAndGetValue(24, 0, 0, 0)', '"00:00"');
     30shouldBe('setValueAsDateAndGetValue(48, 0, 13, 0)', '"00:00:13"');
     31shouldBe('setValueAsDateAndGetValue(-23, -59, -59, 0)', '"00:00:01"');
     32
     33debug('Invalid Date:');
     34// Date of JavaScript can't represent 8.65E15.
     35shouldBe('var date = new Date(); date.setTime(8.65E15); input.valueAsDate = date; input.value', '""');
     36debug('Invalid objects:');
     37shouldBe('input.value = "00:00"; input.valueAsDate = document; input.value', '""');
     38shouldBe('input.value = "00:00"; input.valueAsDate = null; input.value', '""');
     39
     40debug('Step attribute value and string representation:');
     41// If the step attribute value is 1 second and the second part is 0, we should show the second part.
     42shouldBe('input.step = "1"; setValueAsDateAndGetValue(0, 0, 0, 0)', '"00:00:00"');
     43// If the step attribute value is 0.001 second and the millisecond part is 0, we should show the millisecond part.
     44shouldBe('input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0)', '"00:00:00.000"');
     45
    1646var successfullyParsed = true;
  • trunk/WebCore/ChangeLog

    r53549 r53551  
     12010-01-20  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate setter support for type=time.
     6        https://bugs.webkit.org/show_bug.cgi?id=33825
     7
     8        Introduce ISODateTime::setMillisecondsSinceMidnight() and add a
     9        SecondFormat parameter to ISODateTime::toString(). The main code
     10        logic for type=time is implemented in
     11        setMillisecondsSinceMidnightInternal() and toStringForTime()
     12        because the logic is going to be used for other types.
     13
     14        * html/HTMLInputElement.cpp:
     15        (WebCore::HTMLInputElement::setValueAsDate):
     16        * html/ISODateTime.cpp:
     17        (WebCore::positiveFmod):
     18        (WebCore::ISODateTime::setMillisecondsSinceMidnightInternal):
     19        (WebCore::ISODateTime::setMillisecondsSinceMidnight):
     20        (WebCore::ISODateTime::toStringForTime):
     21        (WebCore::ISODateTime::toString):
     22        * html/ISODateTime.h:
     23        (WebCore::ISODateTime::):
     24
    1252010-01-20  Csaba Osztrogonác  <ossy@webkit.org>
    226
  • trunk/WebCore/html/HTMLInputElement.cpp

    r53451 r53551  
    14021402        success = dateTime.setMillisecondsSinceEpochForMonth(value);
    14031403        break;
     1404    case TIME:
     1405        success = dateTime.setMillisecondsSinceMidnight(value);
     1406        break;
    14041407    // FIXME: implementations for other supported types.
    14051408    default:
     
    14111414        return;
    14121415    }
     1416    // FIXME: We should specify SecondFormat.
     1417    // e.g. If the step value is 60, use SecondFormat::None.
     1418    //      If the step value is 1, use SecondFormat::Second.
    14131419    setValue(dateTime.toString());
    14141420}
  • trunk/WebCore/html/ISODateTime.cpp

    r53445 r53551  
    451451}
    452452
     453static inline double positiveFmod(double value, double divider)
     454{
     455    double remainder = fmod(value, divider);
     456    return remainder < 0 ? remainder + divider : remainder;
     457}
     458
     459void ISODateTime::setMillisecondsSinceMidnightInternal(double msInDay)
     460{
     461    ASSERT(msInDay >= 0 && msInDay < msPerDay);
     462    m_millisecond = static_cast<int>(fmod(msInDay, msPerSecond));
     463    double value = floor(msInDay / msPerSecond);
     464    m_second = static_cast<int>(fmod(value, secondsPerMinute));
     465    value = floor(value / secondsPerMinute);
     466    m_minute = static_cast<int>(fmod(value, minutesPerHour));
     467    m_hour = static_cast<int>(value / minutesPerHour);
     468}
     469
    453470bool ISODateTime::setMillisecondsSinceEpochForDateInternal(double ms)
    454471{
     
    470487        return false;
    471488    m_type = Month;
     489    return true;
     490}
     491
     492bool ISODateTime::setMillisecondsSinceMidnight(double ms)
     493{
     494    if (!isfinite(ms))
     495        return false;
     496    setMillisecondsSinceMidnightInternal(positiveFmod(round(ms), msPerDay));
     497    m_type = Time;
    472498    return true;
    473499}
     
    506532}
    507533
    508 String ISODateTime::toString() const
     534String ISODateTime::toStringForTime(SecondFormat format) const
     535{
     536    ASSERT(m_type == DateTime || m_type == DateTimeLocal || m_type == Time);
     537    SecondFormat effectiveFormat = format;
     538    if (m_millisecond)
     539        effectiveFormat = Millisecond;
     540    else if (format == None && m_second)
     541        effectiveFormat = Second;
     542
     543    switch (effectiveFormat) {
     544    default:
     545        ASSERT_NOT_REACHED();
     546        // Fallback to None.
     547    case None:
     548        return String::format("%02d:%02d", m_hour, m_minute);
     549    case Second:
     550        return String::format("%02d:%02d:%02d", m_hour, m_minute, m_second);
     551    case Millisecond:
     552        return String::format("%02d:%02d:%02d.%03d", m_hour, m_minute, m_second, m_millisecond);
     553    }
     554}
     555
     556String ISODateTime::toString(SecondFormat format) const
    509557{
    510558    switch (m_type) {
    511559    case Month:
    512560        return String::format("%04d-%02d", m_year, m_month + 1);
     561    case Time:
     562        return toStringForTime(format);
    513563
    514564    // FIXME: implementations for other types.
  • trunk/WebCore/html/ISODateTime.h

    r53445 r53551  
    6969    int week() const { return m_week; }
    7070
     71    enum SecondFormat {
     72        None, // Suppress the second part and the millisecond part if they are 0.
     73        Second, // Always show the second part, and suppress the millisecond part if it is 0.
     74        Millisecond // Always show the second part and the millisecond part.
     75    };
     76
    7177    // Returns an ISO 8601 representation for this instance.
    72     String toString() const;
     78    // The format argument is valid for DateTime, DateTimeLocal, and Time types.
     79    String toString(SecondFormat format = None) const;
    7380
    7481    // The following six functions parse the input 'src' whose length is
     
    100107    // false if it fails.
    101108
    102     // For Month type.  Updates m_year and m_month.
     109    // For Month type. Updates m_year and m_month.
    103110    bool setMillisecondsSinceEpochForMonth(double ms);
    104111    // FIXME: Add setMillisecondsSinceEpochFor*() for other types.
     112
     113    // For Time type. Updates m_hour, m_minute, m_second and m_millisecond.
     114    bool setMillisecondsSinceMidnight(double ms);
    105115
    106116    // Returns the number of milliseconds from 1970-01-01 00:00:00 UTC.
     
    120130    // Helper for millisecondsSinceEpoch().
    121131    double millisecondsSinceEpochForTime() const;
    122     // Helper for setMillisecondsSinceEpochFor*().
     132    // Helpers for setMillisecondsSinceEpochFor*().
    123133    bool setMillisecondsSinceEpochForDateInternal(double ms);
     134    void setMillisecondsSinceMidnightInternal(double ms);
     135    // Helper for toString().
     136    String toStringForTime(SecondFormat) const;
    124137
    125138    // m_weekDay values
Note: See TracChangeset for help on using the changeset viewer.