123123213weqw opened a new pull request, #5723:
URL: https://github.com/apache/rocketmq-dashboard/pull/5723

   ## Problem / Evidence
   
   The alerts page header stat "Triggered in 24h on page" (本页 24h 触发) parses 
`lastTriggered` with a bare `new Date(...)` (`web/src/pages/ops/alerts.tsx`):
   
   ```ts
   const triggered24h = rules.filter(
     (r) => r.lastTriggered && new Date(r.lastTriggered).getTime() > dayAgo,
   ).length;
   ```
   
   `lastTriggered` is a UTC `LocalDateTime` serialized **without an offset 
suffix`, which the Last-Triggered column on the very same page already 
documents and handles via `formatUtcDateTime` ("The backend stamps 
lastTriggered with ZoneOffset.UTC without an offset suffix"). The two consumers 
of the same field therefore disagree:
   
   - a browser in UTC+8 parses a firing that is 23h old UTC as 31h old → the 
stat **undercounts**;
   - a browser in UTC−8 parses a 31h-old firing as 23h old → the stat 
**overcounts**;
   - only a browser set exactly to UTC shows the right number.
   
   ## Root cause / Fix
   
   The stat predates the UTC-parsing convention the column follows and never 
adopted it.
   
   - `web/src/utils/format.ts`: extract the convention into an exported 
`parseAlertTimestamp()` — an offset-less string is UTC (append `Z`), an 
explicit offset is honored, unusable input yields `NaN`; `formatUtcDateTime` 
now routes through it so the parse rule exists in exactly one place.
   - `web/src/pages/ops/alerts.tsx`: the stat filters on 
`parseAlertTimestamp(r.lastTriggered) > dayAgo`.
   
   ## Tests
   
   - `web/src/utils/format.test.ts`: unit tests for `parseAlertTimestamp` 
(offset-less ⇒ UTC, explicit `Z`/`±hh:mm` honored, `Date` passthrough, 
blank/invalid ⇒ NaN).
   - `web/src/pages/ops/__tests__/AlertsPage.test.tsx`: page-level regression 
that stubs `TZ=Asia/Shanghai` and pins `Date.now` at `2026-08-24T12:00:00Z`, 
feeds one rule with `lastTriggered = '2026-08-23T13:00:00'` (23h old in UTC; 
31h old under the browser-zone parse) and asserts the stat renders **1**. 
Verified the test fails on the pre-fix code (rendered 0).
   - Full suite: `npx vitest run` → 147 files / 1390 tests passed; `npx tsc 
--noEmit -p tsconfig.app.json` clean; eslint on touched files reports no new 
findings.
   
   ## Risk
   
   Low: `formatUtcDateTime` behavior is unchanged (existing tests pass); the 
only behavior change is that the stat now uses the same UTC convention as the 
column beside it.


-- 
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]

Reply via email to