From 6403efa64cfe9c6a581e763b169297e09624afd5 Mon Sep 17 00:00:00 2001 From: Richard Bergsma Date: Mon, 7 Jul 2025 20:28:54 +0200 Subject: [PATCH] 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. --- src/components/UptimeStatusIsland.jsx | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/components/UptimeStatusIsland.jsx b/src/components/UptimeStatusIsland.jsx index 925f511..363c785 100644 --- a/src/components/UptimeStatusIsland.jsx +++ b/src/components/UptimeStatusIsland.jsx @@ -48,6 +48,38 @@ function getUptime24hBg(uptime) { function formatLocalTime(rawTime, zone = 'utc') { 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; // First try ISO parsing (most reliable for UTC timestamps)