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,6 +6,7 @@ import {
shortTimestamp,
getDayDifferenceFromNow,
hasOneDayPassed,
isNewerTimestamp,
} from 'shared/helpers/timeHelper';
import { zhCN } from 'date-fns/locale';
@@ -20,6 +21,25 @@ afterEach(() => {
vi.useRealTimers();
});
describe('#isNewerTimestamp', () => {
it.each([
['Unix seconds', 1_700_000_000, 1_700_000_001],
['numeric strings', '1700000000', '1700000001'],
['early Unix milliseconds', 978_307_200_000, 1_700_000_000],
['below the former 1e12 threshold', 999_999_999_999, 1_000_000_000_000],
])('orders %s', (_label, current, next) => {
expect(isNewerTimestamp(current, next)).toBe(true);
});
it('preserves missing and invalid timestamp compatibility', () => {
expect(isNewerTimestamp(null, 'invalid')).toBe(true);
expect(isNewerTimestamp(1_700_000_000, null)).toBe(true);
expect(isNewerTimestamp('invalid', 1_700_000_000)).toBe(true);
expect(isNewerTimestamp(1_700_000_000, 'invalid')).toBe(false);
expect(isNewerTimestamp(1_700_000_000, 9e15)).toBe(false);
});
});
describe('#messageStamp', () => {
it('returns correct value', () => {
expect(messageStamp(1612971343)).toEqual('3:35 PM');