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=month>.');
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").getTime()', 'Date.UTC(1969, 11, 1, 0, 0, 0, 0)');
31 shouldBe('valueAsDateFor("1970-01").getTime()', 'Date.UTC(1970, 0, 1)');
32 shouldBe('valueAsDateFor("2009-12").getTime()', 'Date.UTC(2009, 11, 1)');
34 shouldBe('setValueAsDateAndGetValue(1969, 11, 1)', '"1969-12"');
35 shouldBe('setValueAsDateAndGetValue(1970, 0, 1)', '"1970-01"');
36 shouldBe('setValueAsDateAndGetValue(2009, 11, 31)', '"2009-12"');
37 shouldBe('setValueAsDateAndGetValue(10000, 0, 1)', '"10000-01"');
39 shouldBe('setValueAsDateAndGetValue(-1, 9, 22)', '""');
40 shouldBe('setValueAsDateAndGetValue(0, 11, 30)', '""');
41 shouldBe('setValueAsDateAndGetValue(0001, 0, 1)', '"0001-01"');
42 shouldBe('setValueAsDateAndGetValue(0001, 0, 31)', '"0001-01"');
43 shouldBe('setValueAsDateAndGetValue(275760, 8, 13)', '"275760-09"');
44 shouldBe('setValueAsDateAndGetValue(275760, 8, 14)', '""'); // Date of JavaScript can't represent this.
46 debug('Sets null to valueAsDate:');
47 input
.value
= '2009-12';
48 input
.valueAsDate
= null;
49 shouldBe('input.value', '""');