From 5a09b39fcf10984dee8cec3840f6a61014c36c96 Mon Sep 17 00:00:00 2001
From: JustTemmie <47639983+JustTemmie@users.noreply.github.com>
Date: Thu, 3 Jul 2025 18:09:25 +0200
Subject: [PATCH] feat: Add date to messages if they weren't sent today
---
components/Message.vue | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/components/Message.vue b/components/Message.vue
index c699109..b6b38cc 100644
--- a/components/Message.vue
+++ b/components/Message.vue
@@ -10,6 +10,8 @@
{{ username }}
+ Yesterday at
+ {{ date.toLocaleDateString(undefined) }},
{{ date.toLocaleTimeString(undefined, { timeStyle: "short" }) }}
@@ -49,6 +51,7 @@ const messageElement = ref();
const dateHidden = ref(true);
const date = new Date(props.timestamp);
+const currentDate: Date = new Date()
console.log("message:", props.text);
console.log("author:", props.username);
@@ -74,6 +77,20 @@ onMounted(async () => {
// showHover.value = !showHover.value;
//}
+function getDayDifference(date_1: Date, date_2: Date) {
+// Normalize both dates to midnight
+ const midnight1 = new Date(date_1.getFullYear(), date_1.getMonth(), date_1.getDate());
+ const midnight2 = new Date(date_2.getFullYear(), date_2.getMonth(), date_2.getDate());
+
+ // Calculate the difference in time
+ const timeDifference = midnight2.getTime() - midnight1.getTime();
+
+ // Convert time difference from milliseconds to days
+ const dayDifference = timeDifference / (1000 * 60 * 60 * 24);
+
+ return Math.round(dayDifference); // Round to the nearest whole number
+}
+