Add temporary debug logging to formatLocalTime function in UptimeStatusIsland
- Introduced console logging for various stages of date parsing to assist in production debugging. - Enhanced error handling to log failures during ISO and format parsing attempts. - Maintained existing functionality while providing insights into the parsing process.
This commit is contained in:
@@ -48,22 +48,27 @@ function getUptime24hBg(uptime) {
|
|||||||
function formatLocalTime(rawTime, zone = 'utc') {
|
function formatLocalTime(rawTime, zone = 'utc') {
|
||||||
if (!rawTime) return '';
|
if (!rawTime) return '';
|
||||||
|
|
||||||
|
// Temporary production debug logging
|
||||||
|
console.log('PROD DEBUG - Raw time:', rawTime, 'Zone:', zone);
|
||||||
|
|
||||||
let dt = null;
|
let dt = null;
|
||||||
|
|
||||||
// First try ISO parsing (most reliable for UTC timestamps)
|
// First try ISO parsing (most reliable for UTC timestamps)
|
||||||
try {
|
try {
|
||||||
dt = DateTime.fromISO(rawTime, { zone: 'utc' });
|
dt = DateTime.fromISO(rawTime, { zone: 'utc' });
|
||||||
if (dt.isValid) {
|
if (dt.isValid) {
|
||||||
|
console.log('PROD DEBUG - ISO parsing successful:', dt.toISO());
|
||||||
// If target zone is UTC, return as-is
|
// If target zone is UTC, return as-is
|
||||||
if (zone === 'utc') {
|
if (zone === 'utc') {
|
||||||
return dt.toFormat('dd-MM-yyyy, HH:mm:ss');
|
return dt.toFormat('dd-MM-yyyy, HH:mm:ss');
|
||||||
}
|
}
|
||||||
// Otherwise convert to target timezone
|
// Otherwise convert to target timezone
|
||||||
const converted = dt.setZone(zone);
|
const converted = dt.setZone(zone);
|
||||||
|
console.log('PROD DEBUG - Converted to zone:', converted.toISO());
|
||||||
return converted.isValid ? converted.toFormat('dd-MM-yyyy, HH:mm:ss') : 'Invalid DateTime';
|
return converted.isValid ? converted.toFormat('dd-MM-yyyy, HH:mm:ss') : 'Invalid DateTime';
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Continue to format parsing if ISO fails
|
console.log('PROD DEBUG - ISO parsing failed:', e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try various formats, always assuming incoming time is UTC
|
// Try various formats, always assuming incoming time is UTC
|
||||||
@@ -79,7 +84,10 @@ function formatLocalTime(rawTime, zone = 'utc') {
|
|||||||
for (const format of formats) {
|
for (const format of formats) {
|
||||||
try {
|
try {
|
||||||
dt = DateTime.fromFormat(rawTime, format, { zone: 'utc' });
|
dt = DateTime.fromFormat(rawTime, format, { zone: 'utc' });
|
||||||
if (dt.isValid) break;
|
if (dt.isValid) {
|
||||||
|
console.log('PROD DEBUG - Format parsing successful:', format, dt.toISO());
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -91,13 +99,15 @@ function formatLocalTime(rawTime, zone = 'utc') {
|
|||||||
const jsDate = new Date(rawTime);
|
const jsDate = new Date(rawTime);
|
||||||
if (!isNaN(jsDate.getTime())) {
|
if (!isNaN(jsDate.getTime())) {
|
||||||
dt = DateTime.fromJSDate(jsDate, { zone: 'utc' });
|
dt = DateTime.fromJSDate(jsDate, { zone: 'utc' });
|
||||||
|
console.log('PROD DEBUG - JS Date parsing successful:', dt.toISO());
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Give up
|
console.log('PROD DEBUG - JS Date parsing failed:', e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dt || !dt.isValid) {
|
if (!dt || !dt.isValid) {
|
||||||
|
console.log('PROD DEBUG - All parsing failed for:', rawTime);
|
||||||
return 'Invalid DateTime';
|
return 'Invalid DateTime';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user