From 28a1210dc4a0c17c85c7a67fba010aa7039d3251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Mon, 2 Sep 2024 17:30:34 +0200 Subject: [PATCH] Revert "Add try catches everywhere and defaults for locales" This reverts commit f62dbe6917d5a2d981a522c1f55e46fbede5487c. --- frontend/src/hooks/useTrafficData.ts | 16 +++------------- frontend/src/utils/formatDate.ts | 8 ++++---- 2 files changed, 7 insertions(+), 17 deletions(-) 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', });