Changeset 52524 in webkit


Ignore:
Timestamp:
Dec 23, 2009 3:05:04 AM (14 years ago)
Author:
tkent@chromium.org
Message:

2009-12-23 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate getter support.
https://bugs.webkit.org/show_bug.cgi?id=32876

To implement the valueAsDate getter,

  • Add a method to calculate milliseconds from 1970-01-01 to ISODateTime.
  • Introduce m_type field to ISODateTime.

Tests: fast/forms/input-valueasdate-date.html

fast/forms/input-valueasdate-datetime.html
fast/forms/input-valueasdate-datetimelocal.html
fast/forms/input-valueasdate-month.html
fast/forms/input-valueasdate-time.html
fast/forms/input-valueasdate-week.html

  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::valueAsDate): Implement it with ISODateTime::millisecondsSinceEpoch(). (WebCore::HTMLInputElement::formStringToISODateTime): Early exit for a null String. This avoids assertion failures in ISODateTime::parse*().
  • html/ISODateTime.cpp: (WebCore::ISODateTime::parseMonth): Sets m_type. (WebCore::ISODateTime::parseDate): ditto. (WebCore::ISODateTime::parseWeek): ditto. (WebCore::ISODateTime::parseTime): ditto. (WebCore::ISODateTime::parseDateTimeLocal): ditto. (WebCore::ISODateTime::parseDateTime): ditto. (WebCore::ISODateTime::millisecondsSinceEpochForTime): Added. (WebCore::ISODateTime::millisecondsSinceEpoch): Added.
  • html/ISODateTime.h: (WebCore::ISODateTime::ISODateTime): (WebCore::ISODateTime::invalidMilliseconds):

2009-12-23 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate getter support.
https://bugs.webkit.org/show_bug.cgi?id=32876

Tests for the valueAsDate getter with various types.

  • fast/forms/input-valueasdate-date-expected.txt: Added.
  • fast/forms/input-valueasdate-date.html: Added.
  • fast/forms/input-valueasdate-datetime-expected.txt: Added.
  • fast/forms/input-valueasdate-datetime.html: Added.
  • fast/forms/input-valueasdate-datetimelocal-expected.txt: Added.
  • fast/forms/input-valueasdate-datetimelocal.html: Added.
  • fast/forms/input-valueasdate-month-expected.txt: Added.
  • fast/forms/input-valueasdate-month.html: Added.
  • fast/forms/input-valueasdate-time-expected.txt: Added.
  • fast/forms/input-valueasdate-time.html: Added.
  • fast/forms/input-valueasdate-week-expected.txt: Added.
  • fast/forms/input-valueasdate-week.html: Added.
  • fast/forms/script-tests/input-valueasdate-date.js: Added.
  • fast/forms/script-tests/input-valueasdate-datetime.js: Added.
  • fast/forms/script-tests/input-valueasdate-datetimelocal.js: Added.
  • fast/forms/script-tests/input-valueasdate-month.js: Added.
  • fast/forms/script-tests/input-valueasdate-time.js: Added.
  • fast/forms/script-tests/input-valueasdate-week.js: Added.

2009-12-23 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

HTMLInputElement::valueAsDate getter support.
https://bugs.webkit.org/show_bug.cgi?id=32876

Expose dateToDaysFrom1970().

Location:
trunk
Files:
18 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r52507 r52524  
     12009-12-23  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate getter support.
     6        https://bugs.webkit.org/show_bug.cgi?id=32876
     7
     8        Expose dateToDaysFrom1970().
     9
     10        * JavaScriptCore.exp:
     11        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     12        * wtf/DateMath.cpp:
     13        (WTF::dateToDaysFrom1970):
     14        * wtf/DateMath.h:
     15
    1162009-12-22  Darin Adler  <darin@apple.com>
    217
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r52463 r52524  
    317317__ZN3WTF16callOnMainThreadEPFvPvES0_
    318318__ZN3WTF16fastZeroedMallocEm
     319__ZN3WTF18dateToDaysFrom1970Eiii
    319320__ZN3WTF19initializeThreadingEv
    320321__ZN3WTF20fastMallocStatisticsEv
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r52476 r52524  
    8787    ?currentThread@WTF@@YAIXZ
    8888    ?currentTime@WTF@@YANXZ
     89    ?dateToDaysFrom1970@WTF@@YANHHH@Z
    8990    ?decrement@RefCountedLeakCounter@WTF@@QAEXXZ
    9091    ?defaultAttributes@PropertyDescriptor@JSC@@0IA
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r51986 r52524  
    311311}
    312312
    313 static double dateToDaysFrom1970(int year, int month, int day)
     313double dateToDaysFrom1970(int year, int month, int day)
    314314{
    315315    year += month / 12;
  • trunk/JavaScriptCore/wtf/DateMath.h

    r50711 r52524  
    7777const double msPerMonth = 2592000000.0;
    7878
     79// Returns the number of days from 1970-01-01 to the specified date.
     80double dateToDaysFrom1970(int year, int month, int day);
     81
    7982} // namespace WTF
     83
     84using WTF::dateToDaysFrom1970;
     85using WTF::minutesPerHour;
     86using WTF::msPerDay;
     87using WTF::msPerSecond;
     88using WTF::secondsPerMinute;
    8089
    8190#if USE(JSC)
  • trunk/LayoutTests/ChangeLog

    r52517 r52524  
     12009-12-23  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate getter support.
     6        https://bugs.webkit.org/show_bug.cgi?id=32876
     7
     8        Tests for the valueAsDate getter with various types.
     9
     10        * fast/forms/input-valueasdate-date-expected.txt: Added.
     11        * fast/forms/input-valueasdate-date.html: Added.
     12        * fast/forms/input-valueasdate-datetime-expected.txt: Added.
     13        * fast/forms/input-valueasdate-datetime.html: Added.
     14        * fast/forms/input-valueasdate-datetimelocal-expected.txt: Added.
     15        * fast/forms/input-valueasdate-datetimelocal.html: Added.
     16        * fast/forms/input-valueasdate-month-expected.txt: Added.
     17        * fast/forms/input-valueasdate-month.html: Added.
     18        * fast/forms/input-valueasdate-time-expected.txt: Added.
     19        * fast/forms/input-valueasdate-time.html: Added.
     20        * fast/forms/input-valueasdate-week-expected.txt: Added.
     21        * fast/forms/input-valueasdate-week.html: Added.
     22        * fast/forms/script-tests/input-valueasdate-date.js: Added.
     23        * fast/forms/script-tests/input-valueasdate-datetime.js: Added.
     24        * fast/forms/script-tests/input-valueasdate-datetimelocal.js: Added.
     25        * fast/forms/script-tests/input-valueasdate-month.js: Added.
     26        * fast/forms/script-tests/input-valueasdate-time.js: Added.
     27        * fast/forms/script-tests/input-valueasdate-week.js: Added.
     28
    1292009-12-22  Kenneth Russell  <kbr@google.com>
    230
  • trunk/WebCore/ChangeLog

    r52521 r52524  
     12009-12-23  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        HTMLInputElement::valueAsDate getter support.
     6        https://bugs.webkit.org/show_bug.cgi?id=32876
     7
     8        To implement the valueAsDate getter,
     9        - Add a method to calculate milliseconds from 1970-01-01 to ISODateTime.
     10        - Introduce m_type field to ISODateTime.
     11
     12        Tests: fast/forms/input-valueasdate-date.html
     13               fast/forms/input-valueasdate-datetime.html
     14               fast/forms/input-valueasdate-datetimelocal.html
     15               fast/forms/input-valueasdate-month.html
     16               fast/forms/input-valueasdate-time.html
     17               fast/forms/input-valueasdate-week.html
     18
     19        * html/HTMLInputElement.cpp:
     20        (WebCore::HTMLInputElement::valueAsDate):
     21          Implement it with ISODateTime::millisecondsSinceEpoch().
     22        (WebCore::HTMLInputElement::formStringToISODateTime):
     23          Early exit for a null String. This avoids assertion failures in ISODateTime::parse*().
     24        * html/ISODateTime.cpp:
     25        (WebCore::ISODateTime::parseMonth): Sets m_type.
     26        (WebCore::ISODateTime::parseDate): ditto.
     27        (WebCore::ISODateTime::parseWeek): ditto.
     28        (WebCore::ISODateTime::parseTime): ditto.
     29        (WebCore::ISODateTime::parseDateTimeLocal): ditto.
     30        (WebCore::ISODateTime::parseDateTime): ditto.
     31        (WebCore::ISODateTime::millisecondsSinceEpochForTime): Added.
     32        (WebCore::ISODateTime::millisecondsSinceEpoch): Added.
     33        * html/ISODateTime.h:
     34        (WebCore::ISODateTime::ISODateTime):
     35        (WebCore::ISODateTime::invalidMilliseconds):
     36
    1372009-12-22  Daniel Bates  <dbates@webkit.org>
    238
  • trunk/WebCore/html/HTMLInputElement.cpp

    r52434 r52524  
    13771377double HTMLInputElement::valueAsDate() const
    13781378{
    1379     // FIXME: This is a temporary implementation to check Date binding.
    1380     if (inputType() == MONTH)
    1381         return 0.0;
    1382     return std::numeric_limits<double>::quiet_NaN();
     1379    switch (inputType()) {
     1380    // valueAsDate doesn't work for the DATETIMELOCAL type according to the standard.
     1381    case DATE:
     1382    case DATETIME:
     1383    case MONTH:
     1384    case TIME:
     1385    case WEEK: {
     1386        ISODateTime dateTime;
     1387        if (!formStringToISODateTime(inputType(), value(), &dateTime))
     1388            return ISODateTime::invalidMilliseconds();
     1389        return dateTime.millisecondsSinceEpoch();
     1390    }
     1391    default:
     1392        return ISODateTime::invalidMilliseconds();
     1393    }
    13831394}
    13841395
     
    21302141bool HTMLInputElement::formStringToISODateTime(InputType type, const String& formString, ISODateTime* out)
    21312142{
     2143    if (formString.isEmpty())
     2144        return false;
    21322145    ISODateTime ignoredResult;
    21332146    if (!out)
  • trunk/WebCore/html/ISODateTime.cpp

    r51066 r52524  
    3434#include <limits.h>
    3535#include <wtf/ASCIICType.h>
     36#include <wtf/DateMath.h>
    3637
    3738namespace WebCore {
     
    294295    m_month = month;
    295296    end = index + 2;
     297    m_type = Month;
    296298    return true;
    297299}
     
    318320    m_monthDay = day;
    319321    end = index + 2;
     322    m_type = Date;
    320323    return true;
    321324}
     
    346349    m_week = week;
    347350    end = index + 2;
     351    m_type = Week;
    348352    return true;
    349353}
     
    400404    m_millisecond = millisecond;
    401405    end = index;
     406    m_type = Time;
    402407    return true;
    403408}
     
    414419        return false;
    415420    ++index;
    416     return parseTime(src, length, index, end);
     421    if (!parseTime(src, length, index, end))
     422        return false;
     423    m_type = DateTimeLocal;
     424    return true;
    417425}
    418426
     
    430438    if (!parseTime(src, length, index, index))
    431439        return false;
    432     return parseTimeZone(src, length, index, end);
     440    if (!parseTimeZone(src, length, index, end))
     441        return false;
     442    m_type = DateTime;
     443    return true;
     444}
     445
     446double ISODateTime::millisecondsSinceEpochForTime() const
     447{
     448    ASSERT(m_type == Time || m_type == DateTime);
     449    return ((m_hour * minutesPerHour + m_minute) * secondsPerMinute + m_second) * msPerSecond + m_millisecond;
     450}
     451
     452double ISODateTime::millisecondsSinceEpoch() const
     453{
     454    switch (m_type) {
     455    case Date:
     456        return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay;
     457    case DateTime:
     458    case DateTimeLocal:
     459        return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay + millisecondsSinceEpochForTime();
     460    case Month:
     461        return dateToDaysFrom1970(m_year, m_month, 1) * msPerDay;
     462    case Time:
     463        return millisecondsSinceEpochForTime();
     464    case Week: {
     465        // Offset from January 1st to Monday of the ISO 8601's first week.
     466        //   ex. If January 1st is Friday, such Monday is 3 days later.
     467        int offsetTo1stWeekStart = 1 - dayOfWeek(m_year, 0, 1);
     468        if (offsetTo1stWeekStart <= -4)
     469            offsetTo1stWeekStart += 7;
     470        return (dateToDaysFrom1970(m_year, 0, 1) + offsetTo1stWeekStart + (m_week - 1) * 7) * msPerDay;
     471    }
     472    case Invalid:
     473        break;
     474    }
     475    ASSERT_NOT_REACHED();
     476    return invalidMilliseconds();
    433477}
    434478
  • trunk/WebCore/html/ISODateTime.h

    r51063 r52524  
    3232#define ISODateTime_h
    3333
     34#include <limits>
    3435#include <wtf/unicode/Unicode.h>
    3536
     
    5354        , m_year(0)
    5455        , m_week(0)
     56        , m_type(Invalid)
    5557    {
    5658    }
     
    8789    bool parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end);
    8890
     91    // Returns the number of milliseconds from 1970-01-01 00:00:00 UTC.
     92    // For an ISODateTime initialized with parseDateTimeLocal(),
     93    // millisecondsSinceEpoch() returns a value for UTC timezone.
     94    double millisecondsSinceEpoch() const;
     95    static inline double invalidMilliseconds() { return std::numeric_limits<double>::quiet_NaN(); }
     96
    8997private:
    9098    // Returns the maximum week number in this ISODateTime's year.
     
    95103    bool addMinute(int);
    96104    bool parseTimeZone(const UChar* src, unsigned length, unsigned start, unsigned& end);
     105    // Helper for millisecondsSinceEpoch().
     106    double millisecondsSinceEpochForTime() const;
    97107
    98108    // m_weekDay values
     
    115125    int m_year;  //  1582 -
    116126    int m_week;  // 1 - 53
     127
     128    enum Type {
     129        Invalid,
     130        Date,
     131        DateTime,
     132        DateTimeLocal,
     133        Month,
     134        Time,
     135        Week,
     136    };
     137    Type m_type;
    117138};
    118139
Note: See TracChangeset for help on using the changeset viewer.