This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 27d55b02f fix(metrics): render metric instants through the shared 
formatter instead of the locale string (#6739)
27d55b02f is described below

commit 27d55b02fe26b7a1bedc29842e82cc4e6d971857
Author: bai mengxuan <[email protected]>
AuthorDate: Fri Nov 27 12:26:31 2026 +0800

    fix(metrics): render metric instants through the shared formatter instead 
of the locale string (#6739)
---
 web/src/components/MetricsExplorer.tsx             | 12 ++++++++----
 .../components/__tests__/MetricsExplorer.test.tsx  | 22 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/web/src/components/MetricsExplorer.tsx 
b/web/src/components/MetricsExplorer.tsx
index ac7d0e8dd..a1eec175c 100644
--- a/web/src/components/MetricsExplorer.tsx
+++ b/web/src/components/MetricsExplorer.tsx
@@ -55,6 +55,7 @@ import type { MetricData, MetricMapping, MetricProfile } from 
'../api/metrics';
 import { useLang } from '../i18n/LangContext';
 import useAuthStore from '../stores/authStore';
 import { downloadCsv } from '../utils/download';
+import { formatUtcDateTime } from '../utils/format';
 import { tableScrollX } from '../utils/table';
 import { readLocalStorage, removeLocalStorage, writeLocalStorage } from 
'../utils/browserStorage';
 import {
@@ -1030,15 +1031,18 @@ const MetricsExplorer = ({ instanceId }: 
MetricsExplorerProps) => {
     [customPanel?.data],
   );
 
+  // Sample, window and history instants go through the shared formatter: a 
stable
+  // `YYYY-MM-DD HH:mm:ss` in the viewer's zone, the way the rest of the 
console renders an instant.
+  // `formatSeconds` still takes epoch seconds and `formatMillis` epoch 
milliseconds.
   const formatSeconds = useCallback(
     (timestamp?: number) =>
-      timestamp === undefined ? '-' : new Date(timestamp * 
1000).toLocaleString(locale),
-    [locale],
+      timestamp === undefined ? '-' : formatUtcDateTime(new Date(timestamp * 
1000)),
+    [],
   );
   const formatMillis = useCallback(
     (timestamp?: number) =>
-      timestamp === undefined ? '-' : new 
Date(timestamp).toLocaleString(locale),
-    [locale],
+      timestamp === undefined ? '-' : formatUtcDateTime(new Date(timestamp)),
+    [],
   );
   const formatHistorySource = (entry: MetricsQueryHistoryEntry) =>
     entry.dataSourceKey ? entry.dataSourceName || entry.dataSourceKey : 
copy.defaultDataSource;
diff --git a/web/src/components/__tests__/MetricsExplorer.test.tsx 
b/web/src/components/__tests__/MetricsExplorer.test.tsx
index 00846ec21..4c88868dd 100644
--- a/web/src/components/__tests__/MetricsExplorer.test.tsx
+++ b/web/src/components/__tests__/MetricsExplorer.test.tsx
@@ -516,6 +516,28 @@ describe('MetricsExplorer', () => {
     expect(await screen.findAllByText('cluster=prod / 
node_id=broker-a')).not.toHaveLength(0);
   });
 
+  it('renders metric instants through the shared formatter instead of the 
locale string', async () => {
+    const user = userEvent.setup();
+    renderWithProviders(<MetricsExplorer />);
+    await screen.findByRole('img', { name: 'Message In TPS time series' });
+
+    await user.type(screen.getByLabelText('自定义查询'), 
'sum(rocketmq_topic_number)');
+    await user.click(screen.getByRole('button', { name: '查询' }));
+    await screen.findAllByText('cluster=prod / node_id=broker-a');
+
+    // The panel condenses its metadata into an info popover: query window, 
query time and the
+    // first/last sample instants. They must read as the stable `YYYY-MM-DD 
HH:mm:ss` every other
+    // timestamp surface prints, not Date.toLocaleString's locale-dependent 
string
+    // (`2027/1/15 07:00:00` in zh, `1/15/2027, 7:00:00 AM` in en) - the 
format is the assertion, so
+    // it holds in any viewer time zone.
+    await user.hover(screen.getByRole('button', { name: '自定义查询 查询窗口' }));
+
+    const instants = await screen.findAllByText(/^\d{4}-\d{2}-\d{2} 
\d{2}:\d{2}:\d{2}$/);
+    expect(instants.length).toBeGreaterThan(0);
+    
expect(screen.queryByText(/\d{4}\/\d{1,2}\/\d{1,2}/)).not.toBeInTheDocument();
+    
expect(screen.queryByText(/\d{1,2}\/\d{1,2}\/\d{4}/)).not.toBeInTheDocument();
+  });
+
   it('re-runs the committed custom query when the dashboard instance changes', 
async () => {
     const user = userEvent.setup();
     const view = renderWithProviders(<MetricsExplorer instanceId="instance-11" 
/>);

Reply via email to