HTML and CSS Reference
In-Depth Information
Listing 1.4 A HTML test page
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Date.prototype.strftime test</title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8">
</head>
<body>
<script type="text/javascript" src="../src/strftime.js">
</script>
<script type="text/javascript" src="strftime_test.js">
</script>
</body>
</html>
We then copy our console session into a new file, shown in Listing 1.5, which
will serve as the test file. To log results we'll simply use console.log , which is
available in most modern browsers, and logs to the browser's JavaScript console.
Listing 1.5 strftime test.js
var date = new Date(2009, 11, 5);
console.log(date.strftime("%Y"));
console.log(date.strftime("%m"));
console.log(date.strftime("%d"));
console.log(date.strftime("%y"));
console.log(date.strftime("%F"));
We now have a reproducible test case. We can then attend to the failure:
"%y" does not zero pad the number it returns. It turns out we simply forgot
to wrap the method call in a zeroPad() call. Listing 1.6 shows the updated
Date.formats.y method.
Listing 1.6 Zero-pad year
Date.formats = {
// ...
y: function (date) {
return zeroPad(date.getYear() % 100);
}
// ...
};
 
Search WWH ::




Custom Search