From 5f973f12c4edeea7321f800ee69127a0521073d4 Mon Sep 17 00:00:00 2001 From: evan-scales Date: Mon, 25 Mar 2024 16:40:36 -0400 Subject: [PATCH 1/2] 333: Fix bug --- FU.SPA/src/components/ChatMessage.jsx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/FU.SPA/src/components/ChatMessage.jsx b/FU.SPA/src/components/ChatMessage.jsx index 0ce38c86..6d5ca1bd 100644 --- a/FU.SPA/src/components/ChatMessage.jsx +++ b/FU.SPA/src/components/ChatMessage.jsx @@ -14,18 +14,19 @@ export default function ChatMessage({ chatMessage, userIsSender }) { )); const timeDifference = (timestamp) => { - const today = dayjs(); - const sentDate = dayjs(timestamp); + const messageDate = new Date(timestamp); + const currentTimestamp = Date.now(); - // find the difference between the dates - const diff = today.diff(sentDate, 'day', true); + const difference = currentTimestamp - messageDate.getTime(); - const days = Math.floor(diff); - const hours = Math.floor((diff - days) * 24); - const minutes = Math.floor(((diff - days) * 24 - hours) * 60); - const seconds = Math.floor( - (((diff - days) * 24 - hours) * 60 - minutes) * 60, - ); + if (difference <= 0) { + return 'Just now'; + } + + const seconds = Math.floor(difference / 1000); + const minutes = Math.floor(seconds / 60); + const hours = Math.floor(minutes / 60); + const days = Math.floor(hours / 24); if (days > 0) { return `${days} day${days > 1 ? 's' : ''} ago`; @@ -33,8 +34,6 @@ export default function ChatMessage({ chatMessage, userIsSender }) { return `${hours} hour${hours > 1 ? 's' : ''} ago`; } else if (minutes > 0) { return `${minutes} minute${minutes > 1 ? 's' : ''} ago`; - } else if (seconds < 0) { - return '0 seconds ago'; } else { return `${seconds} second${seconds !== 1 ? 's' : ''} ago`; } From a9caa4e3c738ca964c4178eb567758ca8b880576 Mon Sep 17 00:00:00 2001 From: evan-scales Date: Tue, 26 Mar 2024 17:45:09 -0400 Subject: [PATCH 2/2] fix spa build --- FU.SPA/src/components/ChatMessage.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/FU.SPA/src/components/ChatMessage.jsx b/FU.SPA/src/components/ChatMessage.jsx index 6d5ca1bd..4a175d9b 100644 --- a/FU.SPA/src/components/ChatMessage.jsx +++ b/FU.SPA/src/components/ChatMessage.jsx @@ -1,6 +1,5 @@ import './ChatMessage.css'; import { Avatar } from '@mui/material'; -import dayjs from 'dayjs'; import { useNavigate } from 'react-router-dom'; export default function ChatMessage({ chatMessage, userIsSender }) {