Add timestamp utilities with helpful names

This commit is contained in:
Fedor Indutny 2021-03-22 14:08:52 -07:00 committed by GitHub
parent 9fa3359477
commit a75402d290
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 17 deletions

View file

@ -1,6 +1,8 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { isMoreRecentThan } from './timestamp';
const SIX_HOURS = 1000 * 60 * 60 * 6;
export function isConversationUnregistered({
@ -8,6 +10,6 @@ export function isConversationUnregistered({
}: Readonly<{ discoveredUnregisteredAt?: number }>): boolean {
return Boolean(
discoveredUnregisteredAt &&
discoveredUnregisteredAt > Date.now() - SIX_HOURS
isMoreRecentThan(discoveredUnregisteredAt, SIX_HOURS)
);
}

View file

@ -14026,7 +14026,7 @@
"rule": "jQuery-load(",
"path": "ts/LibSignalStore.js",
"line": " await window.ConversationController.load();",
"lineNumber": 810,
"lineNumber": 811,
"reasonCategory": "falseMatch",
"updated": "2021-02-27T00:48:49.313Z"
},
@ -14034,7 +14034,7 @@
"rule": "jQuery-load(",
"path": "ts/LibSignalStore.ts",
"line": " await window.ConversationController.load();",
"lineNumber": 1221,
"lineNumber": 1222,
"reasonCategory": "falseMatch",
"updated": "2021-02-27T00:48:49.313Z"
},

10
ts/util/timestamp.ts Normal file
View file

@ -0,0 +1,10 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function isMoreRecentThan(timestamp: number, delta: number): boolean {
return timestamp > Date.now() - delta;
}
export function isOlderThan(timestamp: number, delta: number): boolean {
return timestamp <= Date.now() - delta;
}