diff --git a/HISTORY.md b/HISTORY.md
index 3b8af0e..53389a8 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -2,6 +2,7 @@ unreleased
==========
* Send non-chunked response for `OPTIONS`
+ * Use `Date.prototype.toLocaleDateString` to format date
* deps: accepts@~1.2.9
- deps: mime-types@~2.1.1
- deps: negotiator@0.5.3
diff --git a/index.js b/index.js
index 6993266..a76c543 100644
--- a/index.js
+++ b/index.js
@@ -188,7 +188,7 @@ serveIndex.html = function _html(req, res, files, next, dir, showUp, icons, path
var body = str
.replace(/\{style\}/g, style.concat(iconStyle(fileData, icons)))
- .replace(/\{files\}/g, html(fileData, dir, icons, view))
+ .replace(/\{files\}/g, createHtmlFileList(fileData, dir, icons, view))
.replace(/\{directory\}/g, escapeHtml(dir))
.replace(/\{linked-path\}/g, htmlPath(dir));
@@ -227,6 +227,67 @@ serveIndex.plain = function _plain(req, res, files) {
res.end(buf);
};
+/**
+ * Map html `files`, returning an html unordered list.
+ * @private
+ */
+
+function createHtmlFileList(files, dir, useIcons, view) {
+ var html = '
'
+ + (view == 'details' ? (
+ '') : '');
+
+ html += files.map(function (file) {
+ var classes = [];
+ var isDir = '..' == file.name || (file.stat && file.stat.isDirectory());
+ var path = dir.split('/').map(function (c) { return encodeURIComponent(c); });
+
+ if (useIcons) {
+ classes.push('icon');
+
+ if (isDir) {
+ classes.push('icon-directory');
+ } else {
+ var ext = extname(file.name);
+ var icon = iconLookup(file.name);
+
+ classes.push('icon');
+ classes.push('icon-' + ext.substring(1));
+
+ if (classes.indexOf(icon.className) === -1) {
+ classes.push(icon.className);
+ }
+ }
+ }
+
+ path.push(encodeURIComponent(file.name));
+
+ var date = file.stat && file.name !== '..'
+ ? file.stat.mtime.toLocaleDateString() + ' ' + file.stat.mtime.toLocaleTimeString()
+ : '';
+ var size = file.stat && !isDir
+ ? file.stat.size
+ : '';
+
+ return '- '
+ + '' + escapeHtml(file.name) + ''
+ + '' + escapeHtml(size) + ''
+ + '' + escapeHtml(date) + ''
+ + '
';
+ }).join('\n');
+
+ html += '
';
+
+ return html;
+}
+
/**
* Sort function for with directories first.
*/
@@ -359,62 +420,6 @@ function iconStyle (files, useIcons) {
return style;
}
-/**
- * Map html `files`, returning an html unordered list.
- */
-
-function html(files, dir, useIcons, view) {
- return ''
- + (view == 'details' ? (
- '') : '')
- + files.map(function(file){
- var isDir = '..' == file.name || (file.stat && file.stat.isDirectory())
- , classes = []
- , path = dir.split('/').map(function (c) { return encodeURIComponent(c); });
-
- if (useIcons) {
- classes.push('icon');
-
- if (isDir) {
- classes.push('icon-directory');
- } else {
- var ext = extname(file.name);
- var icon = iconLookup(file.name);
-
- classes.push('icon');
- classes.push('icon-' + ext.substring(1));
-
- if (classes.indexOf(icon.className) === -1) {
- classes.push(icon.className);
- }
- }
- }
-
- path.push(encodeURIComponent(file.name));
-
- var date = file.stat && file.name !== '..'
- ? file.stat.mtime.toDateString() + ' ' + file.stat.mtime.toLocaleTimeString()
- : '';
- var size = file.stat && !isDir
- ? file.stat.size
- : '';
-
- return '- '
- + '' + escapeHtml(file.name) + ''
- + '' + escapeHtml(size) + ''
- + '' + escapeHtml(date) + ''
- + '
';
-
- }).join('\n') + '
';
-}
-
/**
* Load and cache the given `icon`.
*