btlqql opened a new pull request, #5332:
URL: https://github.com/apache/rocketmq-dashboard/pull/5332
### Which Issue(s) This PR Fixes
- Fixes #5225
### Brief Description
`web/src/pages/studio/LiteTopic.tsx:72-76` — `formatTime` rendered the
LiteTopic API's `createTime` / `lastActiveTime` (epoch millis, i.e. absolute
instants) with `new Date(ts).toLocaleString()`:
```ts
export const formatTime = (timestamp: number | undefined | null): string => {
if (timestamp == null || !Number.isFinite(timestamp)) return '-';
const date = new Date(timestamp);
return Number.isNaN(date.getTime()) ? '-' : date.toLocaleString();
};
```
The result is locale dependent (`2026/9/30 10:05:04` here, `9/30/2026,
10:05:04 AM` on en-US), silently converted to the browser zone and unlabeled,
so the same row reads as two different times to two operators with nothing
saying which zone either value is in. It feeds the table's last-active column,
the export column and the session drawer's create/last-active items.
`formatTime` now routes the instant through the shared `formatUtcDateTime`
util (the contract the alert surfaces already use): viewer-zone wall clock,
explicit zone suffix, `-` for unusable values.
### How Did You Test This Change?
The existing `LiteTopic.test.tsx` suite pinned the old behaviour
(`expect(formatTime(0)).toBe(new Date(0).toLocaleString())`), so that assertion
is updated to the new contract and a page-level assertion was added for the
table column. The expected value is computed independently (dayjs wall clock in
the runner's zone + the `Intl` short zone name), so the test runs in any
timezone.
```powershell
$ cd web && npx vitest run src/pages/studio/__tests__/LiteTopic.test.tsx
❯ src/pages/studio/__tests__/LiteTopic.test.tsx (15 tests | 2 failed)
22335ms
× renders instants in the labeled viewer zone and rejects invalid
provider values 76ms
× renders the last-active instant in the labeled viewer zone 5249ms
FAIL ... > renders instants in the labeled viewer zone and rejects invalid
provider values
AssertionError: expected '2026/9/30 10:05:04' to be '2026-09-30 10:05:04
GMT+8' // Object.is equality
Expected: "2026-09-30 10:05:04 GMT+8"
Received: "2026/9/30 10:05:04"
FAIL ... > LiteTopic Page > renders the last-active instant in the labeled
viewer zone
TestingLibraryElementError: Unable to find an element with the text:
2030-01-01 08:00:00 GMT+8.
Test Files 1 failed (1)
Tests 2 failed | 13 passed (15) <- before the fix
```
```powershell
$ cd web && npx vitest run src/pages/studio/__tests__/LiteTopic.test.tsx
✓ src/pages/studio/__tests__/LiteTopic.test.tsx (15 tests) 14586ms
Test Files 1 passed (1)
Tests 15 passed (15) <- after the fix
```
`npx tsc -b` passes and `npx eslint` reports 0 errors (the single
`react-refresh/only-export-components` warning on the exported `formatTime`
exists on the base commit as well).
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits
- [x] Tests added or updated for non-trivial changes
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
— not applicable: no new UI text, the value is a formatted timestamp
- [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks) — not applicable: frontend-only change, no Java touched
- [ ] New source files carry the ASF license header — not applicable: no new
source file
- [ ] Documentation touched where behaviour changed — not applicable: the
shared `formatUtcDateTime` contract is already documented in
`web/src/utils/format.ts`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]