fix: timezone-aware timestamp parsing, favicon 404, and performance lag
This commit is contained in:
+21
-4
@@ -2559,6 +2559,23 @@
|
||||
document.body.classList.add('minimal-mode');
|
||||
}
|
||||
|
||||
// Helper: Calculate age in milliseconds robustly against UTC and local timezones
|
||||
function getTimestampAgeMs(ts) {
|
||||
if (!ts) return 999999999;
|
||||
try {
|
||||
let str = String(ts).trim();
|
||||
if (!str.endsWith('Z') && !str.includes('+') && !/[-+]\d{2}:\d{2}$/.test(str)) {
|
||||
str = str + 'Z';
|
||||
}
|
||||
const time = new Date(str).getTime();
|
||||
if (isNaN(time)) return 999999999;
|
||||
return Math.abs(Date.now() - time);
|
||||
} catch (e) {
|
||||
return 999999999;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getTargetPatientBadge() {
|
||||
const items = [];
|
||||
if (targetMrn) items.push(`<span class="patient-mrn-badge" style="padding: 4px 10px; font-size: 12px;">📋 MRN: <strong>${targetMrn}</strong></span>`);
|
||||
@@ -3127,7 +3144,7 @@
|
||||
const now = Date.now();
|
||||
for (let i = readings.length - 1; i >= 0; i--) {
|
||||
const r = readings[i];
|
||||
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999;
|
||||
const rAge = getTimestampAgeMs(r.timestamp);
|
||||
if (rAge <= 25000) {
|
||||
if (r.heart_rate != null) merged.heart_rate = r.heart_rate;
|
||||
if (r.spo2 != null) merged.spo2 = r.spo2;
|
||||
@@ -3220,7 +3237,7 @@
|
||||
const now = Date.now();
|
||||
for (let i = readings.length - 1; i >= 0; i--) {
|
||||
const r = readings[i];
|
||||
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999;
|
||||
const rAge = getTimestampAgeMs(r.timestamp);
|
||||
if (rAge <= 25000) {
|
||||
if (r.heart_rate != null) merged.heart_rate = r.heart_rate;
|
||||
if (r.spo2 != null) merged.spo2 = r.spo2;
|
||||
@@ -3652,7 +3669,7 @@
|
||||
if (readings.length > 0) {
|
||||
const now = Date.now();
|
||||
readings.forEach(r => {
|
||||
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999;
|
||||
const rAge = getTimestampAgeMs(r.timestamp);
|
||||
if (rAge > 25000) {
|
||||
r.heart_rate = null;
|
||||
r.spo2 = null;
|
||||
@@ -3743,7 +3760,7 @@
|
||||
const devKey = r.device_id;
|
||||
if (devKey && connectedDevices[devKey]) {
|
||||
const dev = connectedDevices[devKey];
|
||||
const rAge = r.timestamp ? (now - new Date(r.timestamp).getTime()) : 9999999;
|
||||
const rAge = getTimestampAgeMs(r.timestamp);
|
||||
if (rAge <= 25000) {
|
||||
if ((dev.heart_rate === undefined || dev.heart_rate === null) && r.heart_rate != null) dev.heart_rate = r.heart_rate;
|
||||
if ((dev.spo2 === undefined || dev.spo2 === null) && r.spo2 != null) dev.spo2 = r.spo2;
|
||||
|
||||
Reference in New Issue
Block a user