From e0722545551ee44e98a7db8eb47086d3d71445e1 Mon Sep 17 00:00:00 2001 From: Lucas Bordeau Date: Thu, 13 Jun 2024 14:18:10 +0200 Subject: [PATCH] Fixed new date time formatting util (#5852) The new date time formatting util made for performance optimization missed two things : - Padding 0 for hours and minutes with 1 digit only. - Correctly parsing the day of the month (now uses JS Date native getDate() instead of slicing the ISO String) --- packages/twenty-front/src/utils/date-utils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/twenty-front/src/utils/date-utils.ts b/packages/twenty-front/src/utils/date-utils.ts index ede9c37b6..12542127c 100644 --- a/packages/twenty-front/src/utils/date-utils.ts +++ b/packages/twenty-front/src/utils/date-utils.ts @@ -162,13 +162,18 @@ export const formatISOStringToHumanReadableDateTime = (date: string) => { const year = date.slice(0, 4); const month = date.slice(5, 7); - const day = date.slice(8, 10); const monthLabel = monthLabels[parseInt(month, 10) - 1]; const jsDate = new Date(date); - return `${day} ${monthLabel} ${year} - ${jsDate.getHours()}:${jsDate.getMinutes()}`; + const day = jsDate.getDate(); + + const hours = `0${jsDate.getHours()}`.slice(-2); + + const minutes = `0${jsDate.getMinutes()}`.slice(-2); + + return `${day} ${monthLabel} ${year} - ${hours}:${minutes}`; }; export const formatISOStringToHumanReadableDate = (date: string) => {