mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 16:15:39 +00:00
fix: keep the inbox rendering when a message has an unparsable date #1099
This commit is contained in:
@@ -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('');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user