Add timestamp utilities with helpful names
This commit is contained in:
parent
9fa3359477
commit
a75402d290
8 changed files with 71 additions and 17 deletions
37
ts/test-both/util/timestamp_test.ts
Normal file
37
ts/test-both/util/timestamp_test.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { isOlderThan, isMoreRecentThan } from '../../util/timestamp';
|
||||
|
||||
const ONE_HOUR = 3600 * 1000;
|
||||
const ONE_DAY = 24 * ONE_HOUR;
|
||||
|
||||
describe('timestamp', () => {
|
||||
describe('isOlderThan', () => {
|
||||
it('returns false on recent and future timestamps', () => {
|
||||
assert.isFalse(isOlderThan(Date.now(), ONE_DAY));
|
||||
assert.isFalse(isOlderThan(Date.now() + ONE_DAY, ONE_DAY));
|
||||
});
|
||||
|
||||
it('returns true on old enough timestamps', () => {
|
||||
assert.isFalse(isOlderThan(Date.now() - ONE_DAY + ONE_HOUR, ONE_DAY));
|
||||
assert.isTrue(isOlderThan(Date.now() - ONE_DAY - ONE_HOUR, ONE_DAY));
|
||||
});
|
||||
});
|
||||
|
||||
describe('isMoreRecentThan', () => {
|
||||
it('returns true on recent and future timestamps', () => {
|
||||
assert.isTrue(isMoreRecentThan(Date.now(), ONE_DAY));
|
||||
assert.isTrue(isMoreRecentThan(Date.now() + ONE_DAY, ONE_DAY));
|
||||
});
|
||||
|
||||
it('returns false on old enough timestamps', () => {
|
||||
assert.isTrue(isMoreRecentThan(Date.now() - ONE_DAY + ONE_HOUR, ONE_DAY));
|
||||
assert.isFalse(
|
||||
isMoreRecentThan(Date.now() - ONE_DAY - ONE_HOUR, ONE_DAY)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue