Fix UI for invalid timestamps
This commit is contained in:
parent
187d06fd69
commit
1c933af6ce
4 changed files with 18 additions and 4 deletions
|
@ -30,7 +30,11 @@ import {
|
||||||
isSameCallHistoryGroup,
|
isSameCallHistoryGroup,
|
||||||
CallMode,
|
CallMode,
|
||||||
} from '../types/CallDisposition';
|
} from '../types/CallDisposition';
|
||||||
import { formatDateTimeShort, isMoreRecentThan } from '../util/timestamp';
|
import {
|
||||||
|
formatDateTimeShort,
|
||||||
|
isMoreRecentThan,
|
||||||
|
toBoundedDate,
|
||||||
|
} from '../util/timestamp';
|
||||||
import type { ConversationType } from '../state/ducks/conversations';
|
import type { ConversationType } from '../state/ducks/conversations';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
import { refMerger } from '../util/refMerger';
|
import { refMerger } from '../util/refMerger';
|
||||||
|
@ -89,7 +93,7 @@ function Timestamp({
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const dateTime = useMemo(() => {
|
const dateTime = useMemo(() => {
|
||||||
return new Date(timestamp).toISOString();
|
return toBoundedDate(timestamp).toISOString();
|
||||||
}, [timestamp]);
|
}, [timestamp]);
|
||||||
|
|
||||||
const formatted = useMemo(() => {
|
const formatted = useMemo(() => {
|
||||||
|
|
|
@ -6,6 +6,8 @@ import type { ReactElement, TimeHTMLAttributes } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
import { toBoundedDate } from '../util/timestamp';
|
||||||
|
|
||||||
export function Time({
|
export function Time({
|
||||||
children,
|
children,
|
||||||
dateOnly = false,
|
dateOnly = false,
|
||||||
|
@ -22,7 +24,7 @@ export function Time({
|
||||||
dateTime = moment(timestamp).format('YYYY-MM-DD');
|
dateTime = moment(timestamp).format('YYYY-MM-DD');
|
||||||
} else {
|
} else {
|
||||||
const date =
|
const date =
|
||||||
typeof timestamp === 'number' ? new Date(timestamp) : timestamp;
|
typeof timestamp === 'number' ? toBoundedDate(timestamp) : timestamp;
|
||||||
dateTime = date.toISOString();
|
dateTime = date.toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
|
||||||
import { getMessageQueueTime } from '../util/getMessageQueueTime';
|
import { getMessageQueueTime } from '../util/getMessageQueueTime';
|
||||||
import * as Errors from '../types/errors';
|
import * as Errors from '../types/errors';
|
||||||
import { strictAssert } from '../util/assert';
|
import { strictAssert } from '../util/assert';
|
||||||
|
import { toBoundedDate } from '../util/timestamp';
|
||||||
|
|
||||||
async function eraseTapToViewMessages() {
|
async function eraseTapToViewMessages() {
|
||||||
try {
|
try {
|
||||||
|
@ -73,7 +74,7 @@ class TapToViewMessagesDeletionService {
|
||||||
receivedAtMsForOldestTapToViewMessage + getMessageQueueTime();
|
receivedAtMsForOldestTapToViewMessage + getMessageQueueTime();
|
||||||
window.SignalContext.log.info(
|
window.SignalContext.log.info(
|
||||||
'checkTapToViewMessages: next check at',
|
'checkTapToViewMessages: next check at',
|
||||||
new Date(nextCheck).toISOString()
|
toBoundedDate(nextCheck).toISOString()
|
||||||
);
|
);
|
||||||
|
|
||||||
let wait = nextCheck - Date.now();
|
let wait = nextCheck - Date.now();
|
||||||
|
|
|
@ -206,3 +206,10 @@ export function formatDate(
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_SAFE_DATE = 8640000000000000;
|
||||||
|
const MIN_SAFE_DATE = -8640000000000000;
|
||||||
|
|
||||||
|
export function toBoundedDate(timestamp: number): Date {
|
||||||
|
return new Date(Math.max(MIN_SAFE_DATE, Math.min(timestamp, MAX_SAFE_DATE)));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue