Changeset 52524 in webkit
- Timestamp:
- Dec 23, 2009 3:05:04 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 18 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r52507 r52524 1 2009-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 1 16 2009-12-22 Darin Adler <darin@apple.com> 2 17 -
trunk/JavaScriptCore/JavaScriptCore.exp
r52463 r52524 317 317 __ZN3WTF16callOnMainThreadEPFvPvES0_ 318 318 __ZN3WTF16fastZeroedMallocEm 319 __ZN3WTF18dateToDaysFrom1970Eiii 319 320 __ZN3WTF19initializeThreadingEv 320 321 __ZN3WTF20fastMallocStatisticsEv -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
r52476 r52524 87 87 ?currentThread@WTF@@YAIXZ 88 88 ?currentTime@WTF@@YANXZ 89 ?dateToDaysFrom1970@WTF@@YANHHH@Z 89 90 ?decrement@RefCountedLeakCounter@WTF@@QAEXXZ 90 91 ?defaultAttributes@PropertyDescriptor@JSC@@0IA -
trunk/JavaScriptCore/wtf/DateMath.cpp
r51986 r52524 311 311 } 312 312 313 staticdouble dateToDaysFrom1970(int year, int month, int day)313 double dateToDaysFrom1970(int year, int month, int day) 314 314 { 315 315 year += month / 12; -
trunk/JavaScriptCore/wtf/DateMath.h
r50711 r52524 77 77 const double msPerMonth = 2592000000.0; 78 78 79 // Returns the number of days from 1970-01-01 to the specified date. 80 double dateToDaysFrom1970(int year, int month, int day); 81 79 82 } // namespace WTF 83 84 using WTF::dateToDaysFrom1970; 85 using WTF::minutesPerHour; 86 using WTF::msPerDay; 87 using WTF::msPerSecond; 88 using WTF::secondsPerMinute; 80 89 81 90 #if USE(JSC) -
trunk/LayoutTests/ChangeLog
r52517 r52524 1 2009-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 1 29 2009-12-22 Kenneth Russell <kbr@google.com> 2 30 -
trunk/WebCore/ChangeLog
r52521 r52524 1 2009-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 1 37 2009-12-22 Daniel Bates <dbates@webkit.org> 2 38 -
trunk/WebCore/html/HTMLInputElement.cpp
r52434 r52524 1377 1377 double HTMLInputElement::valueAsDate() const 1378 1378 { 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 } 1383 1394 } 1384 1395 … … 2130 2141 bool HTMLInputElement::formStringToISODateTime(InputType type, const String& formString, ISODateTime* out) 2131 2142 { 2143 if (formString.isEmpty()) 2144 return false; 2132 2145 ISODateTime ignoredResult; 2133 2146 if (!out) -
trunk/WebCore/html/ISODateTime.cpp
r51066 r52524 34 34 #include <limits.h> 35 35 #include <wtf/ASCIICType.h> 36 #include <wtf/DateMath.h> 36 37 37 38 namespace WebCore { … … 294 295 m_month = month; 295 296 end = index + 2; 297 m_type = Month; 296 298 return true; 297 299 } … … 318 320 m_monthDay = day; 319 321 end = index + 2; 322 m_type = Date; 320 323 return true; 321 324 } … … 346 349 m_week = week; 347 350 end = index + 2; 351 m_type = Week; 348 352 return true; 349 353 } … … 400 404 m_millisecond = millisecond; 401 405 end = index; 406 m_type = Time; 402 407 return true; 403 408 } … … 414 419 return false; 415 420 ++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; 417 425 } 418 426 … … 430 438 if (!parseTime(src, length, index, index)) 431 439 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 446 double 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 452 double 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(); 433 477 } 434 478 -
trunk/WebCore/html/ISODateTime.h
r51063 r52524 32 32 #define ISODateTime_h 33 33 34 #include <limits> 34 35 #include <wtf/unicode/Unicode.h> 35 36 … … 53 54 , m_year(0) 54 55 , m_week(0) 56 , m_type(Invalid) 55 57 { 56 58 } … … 87 89 bool parseDateTime(const UChar* src, unsigned length, unsigned start, unsigned& end); 88 90 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 89 97 private: 90 98 // Returns the maximum week number in this ISODateTime's year. … … 95 103 bool addMinute(int); 96 104 bool parseTimeZone(const UChar* src, unsigned length, unsigned start, unsigned& end); 105 // Helper for millisecondsSinceEpoch(). 106 double millisecondsSinceEpochForTime() const; 97 107 98 108 // m_weekDay values … … 115 125 int m_year; // 1582 - 116 126 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; 117 138 }; 118 139
Note: See TracChangeset
for help on using the changeset viewer.