fix(HH-576): normalize realtime message timestamps (#148)

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-24 10:16:22 +08:00
committed by GitHub
co-authored by rogee
parent 83e2a8ead6
commit b981cc6811
5 changed files with 202 additions and 7 deletions
@@ -6,6 +6,28 @@ import {
differenceInDays,
} from 'date-fns';
const normalizeTimestamp = value => {
const numericValue =
typeof value === 'string' && value.trim() ? Number(value) : value;
if (typeof numericValue === 'number' && Number.isFinite(numericValue)) {
return Math.abs(numericValue) < 1e12 ? numericValue * 1000 : numericValue;
}
if (typeof value !== 'string') return null;
const timestamp = Date.parse(value);
return Number.isNaN(timestamp) ? null : timestamp;
};
export const isNewerTimestamp = (currentTimestamp, nextTimestamp) => {
if (currentTimestamp == null || nextTimestamp == null) return true;
const next = normalizeTimestamp(nextTimestamp);
if (next === null) return false;
const current = normalizeTimestamp(currentTimestamp);
return current === null || next > current;
};
/**
* Formats a Unix timestamp into a human-readable time format.
* @param {number} time - Unix timestamp.