Fix RangeError invalid timestamp

This commit is contained in:
Josh Perez 2023-05-25 13:17:10 -04:00 committed by GitHub
parent 35c3349fe6
commit e2f39ed5fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 29 deletions

View file

@ -0,0 +1,17 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assertDev } from './assert';
export function formatTimestamp(
timestamp: number,
options: Intl.DateTimeFormatOptions
): string {
const locale = window.getPreferredSystemLocales();
try {
return new Intl.DateTimeFormat(locale, options).format(timestamp);
} catch (err) {
assertDev(false, 'invalid timestamp');
return '';
}
}