Add fallback handling for date formatting in formatLocalTime function
- Implemented a check for Luxon availability and added a fallback to native JavaScript Date for better robustness. - Enhanced error handling to log failures during date parsing attempts. - Maintained existing functionality while improving resilience against missing dependencies.
This commit is contained in:
@@ -48,6 +48,38 @@ function getUptime24hBg(uptime) {
|
|||||||
function formatLocalTime(rawTime, zone = 'utc') {
|
function formatLocalTime(rawTime, zone = 'utc') {
|
||||||
if (!rawTime) return '';
|
if (!rawTime) return '';
|
||||||
|
|
||||||
|
// Check if Luxon is available
|
||||||
|
if (typeof DateTime === 'undefined') {
|
||||||
|
console.log('PROD DEBUG: Luxon DateTime not available, using fallback');
|
||||||
|
// Fallback to native JavaScript Date
|
||||||
|
try {
|
||||||
|
const date = new Date(rawTime);
|
||||||
|
if (isNaN(date.getTime())) {
|
||||||
|
return 'Invalid DateTime';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zone === 'utc') {
|
||||||
|
return date.toISOString().slice(0, 19).replace('T', ', ').split('-').reverse().join('-');
|
||||||
|
} else {
|
||||||
|
// Convert to local time
|
||||||
|
const options = {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
timeZone: zone,
|
||||||
|
hour12: false
|
||||||
|
};
|
||||||
|
return new Intl.DateTimeFormat('en-GB', options).format(date).replace(/\//g, '-');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('PROD DEBUG: Fallback parsing failed:', e.message);
|
||||||
|
return 'Invalid DateTime';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let dt = null;
|
let dt = null;
|
||||||
|
|
||||||
// First try ISO parsing (most reliable for UTC timestamps)
|
// First try ISO parsing (most reliable for UTC timestamps)
|
||||||
|
Reference in New Issue
Block a user