Stamp "now" events to the second, not the minute
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).
This commit is contained in:
+15
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user