diff --git a/frontend/src/hooks/useTrafficData.ts b/frontend/src/hooks/useTrafficData.ts index f96c8cba01..bbd7b74ef6 100644 --- a/frontend/src/hooks/useTrafficData.ts +++ b/frontend/src/hooks/useTrafficData.ts @@ -47,18 +47,6 @@ const calculateTrafficDataCost = (trafficData: number) => { const padMonth = (month: number): string => month < 10 ? `0${month}` : `${month}`; -const safeLocaleString = (date: Date): string => { - try { - return date.toLocaleString('en-US', { - day: '2-digit', - month: '2-digit', - year: 'numeric', - }); - } catch (e) { - console.error(`Invalid toLocaleString locale: en-US, date: ${date}`, e); - return ''; - } -}; export const toSelectablePeriod = ( date: Date, label?: string, @@ -72,7 +60,9 @@ export const toSelectablePeriod = ( year, month, dayCount, - label: label || safeLocaleString(date), + label: + label || + date.toLocaleString('en-US', { month: 'long', year: 'numeric' }), }; }; diff --git a/frontend/src/utils/formatDate.ts b/frontend/src/utils/formatDate.ts index 65ac97cd8e..a8c073007c 100644 --- a/frontend/src/utils/formatDate.ts +++ b/frontend/src/utils/formatDate.ts @@ -3,7 +3,7 @@ export const formatDateYMDHMS = ( locale?: string, ): string => { try { - return new Date(date).toLocaleString(locale ?? 'en-US', { + return new Date(date).toLocaleString(locale, { day: '2-digit', month: '2-digit', year: 'numeric', @@ -26,7 +26,7 @@ export const formatDateYMDHM = ( timeZone?: string, ): string => { try { - return new Date(date).toLocaleString(locale ?? 'en-US', { + return new Date(date).toLocaleString(locale, { day: '2-digit', month: '2-digit', year: 'numeric', @@ -49,7 +49,7 @@ export const formatDateYMD = ( timeZone?: string, ): string => { try { - return new Date(date).toLocaleString(locale ?? 'en-US', { + return new Date(date).toLocaleString(locale, { day: '2-digit', month: '2-digit', year: 'numeric', @@ -69,7 +69,7 @@ export const formatDateHM = ( locale: string, ): string => { try { - return new Date(date).toLocaleString(locale ?? 'en-US', { + return new Date(date).toLocaleString(locale, { hour: '2-digit', minute: '2-digit', });