fix: keep the inbox rendering when a message has an unparsable date #1099

This commit is contained in:
Linus Rath
2026-09-24 17:47:33 +02:00
parent e752355311
commit 4d11cbf60b
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -172,4 +172,12 @@ describe('mail timestamp formatting honours the override', () => {
expect(formatDate(received)).toContain('23:00');
expect(formatDateTime(received, '24h', { year: 'numeric', month: 'short', day: 'numeric' })).toContain('23:00');
});
it.each(['smart', 'relative', 'full'] as const)('formatDate returns "" for an invalid date in %s mode (#1099)', (dateFormat) => {
useSettingsStore.setState({ timeZone: 'Asia/Tokyo', dateFormat });
expect(formatDate('not-a-valid-date')).toBe('');
expect(formatDate('10000-01-01T00:00:00Z')).toBe('');
expect(formatDate(new Date('nope'))).toBe('');
expect(formatDate(undefined as unknown as string)).toBe('');
});
});
+4
View File
@@ -96,6 +96,10 @@ function resolveDateLocale<T extends string | undefined>(
*/
export function formatDate(date: Date | string): string {
const d = typeof date === "string" ? new Date(date) : date;
// An unparsable receivedAt (e.g. a 5-digit year) makes Intl throw
// "RangeError: Invalid time value" and takes the whole list down with it.
// Leave the row's date slot blank; the viewer header shows the raw value. (#1099)
if (!d || Number.isNaN(d.getTime())) return "";
const now = new Date();
const locale = getEffectiveLocale();