fix(HH-590): define realtime timestamp range (#151)

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-24 10:44:23 +08:00
committed by GitHub
co-authored by rogee
parent 34c45ff2c4
commit c4ac664deb
2 changed files with 30 additions and 1 deletions
@@ -6,11 +6,20 @@ import {
differenceInDays,
} from 'date-fns';
// Numeric realtime timestamps below 1e10 are Unix seconds (through 2286-11-20);
// larger values are milliseconds, bounded by the ECMAScript Date range.
const UNIX_SECONDS_LIMIT = 1e10;
const DATE_MILLISECONDS_LIMIT = 8.64e15;
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;
const timestamp =
Math.abs(numericValue) < UNIX_SECONDS_LIMIT
? numericValue * 1000
: numericValue;
return Math.abs(timestamp) <= DATE_MILLISECONDS_LIMIT ? timestamp : null;
}
if (typeof value !== 'string') return null;