From a5511e3c22f357afac8ecd57fb12cc08e918df98 Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Fri, 3 May 2024 15:55:24 +0100
Subject: update date logic to account for timezones (#3840)

---
 src/components/dms/MessageItem.tsx | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

(limited to 'src/components/dms/MessageItem.tsx')

diff --git a/src/components/dms/MessageItem.tsx b/src/components/dms/MessageItem.tsx
index 3a1d8eab7..a449c6ed1 100644
--- a/src/components/dms/MessageItem.tsx
+++ b/src/components/dms/MessageItem.tsx
@@ -118,16 +118,15 @@ export function MessageItemMetadata({
       }
 
       // if in the last day
-      if (now.toISOString().slice(0, 10) === date.toISOString().slice(0, 10)) {
+      if (localDateString(now) === localDateString(date)) {
         return time
       }
 
       // if yesterday
       const yesterday = new Date(now)
       yesterday.setDate(yesterday.getDate() - 1)
-      if (
-        yesterday.toISOString().slice(0, 10) === date.toISOString().slice(0, 10)
-      ) {
+
+      if (localDateString(yesterday) === localDateString(date)) {
         return _(msg`Yesterday, ${time}`)
       }
 
@@ -164,3 +163,12 @@ export function MessageItemMetadata({
     </TimeElapsed>
   )
 }
+
+function localDateString(date: Date) {
+  // can't use toISOString because it should be in local time
+  const mm = date.getMonth()
+  const dd = date.getDate()
+  const yyyy = date.getFullYear()
+  // not padding with 0s because it's not necessary, it's just used for comparison
+  return `${yyyy}-${mm}-${dd}`
+}
-- 
cgit 1.4.1

