From 201da849671c8434a60ebf229018767b40538442 Mon Sep 17 00:00:00 2001 From: Borislav Pantaleev Date: Thu, 27 Feb 2025 00:03:01 +0200 Subject: [PATCH] Fix handling of date string that are ISO formatted --- src/utils/date.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/date.ts b/src/utils/date.ts index e000e12..cddad4b 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -28,18 +28,18 @@ export const dateFormatter = (v: string | number | Date | undefined | null): str }; // assuming date is in format "2025-02-26 20:52:00" where no timezone is specified -export const getTimeSince = (date: string) => { +export const getTimeSince = (dateToCompare: string) => { const nowUTC = new Date().getTime(); - const past = new Date(date.replace(" ", "T") + "Z"); + if (!dateToCompare.includes("Z")) { + dateToCompare = dateToCompare + "Z"; + } + const past = new Date(dateToCompare); const pastUTC = past.getTime(); const diffInMs = nowUTC - pastUTC; const diffInMinutes = Math.floor(diffInMs / (1000 * 60)); - // Remove or comment out the console.log for production - console.log("FOR now, date", new Date(nowUTC).toISOString(), new Date(pastUTC).toISOString(), "diffInMinutes", diffInMinutes); - if (diffInMinutes < 1) return "a couple of seconds"; if (diffInMinutes === 1) return "1 minute"; if (diffInMinutes < 60) return `${diffInMinutes} minutes`;