Skip to content

Commit

Permalink
Merge pull request #737 from owenl131/autoindex-display-last-modified
Browse files Browse the repository at this point in the history
Implement displaying last modified date in index
  • Loading branch information
thornjad committed Oct 5, 2021
2 parents 08ffbf5 + a5c2768 commit b9bca4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/core/show-dir/index.js
@@ -1,6 +1,7 @@
'use strict';

const styles = require('./styles');
const lastModifiedToString = require('./last-modified-to-string');
const permsToString = require('./perms-to-string');
const sizeToString = require('./size-to-string');
const sortFiles = require('./sort-files');
Expand Down Expand Up @@ -114,6 +115,7 @@ module.exports = (opts) => {
html += `<td class="perms"><code>(${permsToString(file[1])})</code></td>`;
}
html +=
`<td class="last-modified">${lastModifiedToString(file[1])}</td>` +
`<td class="file-size"><code>${sizeToString(file[1], humanReadable, si)}</code></td>` +
`<td class="display-name"><a href="${href}">${displayName}</a></td>` +
'</tr>\n';
Expand Down
10 changes: 10 additions & 0 deletions lib/core/show-dir/last-modified-to-string.js
@@ -0,0 +1,10 @@
'use strict';

module.exports = function lastModifiedToString(stat) {
const t = new Date(stat.mtime);
return (("0" + (t.getDate())).slice(-2) + '-' +
t.toLocaleString('default', { month: 'short' }) + '-' +
t.getFullYear() + ' ' +
("0" + t.getHours()).slice(-2) + ':' +
("0" + t.getMinutes()).slice(-2));
};

0 comments on commit b9bca4e

Please sign in to comment.