From 01ad078b2aa1ab574339060ec1e77e6bc46e2ee5 Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Fri, 10 Jul 2026 12:36:30 +0000 Subject: [PATCH] Stamp "now" events to the second, not the minute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The time input has no seconds and fromDateTimeInputs floors to :00, so an event logged at "now" was stored up to ~59s in the past — the big-clock counter would jump to e.g. "0:40" the instant a sleep boundary was logged. Track whether the user has actually touched the date/time fields (reset in openNoteDialog and the "Now" button, set on manual change/input). When untouched, noteDialogAt() returns the exact Date.now(); an explicitly picked time is still parsed from the inputs (minute precision is fine there). --- src/app.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/app.js b/src/app.js index 7d8ca9c..36dca93 100644 --- a/src/app.js +++ b/src/app.js @@ -1274,6 +1274,10 @@ let pendingType = null; let notePhotoBlob = null; // pending blob for the dialog (not yet committed) let notePhotoURL = null; // current preview object URL + // Whether the user has manually touched the date/time fields. While false the + // dialog logs at the exact current millisecond rather than the minute-floored + // input, so a just-logged event doesn't look up to ~59s old. + let noteTimeEdited = false; function clearNotePhoto() { notePhotoBlob = null; @@ -1288,6 +1292,7 @@ function openNoteDialog(type) { pendingType = type; noteInput.value = ""; + noteTimeEdited = false; const now = Date.now(); noteDate.value = toDateInput(now); noteTime.value = toTimeInput(now); @@ -1301,6 +1306,9 @@ } function noteDialogAt() { + // Untouched time → stamp the exact current instant (sub-minute accurate). + // Once the user picks a time, honor the input (minute precision is fine). + if (!noteTimeEdited) return Date.now(); const parsed = fromDateTimeInputs(noteDate.value, noteTime.value); return Number.isFinite(parsed) ? parsed : Date.now(); } @@ -1309,6 +1317,13 @@ const now = Date.now(); noteDate.value = toDateInput(now); noteTime.value = toTimeInput(now); + noteTimeEdited = false; // "Now" means log at the current instant again + }); + + [noteDate, noteTime].forEach(el => { + const markEdited = () => { noteTimeEdited = true; }; + el.addEventListener("change", markEdited); + el.addEventListener("input", markEdited); }); notePhotoBtn.addEventListener("click", () => notePhotoInput.click());