From a9cdfb567a3f1dd29e5060c1af6b7dc960a5bb9c Mon Sep 17 00:00:00 2001 From: naielv <109038805+naielv@users.noreply.github.com> Date: Thu, 25 Dec 2025 01:46:48 +0100 Subject: [PATCH] Add fecha-diff to materiales --- src/app_modules.js | 31 +++++++++++++++++++++++++++++++ src/page/materiales.js | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/app_modules.js b/src/app_modules.js index 4ffe8cd..c8cb292 100644 --- a/src/app_modules.js +++ b/src/app_modules.js @@ -896,6 +896,37 @@ function TS_IndexElement( new_tr.appendChild(tdFechaISO); break; } + case "fecha-diff": { + const tdFechaISO = document.createElement("td"); + if (data[key.key]) { + const fecha = new Date(data[key.key]); + const now = new Date(); + const diffTime = Math.abs(now - fecha); + const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); + const diffMonths = Math.floor(diffDays / 30); + const diffYears = Math.floor(diffDays / 365); + let diffString = ""; + if (diffYears > 0) { + diffString += diffYears + " año" + (diffYears > 1 ? "s " : " "); + } + if (diffMonths % 12 > 0) { + diffString += + (diffMonths % 12) + + " mes" + + (diffMonths % 12 > 1 ? "es " : " "); + } + + // if more than 3 months, show rgb(255, 192, 192) as background + if (diffMonths >= 3) { + tdFechaISO.style.backgroundColor = "rgb(255, 192, 192)"; + } else if (diffMonths >= 1) { + tdFechaISO.style.backgroundColor = "rgb(252, 252, 176)"; + } + tdFechaISO.innerText = diffString.trim(); + } + new_tr.appendChild(tdFechaISO); + break; + } case "template": { const tdCustomTemplate = document.createElement("td"); new_tr.appendChild(tdCustomTemplate); diff --git a/src/page/materiales.js b/src/page/materiales.js index 446dd3b..f5e4bec 100644 --- a/src/page/materiales.js +++ b/src/page/materiales.js @@ -136,7 +136,7 @@ PAGES.materiales = { `; const config = [ - { key: "Revision", label: "F. Revisión", type: "fecha", default: "" }, + { key: "Revision", label: "Ult. Revisión", type: "fecha-diff", default: "" }, { key: "Nombre", label: "Nombre", type: "text", default: "" }, { key: "Ubicacion", label: "Ubicación", type: "text", default: "--" }, {