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') {
|
||||
if (!rawTime) return '';
|
||||
|
||||
// Temporary production debug logging
|
||||
console.log('PROD DEBUG - Raw time:', rawTime, 'Zone:', zone);
|
||||
|
||||
let dt = null;
|
||||
|
||||
// First try ISO parsing (most reliable for UTC timestamps)
|
||||
try {
|
||||
dt = DateTime.fromISO(rawTime, { zone: 'utc' });
|
||||
if (dt.isValid) {
|
||||
console.log('PROD DEBUG - ISO parsing successful:', dt.toISO());
|
||||
// If target zone is UTC, return as-is
|
||||
if (zone === 'utc') {
|
||||
return dt.toFormat('dd-MM-yyyy, HH:mm:ss');
|
||||
}
|
||||
// Otherwise convert to target timezone
|
||||
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';
|
||||
}
|
||||
} 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
|
||||
@@ -79,7 +84,10 @@ function formatLocalTime(rawTime, zone = 'utc') {
|
||||
for (const format of formats) {
|
||||
try {
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
@@ -91,13 +99,15 @@ function formatLocalTime(rawTime, zone = 'utc') {
|
||||
const jsDate = new Date(rawTime);
|
||||
if (!isNaN(jsDate.getTime())) {
|
||||
dt = DateTime.fromJSDate(jsDate, { zone: 'utc' });
|
||||
console.log('PROD DEBUG - JS Date parsing successful:', dt.toISO());
|
||||
}
|
||||
} catch (e) {
|
||||
// Give up
|
||||
console.log('PROD DEBUG - JS Date parsing failed:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dt || !dt.isValid) {
|
||||
console.log('PROD DEBUG - All parsing failed for:', rawTime);
|
||||
return 'Invalid DateTime';
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user