Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): show message chart hours in local time and mark UTC days

Yudhi Armyndharis860864fb8f56
diff --git a/dashboard/src/components/DashboardCharts.tsx b/dashboard/src/components/DashboardCharts.tsx
index 888fa5323..7ea3b4ba5 100644
--- a/dashboard/src/components/DashboardCharts.tsx
+++ b/dashboard/src/components/DashboardCharts.tsx
@@ -18,6 +18,7 @@ import {
import { BarChart3 } from 'lucide-react';
import { useStatsMessagesQuery } from '../hooks/queries';
import type { StatsPeriod } from '../services/api';
+import { formatTick } from '../utils/chartTicks';
import './DashboardCharts.css';
const PERIODS: StatsPeriod[] = ['24h', '7d', '30d'];
@@ -50,11 +51,6 @@ function colorForType(name: string): string {
return FALLBACK_COLORS[Math.abs(hash) % FALLBACK_COLORS.length];
}
-// '2026-06-24 14:00:00' (hour buckets) → '14:00'; '2026-06-24' (day buckets) → '06-24'.
-function formatTick(ts: string, period: StatsPeriod): string {
- return period === '24h' ? ts.slice(11, 16) : ts.slice(5);
-}
-
// WhatsApp ids look like '[email protected]' / '[email protected]' / '...@lid' — show just the local part.
function shortChat(chatId: string): string {
return chatId.split('@')[0] || chatId;
@@ -111,7 +107,7 @@ export function DashboardCharts() {
) : (
<div className="charts-grid">
<div className="chart-card chart-wide">
- <h3>{t('dashboard.charts.overTime')}</h3>
+ <h3>{period === '24h' ? t('dashboard.charts.overTime') : t('dashboard.charts.overTimeUtcDays')}</h3>
<ResponsiveContainer width="100%" height={260}>
<AreaChart data={timeSeries} margin={{ top: 8, right: 12, left: -12, bottom: 0 }}>
<defs>
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index c35c0da10..39cc201c4 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -238,6 +238,7 @@
"30d": "30 يومًا"
},
"overTime": "الرسائل عبر الزمن",
+ "overTimeUtcDays": "الرسائل عبر الزمن (الأيام بتوقيت UTC)",
"byType": "الرسائل حسب النوع",
"topChats": "أبرز المحادثات",
"sent": "المُرسَلة",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 0d677dd78..551461ffa 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -227,6 +227,7 @@
"30d": "30 Tage"
},
"overTime": "Nachrichten im Zeitverlauf",
+ "overTimeUtcDays": "Nachrichten im Zeitverlauf (Tage in UTC)",
"byType": "Nachrichten nach Typ",
"topChats": "Top-Chats",
"sent": "Gesendet",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index b75ba4e28..c8dfcd7bb 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -227,6 +227,7 @@
"30d": "30d"
},
"overTime": "Messages over time",
+ "overTimeUtcDays": "Messages over time (days in UTC)",
"byType": "Messages by type",
"topChats": "Top chats",
"sent": "Sent",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index 7b210e006..1040c17eb 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -227,6 +227,7 @@
"30d": "30 d"
},
"overTime": "Mensajes a lo largo del tiempo",
+ "overTimeUtcDays": "Mensajes a lo largo del tiempo (días en UTC)",
"byType": "Mensajes por tipo",
"topChats": "Chats principales",
"sent": "Enviados",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 3b475cf0e..99123ae83 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -227,6 +227,7 @@
"30d": "30 j"
},
"overTime": "Messages au fil du temps",
+ "overTimeUtcDays": "Messages au fil du temps (jours en UTC)",
"byType": "Messages par type",
"topChats": "Discussions principales",
"sent": "Envoyés",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 22a6d503e..3cb743693 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -234,6 +234,7 @@
"30d": "30 יום"
},
"overTime": "הודעות לאורך זמן",
+ "overTimeUtcDays": "הודעות לאורך זמן (ימים לפי UTC)",
"byType": "הודעות לפי סוג",
"topChats": "צ'אטים מובילים",
"sent": "נשלחו",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index e97977ee6..660cb6aeb 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -227,6 +227,7 @@
"30d": "30 g"
},
"overTime": "Messaggi nel tempo",
+ "overTimeUtcDays": "Messaggi nel tempo (giorni in UTC)",
"byType": "Messaggi per tipo",
"topChats": "Chat principali",
"sent": "Inviati",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index 498bfef24..756ecada3 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -227,6 +227,7 @@
"30d": "30일"
},
"overTime": "시간별 메시지 추이",
+ "overTimeUtcDays": "시간별 메시지 추이 (UTC 기준 날짜)",
"byType": "유형별 메시지",
"topChats": "인기 채팅",
"sent": "보냄",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 3613bd49b..16f0b8556 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -227,6 +227,7 @@
"30d": "30 d"
},
"overTime": "Mensagens ao longo do tempo",
+ "overTimeUtcDays": "Mensagens ao longo do tempo (dias em UTC)",
"byType": "Mensagens por tipo",
"topChats": "Principais chats",
"sent": "Enviadas",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index ff4575cb8..c973345e2 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -227,6 +227,7 @@
"30d": "30 రో"
},
"overTime": "కాలక్రమంలో సందేశాలు",
+ "overTimeUtcDays": "కాలక్రమంలో సందేశాలు (UTC ప్రకారం రోజులు)",
"byType": "రకం వారీగా సందేశాలు",
"topChats": "టాప్ చాట్‌లు",
"sent": "పంపినవి",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 572702535..bd4fadccc 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -227,6 +227,7 @@
"30d": "30g"
},
"overTime": "Zamana göre mesajlar",
+ "overTimeUtcDays": "Zamana göre mesajlar (günler UTC'ye göre)",
"byType": "Türe göre mesajlar",
"topChats": "En popüler sohbetler",
"sent": "Gönderilen",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index 77d55c3f6..d0f537c6f 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -227,6 +227,7 @@
"30d": "30天"
},
"overTime": "消息趋势",
+ "overTimeUtcDays": "消息趋势(按 UTC 日期)",
"byType": "按类型分类的消息",
"topChats": "热门聊天",
"sent": "已发送",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index c4de298c6..0d59f1247 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -227,6 +227,7 @@
"30d": "30天"
},
"overTime": "訊息趨勢",
+ "overTimeUtcDays": "訊息趨勢(按 UTC 日期)",
"byType": "按類型分類的訊息",
"topChats": "熱門聊天",
"sent": "已傳送",
diff --git a/dashboard/src/utils/chartTicks.test.ts b/dashboard/src/utils/chartTicks.test.ts
new file mode 100644
index 000000000..ff08e35e3
--- /dev/null
+++ b/dashboard/src/utils/chartTicks.test.ts
@@ -0,0 +1,22 @@
+// Pinned to a zone east of UTC so the hour conversion is visible. Node reads TZ when it next needs
+// the zone, and nothing in this file has touched a Date yet.
+process.env.TZ = 'Asia/Jakarta';
+
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { formatTick } from './chartTicks.ts';
+
+test('an hour bucket is shown in the local zone', () => {
+ assert.equal(formatTick('2026-06-24 02:00:00', '24h'), '09:00');
+ // Past local midnight the hour still lands right; the day is not part of the label.
+ assert.equal(formatTick('2026-06-24 20:00:00', '24h'), '03:00');
+});
+
+test('a day bucket keeps its UTC month and day', () => {
+ assert.equal(formatTick('2026-06-24', '7d'), '06-24');
+ assert.equal(formatTick('2026-06-24', '30d'), '06-24');
+});
+
+test('a bucket that does not parse falls back to its text', () => {
+ assert.equal(formatTick('2026-13-45 14:00:00', '24h'), '14:00');
+});
diff --git a/dashboard/src/utils/chartTicks.ts b/dashboard/src/utils/chartTicks.ts
new file mode 100644
index 000000000..0153a7cd8
--- /dev/null
+++ b/dashboard/src/utils/chartTicks.ts
@@ -0,0 +1,15 @@
+import type { StatsPeriod } from '../services/api';
+
+// The gateway buckets messages on the stored UTC timestamp and returns the bucket as zone-less text:
+// '2026-06-24 14:00:00' for an hour, '2026-06-24' for a day.
+//
+// An hour bucket is shown in the browser's zone ('21:00' in UTC+7). A day bucket keeps its 'MM-DD'
+// text: a UTC day spans two local days, so it cannot be moved on the client, and the chart says the
+// days are UTC instead.
+export function formatTick(ts: string, period: StatsPeriod): string {
+ if (period !== '24h') return ts.slice(5);
+ const at = new Date(`${ts.replace(' ', 'T')}Z`);
+ if (Number.isNaN(at.getTime())) return ts.slice(11, 16);
+ const pad = (n: number) => String(n).padStart(2, '0');
+ return `${pad(at.getHours())}:${pad(at.getMinutes())}`;
+}