From b5a6eeef4243e842bbdadcd55e71199b913850a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= <gaston@getunleash.io>
Date: Mon, 2 Sep 2024 17:31:10 +0200
Subject: [PATCH] Revert "Add try catch to toLocaleString"

This reverts commit 1208a9ac0274c8f52193fc66357cf9e8169da7bf.
---
 frontend/src/hooks/useTrafficData.ts |  2 +-
 frontend/src/utils/formatDate.ts     | 84 +++++++++-------------------
 2 files changed, 27 insertions(+), 59 deletions(-)

diff --git a/frontend/src/hooks/useTrafficData.ts b/frontend/src/hooks/useTrafficData.ts
index bbd7b74ef6..00c6e184d9 100644
--- a/frontend/src/hooks/useTrafficData.ts
+++ b/frontend/src/hooks/useTrafficData.ts
@@ -62,7 +62,7 @@ export const toSelectablePeriod = (
         dayCount,
         label:
             label ||
-            date.toLocaleString('en-US', { month: 'long', year: 'numeric' }),
+            "date.toLocaleString('en-US', { month: 'long', year: 'numeric' })",
     };
 };
 
diff --git a/frontend/src/utils/formatDate.ts b/frontend/src/utils/formatDate.ts
index a8c073007c..86729a5d12 100644
--- a/frontend/src/utils/formatDate.ts
+++ b/frontend/src/utils/formatDate.ts
@@ -2,22 +2,14 @@ export const formatDateYMDHMS = (
     date: number | string | Date,
     locale?: string,
 ): string => {
-    try {
-        return new Date(date).toLocaleString(locale, {
-            day: '2-digit',
-            month: '2-digit',
-            year: 'numeric',
-            hour: '2-digit',
-            minute: '2-digit',
-            second: '2-digit',
-        });
-    } catch (e) {
-        console.error(
-            `Invalid toLocaleString locale: ${locale}, date: ${date}`,
-            e,
-        );
-        return '';
-    }
+    return new Date(date).toLocaleString(locale, {
+        day: '2-digit',
+        month: '2-digit',
+        year: 'numeric',
+        hour: '2-digit',
+        minute: '2-digit',
+        second: '2-digit',
+    });
 };
 
 export const formatDateYMDHM = (
@@ -25,22 +17,14 @@ export const formatDateYMDHM = (
     locale: string,
     timeZone?: string,
 ): string => {
-    try {
-        return new Date(date).toLocaleString(locale, {
-            day: '2-digit',
-            month: '2-digit',
-            year: 'numeric',
-            hour: '2-digit',
-            minute: '2-digit',
-            timeZone,
-        });
-    } catch (e) {
-        console.error(
-            `Invalid toLocaleString locale: ${locale}, date: ${date}`,
-            e,
-        );
-        return '';
-    }
+    return new Date(date).toLocaleString(locale, {
+        day: '2-digit',
+        month: '2-digit',
+        year: 'numeric',
+        hour: '2-digit',
+        minute: '2-digit',
+        timeZone,
+    });
 };
 
 export const formatDateYMD = (
@@ -48,36 +32,20 @@ export const formatDateYMD = (
     locale: string,
     timeZone?: string,
 ): string => {
-    try {
-        return new Date(date).toLocaleString(locale, {
-            day: '2-digit',
-            month: '2-digit',
-            year: 'numeric',
-            timeZone,
-        });
-    } catch (e) {
-        console.error(
-            `Invalid toLocaleString locale: ${locale}, date: ${date}`,
-            e,
-        );
-        return '';
-    }
+    return new Date(date).toLocaleString(locale, {
+        day: '2-digit',
+        month: '2-digit',
+        year: 'numeric',
+        timeZone,
+    });
 };
 
 export const formatDateHM = (
     date: number | string | Date,
     locale: string,
 ): string => {
-    try {
-        return new Date(date).toLocaleString(locale, {
-            hour: '2-digit',
-            minute: '2-digit',
-        });
-    } catch (e) {
-        console.error(
-            `Invalid toLocaleString locale: ${locale}, date: ${date}`,
-            e,
-        );
-        return '';
-    }
+    return new Date(date).toLocaleString(locale, {
+        hour: '2-digit',
+        minute: '2-digit',
+    });
 };