From 93e55e8e37022a5bed7a4e6b2e58c1351a2f28cd Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Fri, 3 Jul 2026 18:41:17 +0300 Subject: [PATCH] fix(frontend): show content date in local time, not UTC The datetime-local input was populated by slicing the raw UTC ISO string, so a saved time appeared shifted by the local offset (e.g. 12:00 Moscow rendered as 09:00). Convert the UTC instant to local wall-clock on load via isoToLocalInput; the save path already round-trips local -> UTC. Co-Authored-By: Claude Opus 4.8 --- .../src/lib/components/file/FileViewer.svelte | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/file/FileViewer.svelte b/frontend/src/lib/components/file/FileViewer.svelte index 2e4f18c..abc5283 100644 --- a/frontend/src/lib/components/file/FileViewer.svelte +++ b/frontend/src/lib/components/file/FileViewer.svelte @@ -89,6 +89,18 @@ if (previewSrc) URL.revokeObjectURL(previewSrc); }); + // content_datetime is stored/returned as a UTC ISO instant, but + // works in local wall-clock time with no zone. + // Shift by the local offset so the field shows local time; the save path + // (new Date(value).toISOString()) parses it back as local and re-encodes UTC. + function isoToLocalInput(iso?: string | null): string { + if (!iso) return ''; + const d = new Date(iso); + if (Number.isNaN(d.getTime())) return ''; + const local = new Date(d.getTime() - d.getTimezoneOffset() * 60000); + return local.toISOString().slice(0, 16); // YYYY-MM-DDTHH:mm (local) + } + async function loadFile(id: string) { loading = true; error = ''; @@ -101,9 +113,7 @@ if (fileId !== id) return; // paged on; ignore file = fileData; notes = fileData.notes ?? ''; - contentDatetime = fileData.content_datetime - ? fileData.content_datetime.slice(0, 16) // YYYY-MM-DDTHH:mm - : ''; + contentDatetime = isoToLocalInput(fileData.content_datetime); isPublic = fileData.is_public ?? false; metadataNodes = objectToNodes(fileData.metadata); dirty = false;