fix shift to local timezone
This commit is contained in:
parent
fa8796a413
commit
ca07a7b1ba
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user