fix: show file dates in the app's language and time format

This commit is contained in:
Linus Rath
2026-10-15 02:36:00 +02:00
parent d97571cf0f
commit 63eefd7700
+17 -16
View File
@@ -54,6 +54,7 @@ import { downloadAttachment, shareAttachment } from '../lib/email-export';
import { secureFetch } from '../lib/client-cert'; import { secureFetch } from '../lib/client-cert';
import { getUniqueName } from '../lib/filenode-name'; import { getUniqueName } from '../lib/filenode-name';
import { filesGridLayout } from '../lib/files-grid'; import { filesGridLayout } from '../lib/files-grid';
import { formatListDate } from '../lib/date-format';
import { useLayout, useSheetInsets } from '../lib/use-layout'; import { useLayout, useSheetInsets } from '../lib/use-layout';
import { useBackWhileFocused } from '../lib/use-back-while-focused'; import { useBackWhileFocused } from '../lib/use-back-while-focused';
import { filesBackStep } from '../lib/files-back'; import { filesBackStep } from '../lib/files-back';
@@ -118,22 +119,20 @@ export function formatFileSize(bytes?: number): string {
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`; return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
} }
function formatModified(iso?: string): string { /**
if (!iso) return ''; * Formats a file's modified time like the mail list does: in the app's
const d = new Date(iso); * language and with the 12/24 h and date settings, instead of the device
if (Number.isNaN(d.getTime())) return ''; * defaults ("10:47 PM" next to 24 h times everywhere else).
const now = new Date(); */
const sameDay = function useFormatModified(): (iso?: string) => string {
d.getFullYear() === now.getFullYear() && const dateFormat = useSettingsStore((s) => s.dateFormat);
d.getMonth() === now.getMonth() && const timeFormat = useSettingsStore((s) => s.timeFormat);
d.getDate() === now.getDate(); const locale = useLocaleStore((s) => s.locale);
if (sameDay) { const t = useLocaleStore((s) => s.t);
return d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }); return React.useCallback(
} (iso?: string) => (iso ? formatListDate(iso, { dateFormat, timeFormat, locale, t }) : ''),
if (d.getFullYear() === now.getFullYear()) { [dateFormat, timeFormat, locale, t],
return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }); );
}
return d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
} }
// Last-modified with the creation time as fallback (webmail file-store // Last-modified with the creation time as fallback (webmail file-store
@@ -167,6 +166,7 @@ export default function FilesScreen() {
const c = useColors(); const c = useColors();
const styles = React.useMemo(() => makeStyles(c), [c]); const styles = React.useMemo(() => makeStyles(c), [c]);
const t = useLocaleStore((s) => s.t); const t = useLocaleStore((s) => s.t);
const formatModified = useFormatModified();
// Folder navigation stack. Hierarchy is real parentId nesting (#379) — each // Folder navigation stack. Hierarchy is real parentId nesting (#379) — each
// entry is the folder's node id (namespaced "accountId:nodeId" inside a // entry is the folder's node id (namespaced "accountId:nodeId" inside a
@@ -1229,6 +1229,7 @@ function ActionsSheet({
}: ActionsSheetProps) { }: ActionsSheetProps) {
// Centred on a wide window, clear of side insets in landscape. // Centred on a wide window, clear of side insets in landscape.
const sheetInsets = useSheetInsets(); const sheetInsets = useSheetInsets();
const formatModified = useFormatModified();
const c = useColors(); const c = useColors();
const styles = React.useMemo(() => makeSheetStyles(c), [c]); const styles = React.useMemo(() => makeSheetStyles(c), [c]);
if (!target) return null; if (!target) return null;