From a5c2768b9158ec9704a4eb7a342e6ddc589dac98 Mon Sep 17 00:00:00 2001 From: Owen Leong Date: Sat, 2 Oct 2021 17:53:18 +0800 Subject: [PATCH] Implement displaying last modified date in index --- lib/core/show-dir/index.js | 2 ++ lib/core/show-dir/last-modified-to-string.js | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 lib/core/show-dir/last-modified-to-string.js diff --git a/lib/core/show-dir/index.js b/lib/core/show-dir/index.js index f496b2d2..9a6891cf 100644 --- a/lib/core/show-dir/index.js +++ b/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'); @@ -114,6 +115,7 @@ module.exports = (opts) => { html += `(${permsToString(file[1])})`; } html += + `${lastModifiedToString(file[1])}` + `${sizeToString(file[1], humanReadable, si)}` + `${displayName}` + '\n'; diff --git a/lib/core/show-dir/last-modified-to-string.js b/lib/core/show-dir/last-modified-to-string.js new file mode 100644 index 00000000..8e0854dc --- /dev/null +++ b/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)); +};