Changeset 53551 in webkit
- Timestamp:
- Jan 20, 2010 9:38:36 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r53550 r53551 1 2010-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 1 17 2010-01-20 Philippe Normand <pnormand@igalia.com> 2 18 -
trunk/LayoutTests/fast/forms/input-valueasdate-time-expected.txt
r52524 r53551 8 8 PASS valueAsDateFor("04:35").getTime() is Date.UTC(1970, 0, 1, 4, 35, 0, 0) 9 9 PASS valueAsDateFor("23:59:59.999").getTime() is Date.UTC(1970, 0, 1, 23, 59, 59, 999) 10 PASS setValueAsDateAndGetValue(0, 0, 0, 0) is "00:00" 11 PASS setValueAsDateAndGetValue(0, 0, 1, 0) is "00:00:01" 12 PASS setValueAsDateAndGetValue(0, 0, 0, 2) is "00:00:00.002" 13 PASS setValueAsDateAndGetValue(11, 59, 59, 999) is "11:59:59.999" 14 PASS setValueAsDateAndGetValue(12, 0, 0, 0) is "12:00" 15 PASS setValueAsDateAndGetValue(23, 59, 59, 999) is "23:59:59.999" 16 PASS setValueAsDateAndGetValue(24, 0, 0, 0) is "00:00" 17 PASS setValueAsDateAndGetValue(48, 0, 13, 0) is "00:00:13" 18 PASS setValueAsDateAndGetValue(-23, -59, -59, 0) is "00:00:01" 19 Invalid Date: 20 PASS var date = new Date(); date.setTime(8.65E15); input.valueAsDate = date; input.value is "" 21 Invalid objects: 22 PASS input.value = "00:00"; input.valueAsDate = document; input.value is "" 23 PASS input.value = "00:00"; input.valueAsDate = null; input.value is "" 24 Step attribute value and string representation: 25 FAIL input.step = "1"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00. Was 00:00. 26 FAIL input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00.000. Was 00:00. 10 27 PASS successfullyParsed is true 11 28 -
trunk/LayoutTests/fast/forms/script-tests/input-valueasdate-time.js
r52524 r53551 9 9 } 10 10 11 function 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 11 18 shouldBe('valueAsDateFor("")', 'null'); 12 19 shouldBe('valueAsDateFor("00:00:00.000").getTime()', 'Date.UTC(1970, 0, 1, 0, 0, 0, 0)'); … … 14 21 shouldBe('valueAsDateFor("23:59:59.999").getTime()', 'Date.UTC(1970, 0, 1, 23, 59, 59, 999)'); 15 22 23 shouldBe('setValueAsDateAndGetValue(0, 0, 0, 0)', '"00:00"'); 24 shouldBe('setValueAsDateAndGetValue(0, 0, 1, 0)', '"00:00:01"'); 25 shouldBe('setValueAsDateAndGetValue(0, 0, 0, 2)', '"00:00:00.002"'); 26 shouldBe('setValueAsDateAndGetValue(11, 59, 59, 999)', '"11:59:59.999"'); 27 shouldBe('setValueAsDateAndGetValue(12, 0, 0, 0)', '"12:00"'); 28 shouldBe('setValueAsDateAndGetValue(23, 59, 59, 999)', '"23:59:59.999"'); 29 shouldBe('setValueAsDateAndGetValue(24, 0, 0, 0)', '"00:00"'); 30 shouldBe('setValueAsDateAndGetValue(48, 0, 13, 0)', '"00:00:13"'); 31 shouldBe('setValueAsDateAndGetValue(-23, -59, -59, 0)', '"00:00:01"'); 32 33 debug('Invalid Date:'); 34 // Date of JavaScript can't represent 8.65E15. 35 shouldBe('var date = new Date(); date.setTime(8.65E15); input.valueAsDate = date; input.value', '""'); 36 debug('Invalid objects:'); 37 shouldBe('input.value = "00:00"; input.valueAsDate = document; input.value', '""'); 38 shouldBe('input.value = "00:00"; input.valueAsDate = null; input.value', '""'); 39 40 debug('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. 42 shouldBe('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. 44 shouldBe('input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0)', '"00:00:00.000"'); 45 16 46 var successfullyParsed = true; -
trunk/WebCore/ChangeLog
r53549 r53551 1 2010-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 1 25 2010-01-20 Csaba Osztrogonác <ossy@webkit.org> 2 26 -
trunk/WebCore/html/HTMLInputElement.cpp
r53451 r53551 1402 1402 success = dateTime.setMillisecondsSinceEpochForMonth(value); 1403 1403 break; 1404 case TIME: 1405 success = dateTime.setMillisecondsSinceMidnight(value); 1406 break; 1404 1407 // FIXME: implementations for other supported types. 1405 1408 default: … … 1411 1414 return; 1412 1415 } 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. 1413 1419 setValue(dateTime.toString()); 1414 1420 } -
trunk/WebCore/html/ISODateTime.cpp
r53445 r53551 451 451 } 452 452 453 static inline double positiveFmod(double value, double divider) 454 { 455 double remainder = fmod(value, divider); 456 return remainder < 0 ? remainder + divider : remainder; 457 } 458 459 void 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 453 470 bool ISODateTime::setMillisecondsSinceEpochForDateInternal(double ms) 454 471 { … … 470 487 return false; 471 488 m_type = Month; 489 return true; 490 } 491 492 bool ISODateTime::setMillisecondsSinceMidnight(double ms) 493 { 494 if (!isfinite(ms)) 495 return false; 496 setMillisecondsSinceMidnightInternal(positiveFmod(round(ms), msPerDay)); 497 m_type = Time; 472 498 return true; 473 499 } … … 506 532 } 507 533 508 String ISODateTime::toString() const 534 String 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 556 String ISODateTime::toString(SecondFormat format) const 509 557 { 510 558 switch (m_type) { 511 559 case Month: 512 560 return String::format("%04d-%02d", m_year, m_month + 1); 561 case Time: 562 return toStringForTime(format); 513 563 514 564 // FIXME: implementations for other types. -
trunk/WebCore/html/ISODateTime.h
r53445 r53551 69 69 int week() const { return m_week; } 70 70 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 71 77 // 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; 73 80 74 81 // The following six functions parse the input 'src' whose length is … … 100 107 // false if it fails. 101 108 102 // For Month type. 109 // For Month type. Updates m_year and m_month. 103 110 bool setMillisecondsSinceEpochForMonth(double ms); 104 111 // 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); 105 115 106 116 // Returns the number of milliseconds from 1970-01-01 00:00:00 UTC. … … 120 130 // Helper for millisecondsSinceEpoch(). 121 131 double millisecondsSinceEpochForTime() const; 122 // Helper for setMillisecondsSinceEpochFor*().132 // Helpers for setMillisecondsSinceEpochFor*(). 123 133 bool setMillisecondsSinceEpochForDateInternal(double ms); 134 void setMillisecondsSinceMidnightInternal(double ms); 135 // Helper for toString(). 136 String toStringForTime(SecondFormat) const; 124 137 125 138 // m_weekDay values
Note: See TracChangeset
for help on using the changeset viewer.