From ca07a7b1bac09b38192ca49539385a7dad7ab13d Mon Sep 17 00:00:00 2001 From: lelo Date: Tue, 1 Apr 2025 21:46:30 +0000 Subject: [PATCH] fix shift to local timezone --- templates/dashboard.html | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/templates/dashboard.html b/templates/dashboard.html index 0fe9d0f..6bb385b 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -216,19 +216,17 @@ const timeframe = "{{ timeframe }}"; // e.g., 'last24hours', '7days', '30days', or '365days' const shiftedLabels = timeframeData.map(item => { if (timeframe === 'last24hours') { - // For 'last24hours', the bucket is an hour in UTC (e.g., "14") - const utcHour = parseInt(item.bucket, 10); + // For 'last24hours', the bucket is an hour in local time (e.g., "14") + const localHour = parseInt(item.bucket, 10); const now = new Date(); - // Use UTC components to get the correct UTC date - const utcStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), utcHour)); - const utcEnd = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), utcHour + 1)); - // Convert to local time strings - const localStart = utcStart.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - const localEnd = utcEnd.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - return `${localStart} - ${localEnd}`; + // Use local date components since the timestamp is already local + const localStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), localHour); + const localEnd = new Date(now.getFullYear(), now.getMonth(), now.getDate(), localHour + 1); + return `${localStart.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} - ${localEnd.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`; } else if (timeframe === '7days' || timeframe === '30days') { - const utcDate = new Date(item.bucket + 'T00:00:00Z'); - return utcDate.toLocaleDateString(); + // For these timeframes, assume the bucket is already in local date format + const localDate = new Date(item.bucket); + return localDate.toLocaleDateString(); } else if (timeframe === '365days') { const [year, month] = item.bucket.split('-'); const dateObj = new Date(year, month - 1, 1);