fix(HH-590): define realtime timestamp range (#151)
Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user