Copilot commented on code in PR #4829:
URL:
https://github.com/apache/rocketmq-dashboard/pull/4829#discussion_r4067779164
##########
web/src/utils/format.ts:
##########
@@ -32,6 +32,22 @@ export function formatDateTime(date: string | Date | null |
undefined): string {
);
}
+/**
+ * Format an epoch-millisecond value or a timestamp string as 'YYYY-MM-DD
HH:mm:ss.SSS'.
+ *
+ * Message store times and trace node timestamps arrive either as epoch
milliseconds (Apache
+ * brokers) or as formatted strings (cloud providers), so both are accepted.
Zero is a real
+ * timestamp rather than a missing one, and only an unusable value yields the
placeholder - a
+ * malformed timestamp has to read as absent instead of rendering as
NaN-NaN-NaN.
+ */
+export function formatTimeMs(value: number | string | null | undefined):
string {
+ if (value === null || value === undefined || value === '') return '-';
+ const timestamp = typeof value === 'string' ? Date.parse(value) : value;
+ if (!Number.isFinite(timestamp)) return '-';
+ const date = new Date(timestamp);
+ return `${formatDateTime(date)}.${pad(date.getMilliseconds(), 3)}`;
Review Comment:
`Number.isFinite(timestamp)` does not guarantee that `new Date(timestamp)`
is valid: finite values outside JavaScript's date range (for example
`Number.MAX_VALUE`) produce an invalid `Date`. In that case
`formatDateTime(date)` returns `-`, but the appended milliseconds turn the
result into `-.NaN` instead of the promised placeholder. Check `date.getTime()`
before formatting (and add a regression case for an out-of-range finite number).
--
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]