zjncs opened a new pull request, #4576:
URL: https://github.com/apache/rocketmq-dashboard/pull/4576
### Which Issue(s) Are Addressed
No issue yet; found while auditing the per-user session details added in
#4231.
### Brief Description
The user management page formatted every session and account timestamp with
`new Date(value).toLocaleString()`, but the studio user and session APIs
serialize UTC `LocalDateTime` values **without an offset":
* `AuthService.now()` builds all session/account times at `ZoneOffset.UTC`
(last-seen, expires, password-changed, session aggregates
`MAX(last_seen_at)`/`MIN(expires_at)`);
* the default JDBC URL pins `serverTimezone=UTC`, so DB-default
`gmt_create`/`gmt_modified` are UTC wall times too.
Per the ECMAScript spec, an offset-less ISO string parses as
**browser-local** time, so for any non-UTC admin every 最近活跃/过期时间/创建时间 value in
the sessions drawer, the user table columns and the CSV export was shifted by
the viewer's UTC offset — a session expiring at 10:00 UTC displayed as 10:00
local instead of 18:00 in Asia/Shanghai.
The codebase already centralizes this pitfall in `formatUtcDateTime`
(introduced for the alert subsystem; reused by the message query history fix
#4222). This page was the remaining caller of raw `toLocaleString` on these
values; the fix delegates the `dateTime` helper to `formatUtcDateTime`, which
appends `Z` to offset-less values before rendering in the viewer's zone.
The existing drawer test asserted the rendered text with the identical
misparse (`new Date(...).toLocaleString()`), so it passed in every timezone and
could not catch the bug. It now asserts the helper's output, plus a new test
pins the viewer zone via `vi.stubEnv('TZ', 'Asia/Shanghai')` so the expectation
(17:30 for a 09:30 UTC value) discriminates on any runner.
### How Did You Test This?
Fail-before / pass-after (verified also from a `TZ=America/New_York` base
zone, so the check does not depend on the runner's zone):
```
NODE_OPTIONS=--no-experimental-webstorage npx vitest run
src/pages/studio/__tests__/UserManagement.test.tsx
# before fix: renders session timestamps as UTC values… FAILS (renders
09:30 local)
# after fix: passes
```
Full web suite, lint and typecheck after the fix:
```
NODE_OPTIONS=--no-experimental-webstorage npm test # Test Files 122
passed, Tests 1035 passed
npm run lint # 0 errors (10
pre-existing warnings elsewhere)
tsc -b # clean
```
Note: `exports all users that match the active filters` in the same file is
flaky when that file is run in isolation on a loaded machine (times out in
`waitFor`); it fails identically on pristine master in isolation and passes in
the full suite, so it is unrelated to this change.
### Checklist
- [x] Code follows the project's coding style (Conventional Commits, lint
passes)
- [x] Added/updated tests covering the fix
- [x] All tests pass locally
Signed-off-by: zjncs <[email protected]>
--
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]