<!DOCTYPE HTML><html><head><title>valueAsDate stepping</title><scriptsrc="/resources/testharness.js"></script><scriptsrc="/resources/testharnessreport.js"></script></head><body><p><h3>input_valueAsDate_stepping</h3><!-- This test verifies that valueAsDate reads and writes Date values, that those values step by the correct default step, and that the values represent the correct times. --></p><hr><divid="log"></div><formmethod="post"enctype="application/x-www-form-urlencoded"action=""name="input_form"><p><inputtype='date'id='input_date'></p><p><inputtype='time'id='input_time'></p><p><inputtype='week'id='input_week'></p><p><inputtype='month'id='input_month'></p></form><script>functiontest_stepping(inputType,stringValue,steppedString,baseMillis,stepAmount){test(function(){// put date in, constructed from a UTC timestamp so the test doesn't// vary by local timezoneinput=document.getElementById("input_"+inputType);input.valueAsDate=newDate(baseMillis)// get string out (using startsWith here to allow for optional// seconds and milliseconds)varsanitizedStr=input.value;assert_true(sanitizedStr.startsWith(stringValue),"The input value ["+sanitizedStr+"] must resemble ["+stringValue+"]");// get date outvarsanitized=input.valueAsDate;assert_equals(sanitized.getTime(),baseMillis,"The input valueAsDate must represent the same time as the original Date.")// step up, get new date outinput.stepUp()varsteppedDate=input.valueAsDate;assert_equals(steppedDate.getTime(),baseMillis+stepAmount,"Stepping must be by the correct amount")// get new string outvarsteppedStrOut=input.value;assert_true(steppedStrOut.startsWith(steppedString),"The changed input value ["+steppedStrOut+"] must resemble ["+steppedString+"]");// step back down, get first date out againinput.stepDown()varbackDown=input.valueAsDate;assert_equals(backDown.getTime(),baseMillis,"Stepping back down must return the date to its original value");},inputType+" should step correctly");}varmillis_per_day=24*60*60*1000;// jan 1 midnight, step 1 day to jan 2test_stepping("date","1970-01-01","1970-01-02",0,millis_per_day);// jan 1 midnight, step 1 minute to 00:01:00test_stepping("time","00:00","00:01",0,60*1000);// jan 1 midnight, step 31 days to feb 1test_stepping("month","1970-01","1970-02",0,31*millis_per_day);// monday jan 5 1970 midnight, step 7 days to jan 12// (this has to start on a monday for stepping up and down to return)test_stepping("week","1970-W02","1970-W03",4*millis_per_day,7*millis_per_day);</script></body></html>