diff --git a/public/app.js b/public/app.js index 82242dc..9253f34 100644 --- a/public/app.js +++ b/public/app.js @@ -95,6 +95,29 @@ function getFormattedDateTime() { }; } +// Вспомогательные функции для корректной работы с временем (UTC -> локаль) +function parseSQLiteUtc(ts) { + return new Date(ts.replace(" ", "T") + "Z"); +} + +function formatLocalDateTime(date) { + return new Intl.DateTimeFormat("ru-RU", { + day: "2-digit", + month: "2-digit", + year: "numeric", + hour: "2-digit", + minute: "2-digit", + }).format(date); +} + +function formatLocalDateOnly(date) { + return new Intl.DateTimeFormat("ru-RU", { + day: "2-digit", + month: "2-digit", + year: "numeric", + }).format(date); +} + // Функция для авторасширения текстового поля function autoExpandTextarea(textarea) { textarea.style.height = "auto"; @@ -1200,24 +1223,21 @@ async function renderNotes(notes) { imagesHtml += ""; } - // Форматируем дату создания и дату изменения (в одну строку) - let dateDisplay = `${note.date} ${note.time}`; - if (note.updated_at && note.created_at !== note.updated_at) { - const createdDate = new Date(note.created_at); - const updatedDate = new Date(note.updated_at); - - const formatDate = (date) => { - const day = String(date.getDate()).padStart(2, "0"); - const month = String(date.getMonth() + 1).padStart(2, "0"); - const year = date.getFullYear(); - const hours = String(date.getHours()).padStart(2, "0"); - const minutes = String(date.getMinutes()).padStart(2, "0"); - return `${day}.${month}.${year} ${hours}:${minutes}`; - }; - - dateDisplay = `Создано: ${formatDate( - createdDate - )} • Изменено: ${formatDate(updatedDate)}`; + // Форматируем дату создания и изменения по локали устройства + let dateDisplay; + if (note.created_at) { + const created = parseSQLiteUtc(note.created_at); + if (note.updated_at && note.created_at !== note.updated_at) { + const updated = parseSQLiteUtc(note.updated_at); + dateDisplay = `Создано: ${formatLocalDateTime( + created + )} • Изменено: ${formatLocalDateTime(updated)}`; + } else { + dateDisplay = formatLocalDateTime(created); + } + } else { + // Фолбэк для старых записей + dateDisplay = `${note.date} ${note.time}`; } const noteHtml = ` @@ -2335,11 +2355,7 @@ let currentDate = new Date(); // Функция для преобразования timestamp в формат dd.mm.yyyy function formatDateFromTimestamp(timestamp) { - const date = new Date(timestamp); - const day = String(date.getDate()).padStart(2, "0"); - const month = String(date.getMonth() + 1).padStart(2, "0"); - const year = date.getFullYear(); - return `${day}.${month}.${year}`; + return formatLocalDateOnly(parseSQLiteUtc(timestamp)); } // Функция для отображения календаря