4 <script src=
"../../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description('Tests for .valueAsDate with <input type=date>.');
12 var input
= document
.createElement('input');
15 function valueAsDateFor(stringValue
) {
16 input
.value
= stringValue
;
17 return input
.valueAsDate
;
20 function setValueAsDateAndGetValue(year
, month
, day
) {
21 var date
= new Date();
22 date
.setTime(Date
.UTC(year
, month
, day
));
24 date
.setUTCFullYear(year
);
25 input
.valueAsDate
= date
;
29 shouldBe('valueAsDateFor("")', 'null');
30 shouldBe('valueAsDateFor("1969-12-31").getTime()', 'Date.UTC(1969, 11, 31)');
31 shouldBe('valueAsDateFor("1970-01-01").getTime()', 'Date.UTC(1970, 0, 1)');
32 shouldBe('valueAsDateFor("2009-12-22").getTime()', 'Date.UTC(2009, 11, 22)');
34 shouldBeEqualToString('setValueAsDateAndGetValue(1969, 11, 1)', '1969-12-01');
35 shouldBeEqualToString('setValueAsDateAndGetValue(1970, 0, 1)', '1970-01-01');
36 shouldBeEqualToString('setValueAsDateAndGetValue(2009, 11, 31)', '2009-12-31');
37 shouldBeEqualToString('setValueAsDateAndGetValue(10000, 0, 1)', '10000-01-01');
39 shouldBeEqualToString('setValueAsDateAndGetValue(-1, 0, 1)', '');
40 shouldBeEqualToString('setValueAsDateAndGetValue(0, 11, 31)', '');
41 shouldBeEqualToString('setValueAsDateAndGetValue(1, 0, 1)', '0001-01-01');
42 shouldBeEqualToString('setValueAsDateAndGetValue(1582, 9, 15)', '1582-10-15');
43 shouldBeEqualToString('setValueAsDateAndGetValue(1582, 9, 31)', '1582-10-31');
44 shouldBeEqualToString('setValueAsDateAndGetValue(275760, 8, 13)', '275760-09-13');
45 shouldBeEqualToString('setValueAsDateAndGetValue(275760, 8, 14)', ''); // Date of JavaScript can't represent this.
47 debug('Invalid objects:');
48 shouldBeEqualToString('input.value = "2010-01-01"; input.valueAsDate = document; input.value', '');
49 shouldBeEqualToString('input.value = "2010-01-01"; input.valueAsDate = null; input.value', '');