HTML and CSS Reference
In-Depth Information
Listing 1.4 A HTML test page
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
<html lang="en">
<title>Date.prototype.strftime test</title>
<meta http-equiv="content-type"
<script type="text/javascript" src="../src/strftime.js">
<script type="text/javascript" src="strftime_test.js">
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);
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