From ab3a88dbc05bf646d645f8900da404a15ee830bd Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Sat, 28 Feb 2026 03:14:24 -0500 Subject: [PATCH] fix time and ignore duplciate scans in score keeping --- public/js/timeago.js | 8 +++++++- src/models/index.js | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/public/js/timeago.js b/public/js/timeago.js index 51ada4f..61d2803 100644 --- a/public/js/timeago.js +++ b/public/js/timeago.js @@ -18,7 +18,13 @@ function updateTimes() { document.querySelectorAll('time[datetime]').forEach(function (el) { - var d = new Date(el.getAttribute('datetime')); + var raw = el.getAttribute('datetime'); + // SQLite stores UTC dates without a 'Z' suffix — add it so the browser + // parses them as UTC instead of local time + if (raw && !/[Z+\-]\d{0,4}$/i.test(raw)) { + raw = raw.replace(' ', 'T') + 'Z'; + } + var d = new Date(raw); if (!isNaN(d)) { el.textContent = timeAgo(d); el.title = d.toLocaleString(); diff --git a/src/models/index.js b/src/models/index.js index 60ff7f1..10fb17b 100644 --- a/src/models/index.js +++ b/src/models/index.js @@ -352,10 +352,8 @@ const Scans = { const alreadyScanned = this.hasUserScanned(packageId, userId); if (alreadyScanned) { - // No points, but update last_scanned_by so they can edit the hint + // No points — don't store 0-point scans, just update last_scanned_by db.prepare('UPDATE packages SET last_scanned_by = ? WHERE id = ?').run(userId, packageId); - // Record the scan with 0 points - db.prepare('INSERT INTO scans (package_id, user_id, points_awarded) VALUES (?, ?, 0)').run(packageId, userId); return { points: 0, alreadyScanned: true, isFirst: false }; }