diff --git a/src/index.html b/src/index.html index aeeb4ac..db84665 100644 --- a/src/index.html +++ b/src/index.html @@ -59,7 +59,6 @@ Name Size - Permissions Modified @@ -71,7 +70,6 @@ - diff --git a/src/parts/files.js b/src/parts/files.js index 93054c7..bcf4412 100644 --- a/src/parts/files.js +++ b/src/parts/files.js @@ -90,4 +90,20 @@ export const formatDirectoryItemCount = (directoryItemCount) => { export const openFile = async (path) => { return await tauriInvoke('open_file', { path }); +} + +export const formatDate = (timestamp) => { + const now = (new Date).getTime(); + const date = new Date(parseInt(`${timestamp}000`)) + const then = (date).getTime(); + const diff = now - then; + const diffInDays = Math.floor(diff/(1000 * 60 * 60 * 24)); + + if (diffInDays <= 0) { + return `${date.getHours()}:${date.getMinutes()}`; + } else if (diffInDays <= 365) { + return `${date.toLocaleString('default', { month: 'short' })} ${date.getDate()}` + } + + return `${date.toLocaleString('default', { month: 'short' })} ${date.getDate()} ${date.getFullYear()}`; } \ No newline at end of file diff --git a/src/parts/files/list.js b/src/parts/files/list.js index 33190fe..9b99478 100644 --- a/src/parts/files/list.js +++ b/src/parts/files/list.js @@ -1,5 +1,5 @@ import {getTemplate} from "../../libs/template.js"; -import {formatBytes, formatDirectoryItemCount, getEntries, openFile} from "../files.js"; +import {formatBytes, formatDate, formatDirectoryItemCount, getEntries, openFile} from "../files.js"; import {getCurrentDir, navigate} from "../../libs/navigation.js"; import {getOneElementOrThrow} from "../../libs/element.js"; import {sep} from "../../libs/path.js"; @@ -42,8 +42,7 @@ export const renderListFiles = () => { if (entry.is_directory) prefix = sep; return `${prefix}${value}`; }); - applyValue(entry, itemTemplate, 'permission') - applyValue(entry, itemTemplate, 'modified') + applyValue(entry, itemTemplate, 'modified', (value) => formatDate(value)) applyValue( entry, itemTemplate,