[object Object]

← back to AbramsOS

claims-alert: fix daysTo — pg returns DATE as Date obj (was NaN, urgency never fired); compare calendar days

68dc94c6a611d00bc114388b26343c5834663598 · 2026-08-18 14:17:11 -0700 · Steve

Files touched

Diff

commit 68dc94c6a611d00bc114388b26343c5834663598
Author: Steve <steve@designerwallcoverings.com>
Date:   Tue Aug 18 14:17:11 2026 -0700

    claims-alert: fix daysTo — pg returns DATE as Date obj (was NaN, urgency never fired); compare calendar days
---
 lib/claims-alert.js | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/claims-alert.js b/lib/claims-alert.js
index ae525c5..eeb4d61 100644
--- a/lib/claims-alert.js
+++ b/lib/claims-alert.js
@@ -26,7 +26,17 @@ function esc(s) {
   return String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
 }
 function today() { return new Date().toISOString().slice(0, 10); }
-function daysTo(d) { return d == null ? null : Math.round((new Date(d + 'T00:00:00').getTime() - Date.now()) / 86400000); }
+// pg returns DATE columns as JS Date objects (not strings); handle both, and
+// compare CALENDAR days at local midnight so 0 = due today, 1 = tomorrow.
+function daysTo(d) {
+  if (d == null) return null;
+  const dt = d instanceof Date ? d : new Date(String(d) + 'T00:00:00');
+  if (isNaN(dt.getTime())) return null;
+  const target = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()).getTime();
+  const now = new Date();
+  const todayMid = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
+  return Math.round((target - todayMid) / 86400000);
+}
 
 async function collect(userId = USER) {
   const { rows } = await db.query(

← b757b9f AbramsOS: settlement-claim autopilot — auto-fill every open  ·  back to AbramsOS  ·  Add priority ranking + per-item ratings view to settlement-c ad64537 →